Luke Smith![]()
var instance = new Y.SomeClass({ ... });
instance.plug(Y.Plugin.Drag);
is a nuisance. I want the instantiation of my class to describe its makeup entirely. Two is one too many steps.
So this module allows you to have plugins register a triggering attribute on host classes that will do the magic for you under the hood.
// Add the attribute 'draggable' to Y.SomeClass to (un)plug Y.Plugin.Drag
Y.Plugin.addHostAttr('draggable', Y.SomeClass, Y.Plugin.Drag);
var instance = new Y.SomeClass({
...,
draggable: true
});
See the linked docs for more details and extended signature.
Example 1.
Add "draggable" triggering attribute to Y.DataTable.Base:
Example 2.
Add a triggering attribute "filters" that accepts true|false or
a configuration object (out-of-the-box support), as well as a single
string or string array to pass as the plugin's "category" configuration
<script src="http://yui.yahooapis.com/3.4.0 PR3/build/yui/yui-min.js"></script>YUI({
//Last Gallery Build of this module
gallery: 'gallery-2011.08.03-21-18'
}).use('datatable-sort', 'console-filters', 'gallery-pluginattr', function(Y) {
// Example 1.
Y.Plugin.addHostAttr('sortable', Y.DataTable.Base, Y.Plugin.DataTableSort);
var table = new Y.DataTable.Base({ sortable: true }); // plugs DTSort
table.set('sortable', false); // unplugs DTSort
// Example 2.
Y.Plugin.addHostAttr('filters', Y.Console, Y.Plugin.ConsoleFilters,
function (config) {
if (Y.Lang.isString(config) || Y.Lang.isArray(config)) {
config = {
defaultVisibility: false,
category: Y.Array.hash(Y.Array(config))
};
}
return config;
}
});
var con = new Y.Console({ filters: ['warn', 'error'] });
});
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info