Base.js revision 3a81ce564b8d21870eb054300f28209035ce88ce
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Base class support for objects requiring managed attributes and acting as event targets.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * The base module also provides an augmentable PluginHost interface.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @module base
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * The base-base sub-module provides the Base class, without Base.build functionality
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @module base
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @sub-module base-base
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync var O = Y.Object,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DOT = ".",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DESTROY = "destroy",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync INIT = "init",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync INITIALIZED = "initialized",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DESTROYED = "destroyed",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync INITIALIZER = "initializer",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync OBJECT_CONSTRUCTOR = Object.prototype.constructor,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DEEP = "deep",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync SHALLOW = "shallow",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync VALUE = "value",
b2640405e06105d868b5fc8f7b676bb680884380vboxsync DESTRUCTOR = "destructor";
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Provides a base class for managed attribute based
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * objects, which handles the chaining of initializer and destructor methods
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * across the hierarchy during init and destroy lifecycle methods and
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * handles automatic configuration of registered Attributes, through
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * the static <a href="#property_ATTRS">ATTRS</a> property.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>The Base class also handles prefixing of event types with the static <a href="#property_NAME">NAME</a>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * property for all events fired from instances of classes derived from Base.</p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @constructor
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @class Base
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @uses Attribute, Plugin.Host
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Object} config Object literal of configuration property name/value pairs
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync function Base() {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Y.log('constructor called', 'life', 'base');
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Y.Attribute.call(this);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Y.Plugin.Host.call(this);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._silentInit = this._silentInit || false;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (this._lazyAttrInit !== false) { this._lazyAttrInit = true; }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.init.apply(this, arguments);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Name string to be used to identify instances of
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * this class, for example in prefixing events.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Classes extending Base, should define their own
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * static NAME property.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @property NAME
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @type String
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @static
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Base.NAME = 'base';
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Object literal defining the set of attributes which
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * will be available for instances of this class, and
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * how they are configured. See Attributes addAtt method
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * for a description of configuration options available
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * for each attribute.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @property ATTRS
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @type Object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @static
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Base.ATTRS = {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Flag indicating whether or not this object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * has been through the init lifecycle phase.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @attribute initialized
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @readOnly
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @default false
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @type boolean
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync initialized: {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync readOnly:true,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync value:false
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Flag indicating whether or not this object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * has been through the destroy lifecycle phase.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @attribute destroyed
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @readOnly
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @default false
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @type boolean
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync destroyed: {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync readOnly:true,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync value:false
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync };
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Base.prototype = {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Init lifecycle method, invoked during construction.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Fires the init event prior to invoking initializers on
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * the class hierarchy.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method init
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @final
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @chainable
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Object} config Object literal of configuration property name/value pairs
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @return {Base} A reference to this object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync init: function(config) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Y.log('init called', 'life', 'base');
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * The name string to be used to identify
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * this instance of object.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @property name
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @type String
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._yuievt.config.prefix = this.name = this.constructor.NAME;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Lifecycle event for the init phase, fired prior to initialization.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Invoking the preventDefault method on the event object provided
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * to subscribers will prevent initialization from occuring.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Subscribers to the "after" momemt of this event, will be notified
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * after initialization of the object is complete (and therefore
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * cannot prevent initialization).
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @event init
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @preventable _defInitFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Event.Facade} e Event object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param config Object literal of configuration name/value pairs
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (!this._silentInit) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.publish(INIT, {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync queuable:false,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync defaultFn:this._defInitFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync });
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (config) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (config.on) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.on(config.on);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (config.after) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.after(config.after);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (!this._silentInit) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.fire(INIT, {cfg: config});
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync } else {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._defInitFn({cfg: config});
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync return this;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Destroy lifecycle method. Fires the destroy
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * event, prior to invoking destructors for the
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * class hierarchy.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Subscribers to the destroy
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * event can invoke preventDefault on the event object, to prevent destruction
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * from proceeding.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method destroy
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @return {Base} A reference to this object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @final
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @chainable
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync destroy: function() {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync Y.log('destroy called', 'life', 'base');
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Lifecycle event for the destroy phase,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * fired prior to destruction. Invoking the preventDefault
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * method on the event object provided to subscribers will
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * prevent destruction from proceeding.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * <p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Subscribers to the "after" moment of this event, will be notified
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * after destruction is complete (and as a result cannot prevent
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * destruction).
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * </p>
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @event destroy
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @preventable _defDestroyFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Event.Facade} e Event object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.publish(DESTROY, {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync queuable:false,
b2640405e06105d868b5fc8f7b676bb680884380vboxsync defaultFn: this._defDestroyFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync });
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this.fire(DESTROY);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync return this;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Default init event handler
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method _defInitFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Event.Facade} e Event object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @protected
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync _defInitFn : function(e) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._initHierarchy(e.cfg);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._initPlugins(e.cfg);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (!this._silentInit) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._set(INITIALIZED, true);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync } else {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._conf.add(INITIALIZED, VALUE, true);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Default destroy event handler
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method _defDestroyFn
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @param {Event.Facade} e Event object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @protected
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync _defDestroyFn : function(e) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._destroyHierarchy();
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._destroyPlugins();
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._set(DESTROYED, true);
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Returns the class hierarchy for this object, with Base being the last class in the array.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method _getClasses
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @protected
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @return {Function[]} An Array of classes (constructor functions), making up the class hierarchy for this object
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
b2640405e06105d868b5fc8f7b676bb680884380vboxsync _getClasses : function() {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync if (!this._classes) {
b2640405e06105d868b5fc8f7b676bb680884380vboxsync this._initHierarchyData();
b2640405e06105d868b5fc8f7b676bb680884380vboxsync }
b2640405e06105d868b5fc8f7b676bb680884380vboxsync return this._classes;
b2640405e06105d868b5fc8f7b676bb680884380vboxsync },
b2640405e06105d868b5fc8f7b676bb680884380vboxsync
b2640405e06105d868b5fc8f7b676bb680884380vboxsync /**
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
b2640405e06105d868b5fc8f7b676bb680884380vboxsync *
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @method _getAttrCfgs
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @protected
b2640405e06105d868b5fc8f7b676bb680884380vboxsync * @return {Object} The hash of attribute configurations, aggregated across classes in the hierarchy
b2640405e06105d868b5fc8f7b676bb680884380vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _getAttrCfgs : function() {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (!this._attrs) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync this._initHierarchyData();
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync return this._attrs;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method _filterAttrCfs
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @private
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @param {Function} clazz
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @param {Objects} allCfgs
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _filterAttrCfgs : function(clazz, allCfgs) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync var cfgs = {};
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (clazz.ATTRS) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.each(clazz.ATTRS, function(v, k) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (allCfgs[k]) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync cfgs[k] = allCfgs[k];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync delete allCfgs[k];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync });
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync return cfgs;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method _initHierarchyData
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @private
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _initHierarchyData : function() {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync var c = this.constructor,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync classes = [],
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync attrs = [];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync while (c) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // Add to classes
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync classes[classes.length] = c;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // Add to attributes
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (c.ATTRS) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync attrs[attrs.length] = c.ATTRS;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync c = c.superclass ? c.superclass.constructor : null;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync this._classes = classes;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync this._attrs = this._aggregateAttrs(attrs);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method _aggregateAttrs
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @private
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @param {Object} allAttrs
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _aggregateAttrs : function(allAttrs) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync var attr, attrs, cfg, val, path, i, clone,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync aggAttrs = {};
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (allAttrs) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync for (i = allAttrs.length-1; i >= 0; --i) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync attrs = allAttrs[i];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync for (attr in attrs) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (attrs.hasOwnProperty(attr)) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // Protect
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync cfg = Y.merge(attrs[attr]);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync val = cfg.value;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync clone = cfg.cloneDefaultValue;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (val) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.log('Cloning default value for attribute:' + attr, 'info', 'base');
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync cfg.value = Y.clone(val);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync } else if (clone === SHALLOW) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.log('Merging default value for attribute:' + attr, 'info', 'base');
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync cfg.value = Y.merge(val);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // else if (clone === false), don't clone the static default value.
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // It's intended to be used by reference.
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync path = null;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (attr.indexOf(DOT) !== -1) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync path = attr.split(DOT);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync attr = path.shift();
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (path && aggAttrs[attr] && aggAttrs[attr].value) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync O.setValue(aggAttrs[attr].value, path, val);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync } else if (!path){
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (!aggAttrs[attr]) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync aggAttrs[attr] = cfg;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync } else {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync aggAttrs[attr] = Y.mix(aggAttrs[attr], cfg, true);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync return aggAttrs;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * Initializes the class hierarchy rooted at this base class,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * which includes initializing attributes for each class defined
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * in the class's static <a href="#property_ATTRS">ATTRS</a> property and invoking the initializer
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * method on the prototype of each class in the hierarchy.
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync *
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method _initHierarchy
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @param {Object} userVals Object literal containing attribute name/value pairs
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @private
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _initHierarchy : function(userVals) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync var lazy = this._lazyAttrInit,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constr,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync ci,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync ei,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync el,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync classes = this._getClasses(),
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync attrCfgs = this._getAttrCfgs();
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync for (ci = classes.length-1; ci >= 0; ci--) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constr = classes[ci];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto = constr.prototype;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (constr._yuibuild && constr._yuibuild.exts && !constr._yuibuild.dynamic) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync for (ei = 0, el = constr._yuibuild.exts.length; ei < el; ei++) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constr._yuibuild.exts[ei].apply(this, arguments);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync this.addAttrs(this._filterAttrCfgs(constr, attrCfgs), userVals, lazy);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (constrProto.hasOwnProperty(INITIALIZER)) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto.initializer.apply(this, arguments);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * Destroys the class hierarchy rooted at this base class by invoking
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * the descructor method on the prototype of each class in the hierarchy.
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync *
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method _destroyHierarchy
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @private
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync _destroyHierarchy : function() {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync var constr,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync ci, cl,
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync classes = this._getClasses();
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync for (ci = 0, cl = classes.length; ci < cl; ci++) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constr = classes[ci];
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto = constr.prototype;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync if (constrProto.hasOwnProperty(DESTRUCTOR)) {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync constrProto.destructor.apply(this, arguments);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync },
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync /**
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * Default toString implementation. Provides the constructor NAME
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * and the instance ID.
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync *
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @method toString
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync * @return {String} String representation for this object
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync */
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync toString: function() {
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync return this.constructor.NAME + "[" + Y.stamp(this) + "]";
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync }
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync };
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // Straightup augment, no wrapper functions
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.mix(Base, Y.Attribute, false, null, 1);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.mix(Base, PluginHost, false, null, 1);
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Base.plug = PluginHost.plug;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Base.unplug = PluginHost.unplug;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync // Fix constructor
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Base.prototype.constructor = Base;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync Y.Base = Base;
eb4f1fa4c357485330370c0eaba27e5a2af7d9c4vboxsync