src/cm/media/js/lib/yui/yui3-3.15.0/build/node-pluginhost/node-pluginhost.js
changeset 602 e16a97fb364a
equal deleted inserted replaced
601:d334a616c023 602:e16a97fb364a
       
     1 YUI.add('node-pluginhost', function (Y, NAME) {
       
     2 
       
     3 /**
       
     4  * @module node
       
     5  * @submodule node-pluginhost
       
     6  */
       
     7 
       
     8 /**
       
     9  * Registers plugins to be instantiated at the class level (plugins
       
    10  * which should be plugged into every instance of Node by default).
       
    11  *
       
    12  * @method plug
       
    13  * @static
       
    14  * @for Node
       
    15  * @param {Function | Array} plugin Either the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
       
    16  * @param {Object} config (Optional) If plugin is the plugin class, the configuration for the plugin
       
    17  */
       
    18 Y.Node.plug = function() {
       
    19     var args = Y.Array(arguments);
       
    20     args.unshift(Y.Node);
       
    21     Y.Plugin.Host.plug.apply(Y.Base, args);
       
    22     return Y.Node;
       
    23 };
       
    24 
       
    25 /**
       
    26  * Unregisters any class level plugins which have been registered by the Node
       
    27  *
       
    28  * @method unplug
       
    29  * @static
       
    30  *
       
    31  * @param {Function | Array} plugin The plugin class, or an array of plugin classes
       
    32  */
       
    33 Y.Node.unplug = function() {
       
    34     var args = Y.Array(arguments);
       
    35     args.unshift(Y.Node);
       
    36     Y.Plugin.Host.unplug.apply(Y.Base, args);
       
    37     return Y.Node;
       
    38 };
       
    39 
       
    40 Y.mix(Y.Node, Y.Plugin.Host, false, null, 1);
       
    41 
       
    42 // run PluginHost constructor on cached Node instances
       
    43 Y.Object.each(Y.Node._instances, function (node) {
       
    44     Y.Plugin.Host.apply(node);
       
    45 });
       
    46 
       
    47 // allow batching of plug/unplug via NodeList
       
    48 // doesn't use NodeList.importMethod because we need real Nodes (not tmpNode)
       
    49 /**
       
    50  * Adds a plugin to each node in the NodeList.
       
    51  * This will instantiate the plugin and attach it to the configured namespace on each node
       
    52  * @method plug
       
    53  * @for NodeList
       
    54  * @param P {Function | Object |Array} Accepts the plugin class, or an
       
    55  * object with a "fn" property specifying the plugin class and
       
    56  * a "cfg" property specifying the configuration for the Plugin.
       
    57  * <p>
       
    58  * Additionally an Array can also be passed in, with the above function or
       
    59  * object values, allowing the user to add multiple plugins in a single call.
       
    60  * </p>
       
    61  * @param config (Optional) If the first argument is the plugin class, the second argument
       
    62  * can be the configuration for the plugin.
       
    63  * @chainable
       
    64  */
       
    65 Y.NodeList.prototype.plug = function() {
       
    66     var args = arguments;
       
    67     Y.NodeList.each(this, function(node) {
       
    68         Y.Node.prototype.plug.apply(Y.one(node), args);
       
    69     });
       
    70     return this;
       
    71 };
       
    72 
       
    73 /**
       
    74  * Removes a plugin from all nodes in the NodeList. This will destroy the
       
    75  * plugin instance and delete the namespace each node.
       
    76  * @method unplug
       
    77  * @for NodeList
       
    78  * @param {String | Function} plugin The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided,
       
    79  * all registered plugins are unplugged.
       
    80  * @chainable
       
    81  */
       
    82 Y.NodeList.prototype.unplug = function() {
       
    83     var args = arguments;
       
    84     Y.NodeList.each(this, function(node) {
       
    85         Y.Node.prototype.unplug.apply(Y.one(node), args);
       
    86     });
       
    87     return this;
       
    88 };
       
    89 
       
    90 
       
    91 }, '@VERSION@', {"requires": ["node-base", "pluginhost"]});