Plugin.Host Class
yui3/src/pluginhost/js/PluginHost.js:11
<p> An augmentable class, which provides the augmented class with the ability to host plugins. It adds <a href="#method_plug">plug</a> and <a href="#method_unplug">unplug</a> methods to the augmented class, which can be used to add or remove plugins from instances of the class. </p>
<p>Plugins can also be added through the constructor configuration object passed to the host class' constructor using the "plugins" property. Supported values for the "plugins" property are those defined by the <a href="#method_plug">plug</a> method.
For example the following code would add the AnimPlugin and IOPlugin to Overlay (the plugin host): <xmp> var o = new Overlay({plugins: [ AnimPlugin, {fn:IOPlugin, cfg:{section:"header"}}]}); </xmp> </p> <p> Plug.Host's protected <a href="#method_initPlugins">_initPlugins</a> and <a href="#method_destroyPlugins">_destroyPlugins</a> methods should be invoked by the host class at the appropriate point in the host's lifecyle. </p>
Index
Methods
- _destroyPlugins
- _initConfigPlugins
- _initPlugins
- hasPlugin
- plug
- plug static
- unplug
- unplug static
Methods
_destroyPlugins
()
private
Unplugs and destroys all plugins on the host
_initConfigPlugins
-
config
A protected initialization method, used by the host class to initialize plugin configurations passed the constructor, through the config object.
Host objects should invoke this method at the appropriate time in their construction lifecycle.
Parameters:
-
config
ObjectThe configuration object passed to the constructor
_initPlugins
-
config
Initializes static plugins registered on the host (using the Base.plug static method) and any plugins passed to the instance through the "plugins" configuration property.
Parameters:
-
config
ObjectThe configuration object with property name/value pairs.
hasPlugin
-
ns
Determines if a plugin has plugged into this host.
Parameters:
-
ns
StringThe plugin's namespace
Returns:
Returns a truthy value (the plugin instance) if present, or undefined if not.
plug
-
P
-
config
Adds a plugin to the host object. This will instantiate the plugin and attach it to the configured namespace on the host object.
Parameters:
-
P
Function | Object | ArrayAccepts the plugin class, or an object with a "fn" property specifying the plugin class and a "cfg" property specifying the configuration for the Plugin. <p> Additionally an Array can also be passed in, with the above function or object values, allowing the user to add multiple plugins in a single call. </p>
-
config
Object(Optional) If the first argument is the plugin class, the second argument can be the configuration for the plugin.
Returns:
A reference to the host object
plug
-
hostClass
-
plugin
-
config
Registers plugins to be instantiated at the class level (plugins which should be plugged into every instance of the class by default).
Parameters:
-
hostClass
FunctionThe host class on which to register the plugins
-
plugin
Function | ArrayEither the plugin class, an array of plugin classes or an array of objects (with fn and cfg properties defined)
-
config
Object(Optional) If plugin is the plugin class, the configuration for the plugin
unplug
-
plugin
Removes a plugin from the host object. This will destroy the plugin instance and delete the namespace from the host object.
Parameters:
-
plugin
String | FunctionThe namespace of the plugin, or the plugin class with the static NS namespace property defined. If not provided, all registered plugins are unplugged.
Returns:
A reference to the host object
unplug
-
hostClass
-
plugin
Unregisters any class level plugins which have been registered by the host class, or any other class in the hierarchy.
Parameters:
-
hostClass
FunctionThe host class from which to unregister the plugins
-
plugin
Function | ArrayThe plugin class, or an array of plugin classes