MDL-35616 import YUI 3.7.2
[moodle.git] / lib / yuilib / 3.7.2 / build / node-pluginhost / node-pluginhost.js
blobb48c691712731b0ed6ca320af93ce2decba2d7f3
1 /*
2 YUI 3.7.2 (build 5639)
3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
7 YUI.add('node-pluginhost', function (Y, NAME) {
9 /**
10  * @module node
11  * @submodule node-pluginhost
12  */
14 /**
15  * Registers plugins to be instantiated at the class level (plugins
16  * which should be plugged into every instance of Node by default).
17  *
18  * @method plug
19  * @static
20  * @for Node
21  * @param {Function | Array} plugin Either the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
22  * @param {Object} config (Optional) If plugin is the plugin class, the configuration for the plugin
23  */
24 Y.Node.plug = function() {
25     var args = Y.Array(arguments);
26     args.unshift(Y.Node);
27     Y.Plugin.Host.plug.apply(Y.Base, args);
28     return Y.Node;
31 /**
32  * Unregisters any class level plugins which have been registered by the Node
33  *
34  * @method unplug
35  * @static
36  *
37  * @param {Function | Array} plugin The plugin class, or an array of plugin classes
38  */
39 Y.Node.unplug = function() {
40     var args = Y.Array(arguments);
41     args.unshift(Y.Node);
42     Y.Plugin.Host.unplug.apply(Y.Base, args);
43     return Y.Node;
46 Y.mix(Y.Node, Y.Plugin.Host, false, null, 1);
48 // allow batching of plug/unplug via NodeList
49 // doesn't use NodeList.importMethod because we need real Nodes (not tmpNode)
50 /**
51  * Adds a plugin to each node in the NodeList.
52  * This will instantiate the plugin and attach it to the configured namespace on each node
53  * @method plug
54  * @for NodeList
55  * @param P {Function | Object |Array} Accepts the plugin class, or an 
56  * object with a "fn" property specifying the plugin class and 
57  * a "cfg" property specifying the configuration for the Plugin.
58  * <p>
59  * Additionally an Array can also be passed in, with the above function or 
60  * object values, allowing the user to add multiple plugins in a single call.
61  * </p>
62  * @param config (Optional) If the first argument is the plugin class, the second argument
63  * can be the configuration for the plugin.
64  * @chainable
65  */
66 Y.NodeList.prototype.plug = function() {
67     var args = arguments;
68     Y.NodeList.each(this, function(node) {
69         Y.Node.prototype.plug.apply(Y.one(node), args);
70     });
71     return this;
74 /**
75  * Removes a plugin from all nodes in the NodeList. This will destroy the 
76  * plugin instance and delete the namespace each node. 
77  * @method unplug
78  * @for NodeList
79  * @param {String | Function} plugin The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided,
80  * all registered plugins are unplugged.
81  * @chainable
82  */
83 Y.NodeList.prototype.unplug = function() {
84     var args = arguments;
85     Y.NodeList.each(this, function(node) {
86         Y.Node.prototype.unplug.apply(Y.one(node), args);
87     });
88     return this;
92 }, '3.7.2', {"requires": ["node-base", "pluginhost"]});