attr.js revision 985b0bdb9af3bdc0fff992e92d17f29b9d6b6d9a
/**
* <p>Register a Plugin with an activation attribute on a host class.
* Setting this attribute at construction or at run time will cause the
* Plugin to be plugged into the instance. For example:</p>
*
* <pre><code>
* Y.Plugin.addHostAttr('sortable', Y.DataTable, Y.Plugin.DTSort);
*
* var dt = new Y.DataTable({ sortable: true }); // plugs DTSort
* dt.set('sortable', false); // unplugs DTSort
* </code></pre>
*
* <p>To support enhancing host instance behavior when the plugin is
* use()d after the host instance is instantiated, you can also pass the
* instance as the second parameter.</p>
*
* <p>To allow custom values to be passed to the trigger attribute, pass a
* preprocessor function as the fourth parameter. The value assigned to the
* attribute will be translated by this function prior to getting passed to
* plug() as the configuration. Return false from this function to cause
* the plugin to be unplugged.</p>
*
* <pre><code>
* 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'] });</code></pre>
*
* <p>The host class must have a static ATTRS collection.</p>
*
* @method Plugin.addHostAttr
* @param name {String} The attribute name to trigger plug and unplug
* @param host {Function|Object} The class or instance to receive the
* triggering attribute
* @param plugin {Function} The plugin class
* @param [setter] {Function} Attribute value preprocessor
* @param [force] {Boolean} Redefine an existing host attribue?
* @static
*/
return false;
}
if (!isFunction(setter)) {
setter = null;
}
if (isFunction(plugin)) {
// For now, disallow subattribute as a trigger or
// plugin attribute setter
}
return ret;
};
} else {
}
if (isFunction(host)) {
}
}
return true;
};