~ubuntu-branches/ubuntu/precise/maas/precise-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/pluginhost-base/pluginhost-base-debug.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('pluginhost-base', function(Y) {
8
 
 
9
 
    /**
10
 
     * Provides the augmentable PluginHost interface, which can be added to any class.
11
 
     * @module pluginhost
12
 
     */
13
 
 
14
 
    /**
15
 
     * Provides the augmentable PluginHost interface, which can be added to any class.
16
 
     * @module pluginhost-base
17
 
     */
18
 
 
19
 
    /**
20
 
     * <p>
21
 
     * An augmentable class, which provides the augmented class with the ability to host plugins.
22
 
     * It adds <a href="#method_plug">plug</a> and <a href="#method_unplug">unplug</a> methods to the augmented class, which can 
23
 
     * be used to add or remove plugins from instances of the class.
24
 
     * </p>
25
 
     *
26
 
     * <p>Plugins can also be added through the constructor configuration object passed to the host class' constructor using
27
 
     * the "plugins" property. Supported values for the "plugins" property are those defined by the <a href="#method_plug">plug</a> method. 
28
 
     * 
29
 
     * For example the following code would add the AnimPlugin and IOPlugin to Overlay (the plugin host):
30
 
     * <xmp>
31
 
     * var o = new Overlay({plugins: [ AnimPlugin, {fn:IOPlugin, cfg:{section:"header"}}]});
32
 
     * </xmp>
33
 
     * </p>
34
 
     * <p>
35
 
     * Plug.Host's protected <a href="#method_initPlugins">_initPlugins</a> and <a href="#method_destroyPlugins">_destroyPlugins</a> 
36
 
     * methods should be invoked by the host class at the appropriate point in the host's lifecyle.  
37
 
     * </p>
38
 
     *
39
 
     * @class Plugin.Host
40
 
     */
41
 
 
42
 
    var L = Y.Lang;
43
 
 
44
 
    function PluginHost() {
45
 
        this._plugins = {};
46
 
    }
47
 
 
48
 
    PluginHost.prototype = {
49
 
 
50
 
        /**
51
 
         * Adds a plugin to the host object. This will instantiate the 
52
 
         * plugin and attach it to the configured namespace on the host object.
53
 
         *
54
 
         * @method plug
55
 
         * @chainable
56
 
         * @param P {Function | Object |Array} Accepts the plugin class, or an 
57
 
         * object with a "fn" property specifying the plugin class and 
58
 
         * a "cfg" property specifying the configuration for the Plugin.
59
 
         * <p>
60
 
         * Additionally an Array can also be passed in, with the above function or 
61
 
         * object values, allowing the user to add multiple plugins in a single call.
62
 
         * </p>
63
 
         * @param config (Optional) If the first argument is the plugin class, the second argument
64
 
         * can be the configuration for the plugin.
65
 
         * @return {Base} A reference to the host object
66
 
         */
67
 
        plug: function(Plugin, config) {
68
 
            var i, ln, ns;
69
 
 
70
 
            if (L.isArray(Plugin)) {
71
 
                for (i = 0, ln = Plugin.length; i < ln; i++) {
72
 
                    this.plug(Plugin[i]);
73
 
                }
74
 
            } else {
75
 
                if (Plugin && !L.isFunction(Plugin)) {
76
 
                    config = Plugin.cfg;
77
 
                    Plugin = Plugin.fn;
78
 
                }
79
 
 
80
 
                // Plugin should be fn by now
81
 
                if (Plugin && Plugin.NS) {
82
 
                    ns = Plugin.NS;
83
 
        
84
 
                    config = config || {};
85
 
                    config.host = this;
86
 
        
87
 
                    if (this.hasPlugin(ns)) {
88
 
                        // Update config
89
 
                        this[ns].setAttrs(config);
90
 
                    } else {
91
 
                        // Create new instance
92
 
                        this[ns] = new Plugin(config);
93
 
                        this._plugins[ns] = Plugin;
94
 
                    }
95
 
                }
96
 
                else { Y.log("Attempt to plug in an invalid plugin. Host:" + this + ", Plugin:" + Plugin); }
97
 
            }
98
 
            return this;
99
 
        },
100
 
 
101
 
        /**
102
 
         * Removes a plugin from the host object. This will destroy the 
103
 
         * plugin instance and delete the namepsace from the host object. 
104
 
         *
105
 
         * @method unplug
106
 
         * @param {String | Function} plugin The namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided,
107
 
         * all registered plugins are unplugged.
108
 
         * @return {Base} A reference to the host object
109
 
         * @chainable
110
 
         */
111
 
        unplug: function(plugin) {
112
 
            var ns = plugin, 
113
 
                plugins = this._plugins;
114
 
            
115
 
            if (plugin) {
116
 
                if (L.isFunction(plugin)) {
117
 
                    ns = plugin.NS;
118
 
                    if (ns && (!plugins[ns] || plugins[ns] !== plugin)) {
119
 
                        ns = null;
120
 
                    }
121
 
                }
122
 
        
123
 
                if (ns) {
124
 
                    if (this[ns]) {
125
 
                        this[ns].destroy();
126
 
                        delete this[ns];
127
 
                    }
128
 
                    if (plugins[ns]) {
129
 
                        delete plugins[ns];
130
 
                    }
131
 
                }
132
 
            } else {
133
 
                for (ns in this._plugins) {
134
 
                    if (this._plugins.hasOwnProperty(ns)) {
135
 
                        this.unplug(ns);
136
 
                    }
137
 
                }
138
 
            }
139
 
            return this;
140
 
        },
141
 
 
142
 
        /**
143
 
         * Determines if a plugin has plugged into this host.
144
 
         *
145
 
         * @method hasPlugin
146
 
         * @param {String} ns The plugin's namespace
147
 
         * @return {boolean} returns true, if the plugin has been plugged into this host, false otherwise.
148
 
         */
149
 
        hasPlugin : function(ns) {
150
 
            return (this._plugins[ns] && this[ns]);
151
 
        },
152
 
 
153
 
        /**
154
 
         * Initializes static plugins registered on the host (using the
155
 
         * Base.plug static method) and any plugins passed to the 
156
 
         * instance through the "plugins" configuration property.
157
 
         *
158
 
         * @method _initPlugins
159
 
         * @param {Config} config The configuration object with property name/value pairs.
160
 
         * @private
161
 
         */
162
 
        
163
 
        _initPlugins: function(config) {
164
 
            this._plugins = this._plugins || {};
165
 
 
166
 
            if (this._initConfigPlugins) {
167
 
                this._initConfigPlugins(config);
168
 
            }
169
 
        },
170
 
 
171
 
        /**
172
 
         * Unplugs and destroys all plugins on the host
173
 
         * @method _destroyPlugins
174
 
         * @private
175
 
         */
176
 
        _destroyPlugins: function() {
177
 
            this.unplug();
178
 
        }
179
 
    };
180
 
 
181
 
    Y.namespace("Plugin").Host = PluginHost;
182
 
 
183
 
 
184
 
}, '3.4.1' ,{requires:['yui-base']});