base-debug.js revision cc05f14a87293a437bcbe67deac2da7edad2a120
8215dd9a19d775d6391d4f44be2ca8268952e048TrippYUI.add('base-base', function(Y) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp/**
6f294bea19c397d53e471007448460655f4b8c6bTripp* Base class support for objects requiring managed attributes and acting as event targets.
6f294bea19c397d53e471007448460655f4b8c6bTripp*
6f294bea19c397d53e471007448460655f4b8c6bTripp* The base module also provides an augmentable PluginHost interface.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp*
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp* @module base
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp*/
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp/**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * An augmentable class, which when added to a "Base" based class, allows
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * the class to support Plugins, providing plug and unplug methods.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The PlugHost's _initPlugins and _destroyPlugins should be invoked by the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * host class at the appropriate point in the classes lifecyle. This is done
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * by default for Base class.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @class PluginHost
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Trippvar L = Y.Lang;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Trippfunction PluginHost(config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._plugins = {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp}
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048TrippPluginHost.prototype = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Register and instantiate a plugin with the Widget.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method plug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @chainable
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param p {Function | Object |Array} Accepts the plugin class, or an
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * object literal with a "fn" property specifying the Plugin class and
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * a "cfg" property specifying the configuration for the Plugin.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Additionally an Array can also be passed in, with the above function or
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Object literal values, allowing for multiple plugin registration in a single call.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param config Optional. If the first argument is the plugin class, the second argument
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * can be the configuration for the plugin.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plug: function(p, config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (p) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (L.isFunction(p)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._plug(p, config);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else if (L.isArray(p)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (var i = 0, ln = p.length; i < ln; i++) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.plug(p[i]);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._plug(p.fn, p.cfg);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Unregister and destroy a plugin already instantiated on the host.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method unplug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {String | Function} plugin The namespace of the Plugin, or the Plugin class with the static NS namespace property defined. If not provided,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * all registered plugins are unplugged.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @chainable
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp unplug: function(plugin) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (plugin) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._unplug(plugin);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var ns;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (ns in this._plugins) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (this._plugins.hasOwnProperty(ns)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._unplug(ns);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Determines if a plugin has been registered and instantiated
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * for this widget.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method hasPlugin
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @public
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return {Boolean} returns true, if the plugin has been applied
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * to this widget.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hasPlugin : function(ns) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return (this._plugins[ns] && this[ns]);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Initializes static plugins registered on the host (using the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Base.plug static method) and any plugins passed in for the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * instance through the "plugins" configuration property.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _initPlugins
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Config} the user configuration object for the host.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _initPlugins: function(config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Class Configuration
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var classes = this._getClasses(),
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plug = [],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp unplug = {},
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp constructor, i, classPlug, classUnplug, pluginClassName;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp //TODO: Room for optimization. Can we apply statically/unplug in same pass?
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (i = classes.length - 1; i >= 0; i--) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp constructor = classes[i];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp classUnplug = constructor._UNPLUG;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (classUnplug) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // subclasses over-write
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.mix(unplug, classUnplug, true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp classPlug = constructor._PLUG;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (classPlug) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // subclasses over-write
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.mix(plug, classPlug, true);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp for (pluginClassName in plug) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (plug.hasOwnProperty(pluginClassName)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!unplug[pluginClassName]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.plug(plug[pluginClassName]);
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // User Configuration
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (config && config.plugins) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.plug(config.plugins);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Private method used to unplug and destroy all plugins on the host
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _destroyPlugins
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _destroyPlugins: function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._unplug();
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp },
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Private method used to instantiate and attach plugins to the host
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _plug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function} PluginClass The plugin class to instantiate
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} config The configuration object for the plugin
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _plug: function(PluginClass, config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (PluginClass && PluginClass.NS) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var ns = PluginClass.NS;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp config = config || {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp config.host = this;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (this.hasPlugin(ns)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Update config
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this[ns].setAttrs(config);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Create new instance
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this[ns] = new PluginClass(config);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._plugins[ns] = PluginClass;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Private method used to unregister and destroy a plugin already instantiated with the host.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _unplug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {String | Function} plugin The namespace for the Plugin, or a Plugin class, with the static NS property defined.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _unplug : function(plugin) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var ns = plugin,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plugins = this._plugins;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (L.isFunction(plugin)) {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp ns = plugin.NS;
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp if (ns && (!plugins[ns] || plugins[ns] !== plugin)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp ns = null;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (ns) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (this[ns]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this[ns].destroy();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp delete this[ns];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (plugins[ns]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp delete plugins[ns];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp/**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Registers plugins to be instantiated at the class level (plugins
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * which should be plugged into every instance of the class by default).
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method PluginHost.plug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @static
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function} hostClass The host class on which to register the plugins
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function | Array} plugin Either the plugin class, or an array of plugin classes/plugin fn, cfg object literals
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @param {Object} config If plugin is the plugin class, the configuration for the plugin can be passed
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * as the configuration for the plugin
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048TrippPluginHost.plug = function(hostClass, plugin, config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Cannot plug into Base, since Plugins derive from Base [ will cause infinite recurrsion ]
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var p, i, l, name;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (hostClass !== Y.Base) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hostClass._PLUG = hostClass._PLUG || {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!L.isArray(plugin)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plugin = {fn:plugin, cfg:config};
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plugin = [plugin];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (i = 0, l = plugin.length; i < l;i++) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp p = plugin[i];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name = p.NAME || p.fn.NAME;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hostClass._PLUG[name] = p;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp/**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Unregisters plugins which have been registered by the host class, or any
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * other class in the hierarchy.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method PluginHost.unplug
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @static
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function} hostClass The host class from which to unregister the plugins
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function | Array} plugin The plugin class, or an array of plugin classes
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048TrippPluginHost.unplug = function(hostClass, plugin) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var p, i, l, name;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (hostClass !== Y.Base) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hostClass._UNPLUG = hostClass._UNPLUG || {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!L.isArray(plugin)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp plugin = [plugin];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (i = 0, l = plugin.length; i < l; i++) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp p = plugin[i];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp name = p.NAME;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!hostClass._PLUG[name]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp hostClass._UNPLUG[name] = p;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp delete hostClass._PLUG[name];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048TrippY.namespace("Plugin").Host = PluginHost;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Base class support for objects requiring managed attributes and acting as event targets.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The base module also provides an augmentable PluginHost interface.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @module base
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The base-base sub-module provides the Base class, without Base.build functionality
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @module base
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @sub-module base-base
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var O = Y.Object,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp DOT = ".",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp DESTROY = "destroy",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp INIT = "init",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp INITIALIZED = "initialized",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp DESTROYED = "destroyed",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp INITIALIZER = "initializer",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp OBJECT_CONSTRUCTOR = Object.prototype.constructor,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp DEEP = "deep",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp SHALLOW = "shallow",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp VALUE = "value",
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp DESTRUCTOR = "destructor";
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Provides a base class for managed attribute based
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * objects, which handles the chaining of initializer and destructor methods
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * across the hierarchy during init and destroy lifecycle methods and
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * handles automatic configuration of registered Attributes, through
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * the static <a href="#property_ATTRS">ATTRS</a> property.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>The Base class also handles prefixing of event types with the static <a href="#property_NAME">NAME</a>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * property for all events fired from instances of classes derived from Base.</p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @constructor
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @class Base
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @uses Attribute, Plugin.Host
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} config Object literal of configuration property name/value pairs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp function Base() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.log('constructor called', 'life', 'base');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Attribute.call(this);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.Plugin.Host.call(this);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._silentInit = this._silentInit || false;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (this._lazyAddAttrs !== false) { this._lazyAddAttrs = true; }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.init.apply(this, arguments);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * The list of properties which can be configured for
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * each attribute (e.g. setter, getter, writeOnce etc.)
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @property Base._ATTR_CFG
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Array
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @static
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Base._ATTR_CFG = Y.Attribute._ATTR_CFG.concat("cloneDefaultValue");
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Name string to be used to identify instances of
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * this class, for example in prefixing events.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Classes extending Base, should define their own
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * static NAME property.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @property NAME
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type String
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @static
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Base.NAME = 'base';
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Object literal defining the set of attributes which
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * will be available for instances of this class, and
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * how they are configured. See Attributes addAtt method
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * for a description of configuration options available
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * for each attribute.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @property ATTRS
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type Object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @static
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Base.ATTRS = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Flag indicating whether or not this object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * has been through the init lifecycle phase.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute initialized
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @default false
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type boolean
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp initialized: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp readOnly:true,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value:false
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Flag indicating whether or not this object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * has been through the destroy lifecycle phase.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @attribute destroyed
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @readOnly
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @default false
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @type boolean
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp destroyed: {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp readOnly:true,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp value:false
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp };
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Base.prototype = {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Init lifecycle method, invoked during construction.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Fires the init event prior to invoking initializers on
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * the class hierarchy.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method init
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @final
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @chainable
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} config Object literal of configuration property name/value pairs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return {Base} A reference to this object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp init: function(config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.log('init called', 'life', 'base');
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp /**
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * The name string to be used to identify
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * this instance of object.
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @property name
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @type String
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._yuievt.config.prefix = this.name = this.constructor.NAME;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Lifecycle event for the init phase, fired prior to initialization.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Invoking the preventDefault method on the event object provided
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * to subscribers will prevent initialization from occuring.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Subscribers to the "after" momemt of this event, will be notified
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * after initialization of the object is complete (and therefore
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * cannot prevent initialization).
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @event init
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @preventable _defInitFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Event.Facade} e Event object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param config Object literal of configuration name/value pairs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!this._silentInit) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.publish(INIT, {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp queuable:false,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp defaultFn:this._defInitFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp });
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (config) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (config.on) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.on(config.on);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (config.after) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.after(config.after);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!this._silentInit) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.fire(INIT, {cfg: config});
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._defInitFn({cfg: config});
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Destroy lifecycle method. Fires the destroy
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * event, prior to invoking destructors for the
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * class hierarchy.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Subscribers to the destroy
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * event can invoke preventDefault on the event object, to prevent destruction
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * from proceeding.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method destroy
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return {Base} A reference to this object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @final
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @chainable
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp destroy: function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.log('destroy called', 'life', 'base');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Lifecycle event for the destroy phase,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * fired prior to destruction. Invoking the preventDefault
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * method on the event object provided to subscribers will
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * prevent destruction from proceeding.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * <p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Subscribers to the "after" moment of this event, will be notified
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * after destruction is complete (and as a result cannot prevent
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * destruction).
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * </p>
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @event destroy
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @preventable _defDestroyFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Event.Facade} e Event object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.publish(DESTROY, {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp queuable:false,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp defaultFn: this._defDestroyFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp });
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this.fire(DESTROY);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Default init event handler
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _defInitFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Event.Facade} e Event object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _defInitFn : function(e) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._initHierarchy(e.cfg);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._initPlugins(e.cfg);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!this._silentInit) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._set(INITIALIZED, true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._conf.add(INITIALIZED, VALUE, true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Default destroy event handler
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _defDestroyFn
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Event.Facade} e Event object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _defDestroyFn : function(e) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._destroyHierarchy();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._destroyPlugins();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._set(DESTROYED, true);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns the class hierarchy for this object, with Base being the last class in the array.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getClasses
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return {Function[]} An Array of classes (constructor functions), making up the class hierarchy for this object
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getClasses : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!this._classes) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._initHierarchyData();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this._classes;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp *
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _getAttrCfgs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @protected
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @return {Object} The hash of attribute configurations, aggregated across classes in the hierarchy
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _getAttrCfgs : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!this._attrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._initHierarchyData();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return this._attrs;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _filterAttrCfs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Function} clazz
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Objects} allCfgs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _filterAttrCfgs : function(clazz, allCfgs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var cfgs = null, attr, attrs = clazz.ATTRS;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (attrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (attr in attrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (attrs.hasOwnProperty(attr) && allCfgs[attr]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfgs = cfgs || {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfgs[attr] = allCfgs[attr];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp delete allCfgs[attr];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return cfgs;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _initHierarchyData
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _initHierarchyData : function() {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var c = this.constructor,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp classes = [],
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp attrs = [];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp while (c) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Add to classes
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp classes[classes.length] = c;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Add to attributes
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (c.ATTRS) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp attrs[attrs.length] = c.ATTRS;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp c = c.superclass ? c.superclass.constructor : null;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._classes = classes;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp this._attrs = this._aggregateAttrs(attrs);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @method _aggregateAttrs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @private
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * @param {Object} allAttrs
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp */
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp _aggregateAttrs : function(allAttrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp var attr,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp attrs,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfg,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp val,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp path,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp i,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp clone,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfgProps = Base._ATTR_CFG,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp aggAttrs = {};
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (allAttrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (i = allAttrs.length-1; i >= 0; --i) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp attrs = allAttrs[i];
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp for (attr in attrs) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (attrs.hasOwnProperty(attr)) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // Protect config passed in
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfg = Y.mix({}, attrs[attr], true, cfgProps);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp val = cfg.value;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp clone = cfg.cloneDefaultValue;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (val) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.log('Cloning default value for attribute:' + attr, 'info', 'base');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfg.value = Y.clone(val);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else if (clone === SHALLOW) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.log('Merging default value for attribute:' + attr, 'info', 'base');
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp cfg.value = Y.merge(val);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // else if (clone === false), don't clone the static default value.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp // It's intended to be used by reference.
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp path = null;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (attr.indexOf(DOT) !== -1) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp path = attr.split(DOT);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp attr = path.shift();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (path && aggAttrs[attr] && aggAttrs[attr].value) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp O.setValue(aggAttrs[attr].value, path, val);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else if (!path){
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp if (!aggAttrs[attr]) {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp aggAttrs[attr] = cfg;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp } else {
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp Y.mix(aggAttrs[attr], cfg, true, cfgProps);
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp }
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp return aggAttrs;
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp },
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp /**
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * Initializes the class hierarchy rooted at this base class,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * which includes initializing attributes for each class defined
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp * in the class's static <a href="#property_ATTRS">ATTRS</a> property and invoking the initializer
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * method on the prototype of each class in the hierarchy.
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp *
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @method _initHierarchy
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @param {Object} userVals Object literal containing attribute name/value pairs
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @private
6f294bea19c397d53e471007448460655f4b8c6bTripp */
6f294bea19c397d53e471007448460655f4b8c6bTripp _initHierarchy : function(userVals) {
6f294bea19c397d53e471007448460655f4b8c6bTripp var lazy = this._lazyAddAttrs,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp constr,
6f294bea19c397d53e471007448460655f4b8c6bTripp constrProto,
6f294bea19c397d53e471007448460655f4b8c6bTripp ci,
6f294bea19c397d53e471007448460655f4b8c6bTripp ei,
6f294bea19c397d53e471007448460655f4b8c6bTripp el,
6f294bea19c397d53e471007448460655f4b8c6bTripp classes = this._getClasses(),
6f294bea19c397d53e471007448460655f4b8c6bTripp attrCfgs = this._getAttrCfgs();
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp for (ci = classes.length-1; ci >= 0; ci--) {
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp constr = classes[ci];
6f294bea19c397d53e471007448460655f4b8c6bTripp constrProto = constr.prototype;
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp if (constr._yuibuild && constr._yuibuild.exts && !constr._yuibuild.dynamic) {
6f294bea19c397d53e471007448460655f4b8c6bTripp for (ei = 0, el = constr._yuibuild.exts.length; ei < el; ei++) {
6f294bea19c397d53e471007448460655f4b8c6bTripp constr._yuibuild.exts[ei].apply(this, arguments);
6f294bea19c397d53e471007448460655f4b8c6bTripp }
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp }
6f294bea19c397d53e471007448460655f4b8c6bTripp
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp this.addAttrs(this._filterAttrCfgs(constr, attrCfgs), userVals, lazy);
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp if (constrProto.hasOwnProperty(INITIALIZER)) {
6f294bea19c397d53e471007448460655f4b8c6bTripp constrProto.initializer.apply(this, arguments);
6f294bea19c397d53e471007448460655f4b8c6bTripp }
6f294bea19c397d53e471007448460655f4b8c6bTripp }
6f294bea19c397d53e471007448460655f4b8c6bTripp },
6f294bea19c397d53e471007448460655f4b8c6bTripp
6f294bea19c397d53e471007448460655f4b8c6bTripp /**
6f294bea19c397d53e471007448460655f4b8c6bTripp * Destroys the class hierarchy rooted at this base class by invoking
6f294bea19c397d53e471007448460655f4b8c6bTripp * the descructor method on the prototype of each class in the hierarchy.
6f294bea19c397d53e471007448460655f4b8c6bTripp *
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @method _destroyHierarchy
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp * @private
6f294bea19c397d53e471007448460655f4b8c6bTripp */
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp _destroyHierarchy : function() {
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp var constr,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp constrProto,
f943c7186e37311877b6a9cf880bb405c09e2c9dTripp ci, cl,
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp classes = this._getClasses();
8215dd9a19d775d6391d4f44be2ca8268952e048Tripp
for (ci = 0, cl = classes.length; ci < cl; ci++) {
constr = classes[ci];
constrProto = constr.prototype;
if (constrProto.hasOwnProperty(DESTRUCTOR)) {
constrProto.destructor.apply(this, arguments);
}
}
},
/**
* Default toString implementation. Provides the constructor NAME
* and the instance ID.
*
* @method toString
* @return {String} String representation for this object
*/
toString: function() {
return this.constructor.NAME + "[" + Y.stamp(this) + "]";
}
};
// Straightup augment, no wrapper functions
Y.mix(Base, Y.Attribute, false, null, 1);
Y.mix(Base, PluginHost, false, null, 1);
Base.plug = PluginHost.plug;
Base.unplug = PluginHost.unplug;
// Fix constructor
Base.prototype.constructor = Base;
Y.Base = Base;
}, '@VERSION@' ,{requires:['attribute']});
YUI.add('base-build', function(Y) {
/**
* The base-build sub-module provides the Base.build functionality
*
* @module base
* @sub-module base-build
*/
var Base = Y.Base,
L = Y.Lang;
/**
* The build configuration for the Base class.
* Defines the static fields which need to be aggregated,
* when this class is used as the main class passed to
* the <a href="#method_build">Base.build</a> method.
*
* @property _buildCfg
* @type Object
* @static
* @final
* @private
*/
Base._buildCfg = {
aggregates : ["ATTRS", "_PLUG", "_UNPLUG"]
};
/**
* <p>
* Builds a constructor function (class) from the
* main function, and array of extension functions (classes)
* provided.
* </p>
* <p>
* The cfg object literal supports the following properties
* </p>
* <dl>
* <dt>dynamic &#60;boolean&#62;</dt>
* <dd>
* <p>If true (default), a completely new class
* is created which extends the main class, and acts as the
* host on which the extension classes are augmented.</p>
* <p>If false, the extensions classes are augmented directly to
* the main class, modifying the main classes prototype.</p>
* </dd>
* <dt>aggregates &#60;String[]&#62;</dt>
* <dd>An array of static property names, which will get aggregated
* on to the built class, in addition to the default properties build
* will always aggregate as defined by the main class' _buildCfg
* property.
* </dd>
* </dl>
*
* @method build
* @static
* @param {Function} main The name of the new class
* @param {Function} main The main class on which to base the built class
* @param {Function[]} extensions The set of extension classes which will be
* augmented/aggregated to the built class.
* @param {Object} cfg Optional. Configuration for the class.
* @return {Function} A custom class, created from the provided main and extension classes
*/
Base.build = function(name, main, extensions, cfg) {
var build = Base.build,
builtClass = build._getClass(main, cfg),
aggregates = build._getAggregates(main, cfg),
dynamic = builtClass._yuibuild.dynamic,
i, l, val, extClass;
// Shallow isolate aggregates
if (dynamic) {
if (aggregates) {
for (i = 0, l = aggregates.length; i < l; ++i) {
val = aggregates[i];
if (main.hasOwnProperty(val)) {
builtClass[val] = L.isArray(main[val]) ? [] : {};
}
}
Y.aggregate(builtClass, main, true, aggregates);
}
}
// Augment/Aggregate
for (i = 0, l = extensions.length; i < l; i++) {
extClass = extensions[i];
if (aggregates) {
Y.aggregate(builtClass, extClass, true, aggregates);
}
// Old augment
Y.mix(builtClass, extClass, true, null, 1);
builtClass._yuibuild.exts.push(extClass);
}
builtClass.prototype.hasImpl = build._hasImpl;
if (dynamic) {
builtClass.NAME = name;
builtClass.prototype.constructor = builtClass;
}
return builtClass;
};
Y.mix(Base.build, {
_template: function(main) {
function BuiltClass() {
BuiltClass.superclass.constructor.apply(this, arguments);
var f = BuiltClass._yuibuild.exts,
l = f.length,
i;
for (i = 0; i < l; i++) {
f[i].apply(this, arguments);
}
return this;
}
Y.extend(BuiltClass, main);
return BuiltClass;
},
_hasImpl : function(extClass) {
if (this.constructor._yuibuild) {
var f = this.constructor._yuibuild.exts,
l = f.length,
i;
for (i = 0; i < l; i++) {
if (f[i] === extClass) {
return true;
}
}
}
return false;
},
_getClass : function(main, cfg) {
var dynamic = (cfg && false === cfg.dynamic) ? false : true,
builtClass = (dynamic) ? Base.build._template(main) : main;
builtClass._yuibuild = {
id: null,
exts : [],
dynamic : dynamic
};
return builtClass;
},
_getAggregates : function(main, cfg) {
var aggr = [],
cfgAggr = (cfg && cfg.aggregates),
c = main,
classAggr;
while (c && c.prototype) {
classAggr = c._buildCfg && c._buildCfg.aggregates;
if (classAggr) {
aggr = aggr.concat(classAggr);
}
c = c.superclass ? c.superclass.constructor : null;
}
if (cfgAggr) {
aggr = aggr.concat(cfgAggr);
}
return aggr;
}
});
}, '@VERSION@' ,{requires:['base-base']});
YUI.add('base', function(Y){}, '@VERSION@' ,{use:['base-base', 'base-build']});