Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created March 31, 2011 04:49
Show Gist options
  • Save lsmith/895834 to your computer and use it in GitHub Desktop.
Save lsmith/895834 to your computer and use it in GitHub Desktop.
Thoughts on adding HTML_PARSER support to Plugin.addHostAttr sugar for Plugins.
Y.Plugin.addHostAttr = function (name, host, plugin) {
host.ATTRS[name] = {
setter: function (val) {
var config = isObject(val) ? val : {},
method = (val) ? 'plug' : 'unplug',
widgetProto = Widget.prototype;
this[method](plugin, config);
if (val && (host.prototype === widgetProto || widgetProto.isPrototypeOf(host.prototype))) {
if (!host.HTML_PARSER) {
host.HTML_PARSER = {};
}
host.HTML_PARSER[name] = function (bb) {
var cname = Y.ClassNameManager.getClassName(name);
return !!(bb.hasClass(cname) ||
bb.one('.yui3-widget-content.' + cname));
// Alternate approach would be to look for data-* attribute?
}
}
},
...
};
};
<div id="yconsole" class="yui3-draggable">
...
</div>
<script>
/* what would appear in plugin-drag module */
YUI.add('plugin-drag', function (Y) {
...
Y.Plugin.addHostAttr('draggable', Y.Widget, Y.Plugin.Drag);
}...);
/* then back in the implementation code */
Y.use('console', 'plugin-drag', function () {
var yconsole = new Y.Console({ srcNode: '#yconsole' }); // boom, draggable Console
...
});
@ericf
Copy link

ericf commented Mar 31, 2011

Ah yes, it's unplug that can accept just the NS: foo.unplug('dd')

Yeah I think this idea is very interesting, I do like that YUI has built in the idea of sandboxing (and nested sandboxes ala Y.use(…)) so if the developer desires for plugins behavior to be sequestered, they could create a nested Y.use('da-plugin', function(){ … }) sandbox to apply it to, instead of their top-level YUI().use(…).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment