Created
March 31, 2011 04:49
-
-
Save lsmith/895834 to your computer and use it in GitHub Desktop.
Thoughts on adding HTML_PARSER support to Plugin.addHostAttr sugar for Plugins.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? | |
} | |
} | |
}, | |
... | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 | |
... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah yes, it's
unplug
that can accept just theNS
: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 nestedY.use('da-plugin', function(){ … })
sandbox to apply it to, instead of their top-levelYUI().use(…)
.