]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/base/base.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / base / base.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('base-base', function(Y) {
9
10     /**
11      * The base module provides the Base class, which objects requiring attribute and custom event support can extend. 
12      * The module also provides two ways to reuse code - It augments Base with the Plugin.Host interface which provides 
13      * plugin support and also provides the Base.build method which provides a way to build custom classes using extensions.
14      *
15      * @module base
16      */
17
18     /**
19      * The base-base submodule provides the Base class without the Plugin support, provided by Plugin.Host, 
20      * and without the extension support provided by Base.build.
21      *
22      * @module base
23      * @submodule base-base
24      */
25     var O = Y.Object,
26         L = Y.Lang,
27         DOT = ".",
28         DESTROY = "destroy",
29         INIT = "init",
30         INITIALIZED = "initialized",
31         DESTROYED = "destroyed",
32         INITIALIZER = "initializer",
33         BUBBLETARGETS = "bubbleTargets",
34         _BUBBLETARGETS = "_bubbleTargets",
35         OBJECT_CONSTRUCTOR = Object.prototype.constructor,
36         DEEP = "deep",
37         SHALLOW = "shallow",
38         DESTRUCTOR = "destructor",
39
40         Attribute = Y.Attribute;
41
42     /**
43      * <p>
44      * A base class which objects requiring attributes and custom event support can 
45      * extend. Base also handles the chaining of initializer and destructor methods across 
46      * the hierarchy as part of object construction and destruction. Additionally, attributes configured 
47      * through the static <a href="#property_Base.ATTRS">ATTRS</a> property for each class 
48      * in the hierarchy will be initialized by Base.
49      * </p>
50      *
51      * <p>
52      * The static <a href="#property_Base.NAME">NAME</a> property of each class extending 
53      * from Base will be used as the identifier for the class, and is used by Base to prefix 
54      * all events fired by instances of that class.
55      * </p>
56      *
57      * @class Base
58      * @constructor
59      * @uses Attribute
60      * @uses Plugin.Host
61      *
62      * @param {Object} config Object with configuration property name/value pairs. The object can be 
63      * used to provide default values for the objects published attributes.
64      *
65      * <p>
66      * The config object can also contain the following non-attribute properties, providing a convenient 
67      * way to configure events listeners and plugins for the instance, as part of the constructor call:
68      * </p>
69      *
70      * <dl>
71      *     <dt>on</dt>
72      *     <dd>An event name to listener function map, to register event listeners for the "on" moment of the event. A constructor convenience property for the <a href="Base.html#method_on">on</a> method.</dd>
73      *     <dt>after</dt>
74      *     <dd>An event name to listener function map, to register event listeners for the "after" moment of the event. A constructor convenience property for the <a href="Base.html#method_after">after</a> method.</dd>
75      *     <dt>bubbleTargets</dt>
76      *     <dd>An object, or array of objects, to register as bubble targets for bubbled events fired by this instance. A constructor convenience property for the <a href="EventTarget.html#method_addTarget">addTarget</a> method.</dd>
77      *     <dt>plugins</dt>
78      *     <dd>A plugin, or array of plugins to be plugged into the instance (see PluginHost's plug method for signature details). A constructor convenience property for the <a href="Plugin.Host.html#method_plug">plug</a> method.</dd>
79      * </dl>
80      */
81     function Base() {
82
83         // So the object can be used as a hash key (as DD does)
84         Y.stamp(this);
85
86         Attribute.call(this);
87
88         // If Plugin.Host has been augmented [ through base-pluginhost ], setup it's
89         // initial state, but don't initialize Plugins yet. That's done after initialization.
90         var PluginHost = Y.Plugin && Y.Plugin.Host;  
91         if (this._initPlugins && PluginHost) {
92             PluginHost.call(this);
93         }
94
95         if (this._lazyAddAttrs !== false) { this._lazyAddAttrs = true; }
96
97         /**
98          * The string used to identify the class of this object.
99          *
100          * @deprecated Use this.constructor.NAME
101          * @property name
102          * @type String
103          */
104         this.name = this.constructor.NAME;
105         this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
106
107         this.init.apply(this, arguments);
108     }
109
110     /**
111      * The list of properties which can be configured for 
112      * each attribute (e.g. setter, getter, writeOnce, readOnly etc.)
113      *
114      * @property Base._ATTR_CFG
115      * @type Array
116      * @static
117      * @private
118      */
119     Base._ATTR_CFG = Attribute._ATTR_CFG.concat("cloneDefaultValue");
120
121     /**
122      * <p>
123      * The string to be used to identify instances of 
124      * this class, for example in prefixing events.
125      * </p>
126      * <p>
127      * Classes extending Base, should define their own
128      * static NAME property, which should be camelCase by
129      * convention (e.g. MyClass.NAME = "myClass";).
130      * </p>
131      * @property Base.NAME
132      * @type String
133      * @static
134      */
135     Base.NAME = "base";
136
137     /**
138      * The default set of attributes which will be available for instances of this class, and 
139      * their configuration. In addition to the configuration properties listed by 
140      * Attribute's <a href="Attribute.html#method_addAttr">addAttr</a> method, the attribute 
141      * can also be configured with a "cloneDefaultValue" property, which defines how the statically
142      * defined value field should be protected ("shallow", "deep" and false are supported values). 
143      *
144      * By default if the value is an object literal or an array it will be "shallow" cloned, to 
145      * protect the default value.
146      *
147      * @property Base.ATTRS
148      * @type Object
149      * @static
150      */
151     Base.ATTRS = {
152         /**
153          * Flag indicating whether or not this object
154          * has been through the init lifecycle phase.
155          *
156          * @attribute initialized
157          * @readonly
158          * @default false
159          * @type boolean
160          */
161         initialized: {
162             readOnly:true,
163             value:false
164         },
165
166         /**
167          * Flag indicating whether or not this object
168          * has been through the destroy lifecycle phase.
169          *
170          * @attribute destroyed
171          * @readonly
172          * @default false
173          * @type boolean
174          */
175         destroyed: {
176             readOnly:true,
177             value:false
178         }
179     };
180
181     Base.prototype = {
182
183         /**
184          * Init lifecycle method, invoked during construction.
185          * Fires the init event prior to setting up attributes and 
186          * invoking initializers for the class hierarchy.
187          *
188          * @method init
189          * @final
190          * @chainable
191          * @param {Object} config Object with configuration property name/value pairs
192          * @return {Base} A reference to this object
193          */
194         init: function(config) {
195
196             this._yuievt.config.prefix = this._eventPrefix;
197
198             /**
199              * <p>
200              * Lifecycle event for the init phase, fired prior to initialization. 
201              * Invoking the preventDefault() method on the event object provided 
202              * to subscribers will prevent initialization from occuring.
203              * </p>
204              * <p>
205              * Subscribers to the "after" momemt of this event, will be notified
206              * after initialization of the object is complete (and therefore
207              * cannot prevent initialization).
208              * </p>
209              *
210              * @event init
211              * @preventable _defInitFn
212              * @param {EventFacade} e Event object, with a cfg property which 
213              * refers to the configuration object passed to the constructor.
214              */
215             this.publish(INIT, {
216                 queuable:false,
217                 fireOnce:true,
218                 defaultTargetOnly:true,
219                 defaultFn:this._defInitFn
220             });
221
222             this._preInitEventCfg(config);
223
224             this.fire(INIT, {cfg: config});
225
226             return this;
227         },
228
229         /**
230          * Handles the special on, after and target properties which allow the user to
231          * easily configure on and after listeners as well as bubble targets during 
232          * construction, prior to init.
233          *
234          * @private
235          * @method _preInitEventCfg
236          * @param {Object} config The user configuration object
237          */
238         _preInitEventCfg : function(config) {
239             if (config) {
240                 if (config.on) {
241                     this.on(config.on);
242                 }
243                 if (config.after) {
244                     this.after(config.after);
245                 }
246             }
247
248             var i, l, target,
249                 userTargets = (config && BUBBLETARGETS in config);
250
251             if (userTargets || _BUBBLETARGETS in this) {
252                 target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
253                 if (L.isArray(target)) {
254                     for (i = 0, l = target.length; i < l; i++) { 
255                         this.addTarget(target[i]);
256                     }
257                 } else if (target) {
258                     this.addTarget(target);
259                 }
260             }
261         },
262
263         /**
264          * <p>
265          * Destroy lifecycle method. Fires the destroy
266          * event, prior to invoking destructors for the
267          * class hierarchy.
268          * </p>
269          * <p>
270          * Subscribers to the destroy
271          * event can invoke preventDefault on the event object, to prevent destruction
272          * from proceeding.
273          * </p>
274          * @method destroy
275          * @return {Base} A reference to this object
276          * @final
277          * @chainable
278          */
279         destroy: function() {
280
281             /**
282              * <p>
283              * Lifecycle event for the destroy phase, 
284              * fired prior to destruction. Invoking the preventDefault 
285              * method on the event object provided to subscribers will 
286              * prevent destruction from proceeding.
287              * </p>
288              * <p>
289              * Subscribers to the "after" moment of this event, will be notified
290              * after destruction is complete (and as a result cannot prevent
291              * destruction).
292              * </p>
293              * @event destroy
294              * @preventable _defDestroyFn
295              * @param {EventFacade} e Event object
296              */
297             this.publish(DESTROY, {
298                 queuable:false,
299                 fireOnce:true,
300                 defaultTargetOnly:true,
301                 defaultFn: this._defDestroyFn
302             });
303             this.fire(DESTROY);
304
305             this.detachAll();
306             return this;
307         },
308
309         /**
310          * Default init event handler
311          *
312          * @method _defInitFn
313          * @param {EventFacade} e Event object, with a cfg property which 
314          * refers to the configuration object passed to the constructor.
315          * @protected
316          */
317         _defInitFn : function(e) {
318             this._initHierarchy(e.cfg);
319             if (this._initPlugins) {
320                 // Need to initPlugins manually, to handle constructor parsing, static Plug parsing
321                 this._initPlugins(e.cfg);
322             }
323             this._set(INITIALIZED, true);
324         },
325
326         /**
327          * Default destroy event handler
328          *
329          * @method _defDestroyFn
330          * @param {EventFacade} e Event object
331          * @protected
332          */
333         _defDestroyFn : function(e) {
334             this._destroyHierarchy();
335             if (this._destroyPlugins) {
336                 this._destroyPlugins();
337             }
338             this._set(DESTROYED, true);
339         },
340
341         /**
342          * Returns the class hierarchy for this object, with Base being the last class in the array.
343          *
344          * @method _getClasses
345          * @protected
346          * @return {Function[]} An array of classes (constructor functions), making up the class hierarchy for this object.
347          * This value is cached the first time the method, or _getAttrCfgs, is invoked. Subsequent invocations return the 
348          * cached value.
349          */
350         _getClasses : function() {
351             if (!this._classes) {
352                 this._initHierarchyData();
353             }
354             return this._classes;
355         },
356
357         /**
358          * Returns an aggregated set of attribute configurations, by traversing the class hierarchy.
359          *
360          * @method _getAttrCfgs
361          * @protected
362          * @return {Object} The hash of attribute configurations, aggregated across classes in the hierarchy
363          * This value is cached the first time the method, or _getClasses, is invoked. Subsequent invocations return
364          * the cached value.
365          */
366         _getAttrCfgs : function() {
367             if (!this._attrs) {
368                 this._initHierarchyData();
369             }
370             return this._attrs;
371         },
372
373         /**
374          * A helper method used when processing ATTRS across the class hierarchy during 
375          * initialization. Returns a disposable object with the attributes defined for 
376          * the provided class, extracted from the set of all attributes passed in .
377          *
378          * @method _filterAttrCfs
379          * @private
380          *
381          * @param {Function} clazz The class for which the desired attributes are required.
382          * @param {Object} allCfgs The set of all attribute configurations for this instance. 
383          * Attributes will be removed from this set, if they belong to the filtered class, so
384          * that by the time all classes are processed, allCfgs will be empty.
385          * 
386          * @return {Object} The set of attributes belonging to the class passed in, in the form
387          * of an object with attribute name/configuration pairs.
388          */
389         _filterAttrCfgs : function(clazz, allCfgs) {
390             var cfgs = null, attr, attrs = clazz.ATTRS;
391
392             if (attrs) {
393                 for (attr in attrs) {
394                     if (attrs.hasOwnProperty(attr) && allCfgs[attr]) {
395                         cfgs = cfgs || {};
396                         cfgs[attr] = allCfgs[attr];
397                         delete allCfgs[attr];
398                     }
399                 }
400             }
401
402             return cfgs;
403         },
404
405         /**
406          * A helper method used by _getClasses and _getAttrCfgs, which determines both
407          * the array of classes and aggregate set of attribute configurations
408          * across the class hierarchy for the instance.
409          * 
410          * @method _initHierarchyData
411          * @private
412          */
413         _initHierarchyData : function() {
414             var c = this.constructor, 
415                 classes = [],
416                 attrs = [];
417
418             while (c) {
419                 // Add to classes
420                 classes[classes.length] = c;
421
422                 // Add to attributes
423                 if (c.ATTRS) {
424                     attrs[attrs.length] = c.ATTRS;
425                 }
426                 c = c.superclass ? c.superclass.constructor : null;
427             }
428
429             this._classes = classes;
430             this._attrs = this._aggregateAttrs(attrs);
431         },
432
433         /**
434          * A helper method, used by _initHierarchyData to aggregate 
435          * attribute configuration across the instances class hierarchy.
436          *
437          * The method will potect the attribute configuration value to protect the statically defined 
438          * default value in ATTRS if required (if the value is an object literal, array or the 
439          * attribute configuration has cloneDefaultValue set to shallow or deep).
440          *
441          * @method _aggregateAttrs
442          * @private
443          * @param {Array} allAttrs An array of ATTRS definitions across classes in the hierarchy 
444          * (subclass first, Base last)
445          * @return {Object} The aggregate set of ATTRS definitions for the instance
446          */
447         _aggregateAttrs : function(allAttrs) {
448             var attr,
449                 attrs,
450                 cfg,
451                 val,
452                 path,
453                 i, 
454                 clone, 
455                 cfgProps = Base._ATTR_CFG,
456                 aggAttrs = {};
457
458             if (allAttrs) {
459                 for (i = allAttrs.length-1; i >= 0; --i) {
460                     attrs = allAttrs[i];
461
462                     for (attr in attrs) {
463                         if (attrs.hasOwnProperty(attr)) {
464
465                             // Protect config passed in
466                             cfg = Y.mix({}, attrs[attr], true, cfgProps);
467
468                             val = cfg.value;
469                             clone = cfg.cloneDefaultValue;
470
471                             if (val) {
472                                 if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
473                                     cfg.value = Y.clone(val);
474                                 } else if (clone === SHALLOW) {
475                                     cfg.value = Y.merge(val);
476                                 }
477                                 // else if (clone === false), don't clone the static default value. 
478                                 // It's intended to be used by reference.
479                             }
480
481                             path = null;
482                             if (attr.indexOf(DOT) !== -1) {
483                                 path = attr.split(DOT);
484                                 attr = path.shift();
485                             }
486
487                             if (path && aggAttrs[attr] && aggAttrs[attr].value) {
488                                 O.setValue(aggAttrs[attr].value, path, val);
489                             } else if (!path){
490                                 if (!aggAttrs[attr]) {
491                                     aggAttrs[attr] = cfg;
492                                 } else {
493                                     Y.mix(aggAttrs[attr], cfg, true, cfgProps);
494                                 }
495                             }
496                         }
497                     }
498                 }
499             }
500
501             return aggAttrs;
502         },
503
504         /**
505          * Initializes the class hierarchy for the instance, which includes 
506          * initializing attributes for each class defined in the class's 
507          * static <a href="#property_Base.ATTRS">ATTRS</a> property and 
508          * invoking the initializer method on the prototype of each class in the hierarchy.
509          *
510          * @method _initHierarchy
511          * @param {Object} userVals Object with configuration property name/value pairs
512          * @private
513          */
514         _initHierarchy : function(userVals) {
515             var lazy = this._lazyAddAttrs,
516                 constr,
517                 constrProto,
518                 ci,
519                 ei,
520                 el,
521                 classes = this._getClasses(),
522                 attrCfgs = this._getAttrCfgs();
523
524             for (ci = classes.length-1; ci >= 0; ci--) {
525
526                 constr = classes[ci];
527                 constrProto = constr.prototype;
528
529                 if (constr._yuibuild && constr._yuibuild.exts) {
530                     for (ei = 0, el = constr._yuibuild.exts.length; ei < el; ei++) {
531                         constr._yuibuild.exts[ei].apply(this, arguments);
532                     }
533                 }
534
535                 this.addAttrs(this._filterAttrCfgs(constr, attrCfgs), userVals, lazy);
536
537                 // Using INITIALIZER in hasOwnProperty check, for performance reasons (helps IE6 avoid GC thresholds when
538                 // referencing string literals). Not using it in apply, again, for performance "." is faster. 
539                 if (constrProto.hasOwnProperty(INITIALIZER)) {
540                     constrProto.initializer.apply(this, arguments);
541                 }
542             }
543         },
544
545         /**
546          * Destroys the class hierarchy for this instance by invoking
547          * the descructor method on the prototype of each class in the hierarchy.
548          *
549          * @method _destroyHierarchy
550          * @private
551          */
552         _destroyHierarchy : function() {
553             var constr,
554                 constrProto,
555                 ci, cl,
556                 classes = this._getClasses();
557
558             for (ci = 0, cl = classes.length; ci < cl; ci++) {
559                 constr = classes[ci];
560                 constrProto = constr.prototype;
561                 if (constrProto.hasOwnProperty(DESTRUCTOR)) {
562                     constrProto.destructor.apply(this, arguments);
563                 }
564             }
565         },
566
567         /**
568          * Default toString implementation. Provides the constructor NAME
569          * and the instance guid, if set.
570          *
571          * @method toString
572          * @return {String} String representation for this object
573          */
574         toString: function() {
575             return this.name + "[" + Y.stamp(this, true) + "]";
576         }
577
578     };
579
580     // Straightup augment, no wrapper functions
581     Y.mix(Base, Attribute, false, null, 1);
582
583     // Fix constructor
584     Base.prototype.constructor = Base;
585
586     Y.Base = Base;
587
588
589 }, '3.3.0' ,{requires:['attribute-base']});
590 YUI.add('base-pluginhost', function(Y) {
591
592     /**
593      * The base-pluginhost submodule adds Plugin support to Base, by augmenting Base with 
594      * Plugin.Host and setting up static (class level) Base.plug and Base.unplug methods.
595      *
596      * @module base
597      * @submodule base-pluginhost
598      * @for Base
599      */
600
601     var Base = Y.Base,
602         PluginHost = Y.Plugin.Host;
603
604     Y.mix(Base, PluginHost, false, null, 1);
605
606     /**
607      * Alias for <a href="Plugin.Host.html#method_Plugin.Host.plug">Plugin.Host.plug</a>. See aliased 
608      * method for argument and return value details.
609      *
610      * @method Base.plug
611      * @static
612      */
613     Base.plug = PluginHost.plug;
614
615     /**
616      * Alias for <a href="Plugin.Host.html#method_Plugin.Host.unplug">Plugin.Host.unplug</a>. See the 
617      * aliased method for argument and return value details.
618      *
619      * @method Base.unplug
620      * @static
621      */
622     Base.unplug = PluginHost.unplug;
623
624
625 }, '3.3.0' ,{requires:['base-base', 'pluginhost']});
626 YUI.add('base-build', function(Y) {
627
628     /**
629      * The base-build submodule provides Base.build functionality, which
630      * can be used to create custom classes, by aggregating extensions onto 
631      * a main class.
632      *
633      * @module base
634      * @submodule base-build
635      * @for Base
636      */
637     var Base = Y.Base,
638         L = Y.Lang,
639         build;
640
641     Base._build = function(name, main, extensions, px, sx, cfg) {
642
643         var build = Base._build,
644
645             builtClass = build._ctor(main, cfg),
646             buildCfg = build._cfg(main, cfg),
647
648             _mixCust = build._mixCust,
649
650             aggregates = buildCfg.aggregates,
651             custom = buildCfg.custom,
652
653             dynamic = builtClass._yuibuild.dynamic,
654
655             i, l, val, extClass;
656
657         if (dynamic && aggregates) {
658             for (i = 0, l = aggregates.length; i < l; ++i) {
659                 val = aggregates[i];
660                 if (main.hasOwnProperty(val)) {
661                     builtClass[val] = L.isArray(main[val]) ? [] : {};
662                 }
663             }
664         }
665
666         // Augment/Aggregate
667         for (i = 0, l = extensions.length; i < l; i++) {
668             extClass = extensions[i];
669
670             // Prototype, old non-displacing augment
671             Y.mix(builtClass, extClass, true, null, 1);
672              // Custom Statics
673             _mixCust(builtClass, extClass, aggregates, custom);
674
675             builtClass._yuibuild.exts.push(extClass);
676         }
677
678         if (px) {
679             Y.mix(builtClass.prototype, px, true);
680         }
681
682         if (sx) {
683             Y.mix(builtClass, build._clean(sx, aggregates, custom), true);
684             _mixCust(builtClass, sx, aggregates, custom);
685         }
686
687         builtClass.prototype.hasImpl = build._impl;
688
689         if (dynamic) {
690             builtClass.NAME = name;
691             builtClass.prototype.constructor = builtClass;
692         }
693
694         return builtClass;
695     };
696
697     build = Base._build;
698
699     Y.mix(build, {
700
701         _mixCust: function(r, s, aggregates, custom) {
702
703             if (aggregates) {
704                 Y.aggregate(r, s, true, aggregates);
705             }
706
707             if (custom) {
708                 for (var j in custom) {
709                     if (custom.hasOwnProperty(j)) {
710                         custom[j](j, r, s);
711                     }
712                 }
713             }
714         },
715
716         _tmpl: function(main) {
717
718             function BuiltClass() {
719                 BuiltClass.superclass.constructor.apply(this, arguments);
720             }
721             Y.extend(BuiltClass, main);
722
723             return BuiltClass;
724         },
725
726         _impl : function(extClass) {
727             var classes = this._getClasses(), i, l, cls, exts, ll, j;
728             for (i = 0, l = classes.length; i < l; i++) {
729                 cls = classes[i];
730                 if (cls._yuibuild) {
731                     exts = cls._yuibuild.exts;
732                     ll = exts.length;
733     
734                     for (j = 0; j < ll; j++) {
735                         if (exts[j] === extClass) {
736                             return true;
737                         }
738                     }
739                 }
740             }
741             return false;
742         },
743
744         _ctor : function(main, cfg) {
745
746            var dynamic = (cfg && false === cfg.dynamic) ? false : true,
747                builtClass = (dynamic) ? build._tmpl(main) : main,
748                buildCfg = builtClass._yuibuild;
749
750             if (!buildCfg) {
751                 buildCfg = builtClass._yuibuild = {};
752             }
753
754             buildCfg.id = buildCfg.id || null;
755             buildCfg.exts = buildCfg.exts || [];
756             buildCfg.dynamic = dynamic;
757
758             return builtClass;
759         },
760
761         _cfg : function(main, cfg) {
762             var aggr = [], 
763                 cust = {},
764                 buildCfg,
765                 cfgAggr = (cfg && cfg.aggregates),
766                 cfgCustBuild = (cfg && cfg.custom),
767                 c = main;
768
769             while (c && c.prototype) {
770                 buildCfg = c._buildCfg; 
771                 if (buildCfg) {
772                     if (buildCfg.aggregates) {
773                         aggr = aggr.concat(buildCfg.aggregates);
774                     }
775                     if (buildCfg.custom) {
776                         Y.mix(cust, buildCfg.custom, true);
777                     }
778                 }
779                 c = c.superclass ? c.superclass.constructor : null;
780             }
781
782             if (cfgAggr) {
783                 aggr = aggr.concat(cfgAggr);
784             }
785             if (cfgCustBuild) {
786                 Y.mix(cust, cfg.cfgBuild, true);
787             }
788
789             return {
790                 aggregates: aggr,
791                 custom: cust
792             };
793         },
794
795         _clean : function(sx, aggregates, custom) {
796             var prop, i, l, sxclone = Y.merge(sx);
797
798             for (prop in custom) {
799                 if (sxclone.hasOwnProperty(prop)) {
800                     delete sxclone[prop];
801                 }
802             }
803
804             for (i = 0, l = aggregates.length; i < l; i++) {
805                 prop = aggregates[i];
806                 if (sxclone.hasOwnProperty(prop)) {
807                     delete sxclone[prop];
808                 }
809             }
810
811             return sxclone;
812         }
813     });
814
815     /**
816      * <p>
817      * Builds a custom constructor function (class) from the
818      * main function, and array of extension functions (classes)
819      * provided. The NAME field for the constructor function is 
820      * defined by the first argument passed in.
821      * </p>
822      * <p>
823      * The cfg object supports the following properties
824      * </p>
825      * <dl>
826      *    <dt>dynamic &#60;boolean&#62;</dt>
827      *    <dd>
828      *    <p>If true (default), a completely new class
829      *    is created which extends the main class, and acts as the 
830      *    host on which the extension classes are augmented.</p>
831      *    <p>If false, the extensions classes are augmented directly to
832      *    the main class, modifying the main class' prototype.</p>
833      *    </dd>
834      *    <dt>aggregates &#60;String[]&#62;</dt>
835      *    <dd>An array of static property names, which will get aggregated
836      *    on to the built class, in addition to the default properties build 
837      *    will always aggregate as defined by the main class' static _buildCfg
838      *    property.
839      *    </dd>
840      * </dl>
841      *
842      * @method Base.build
843      * @deprecated Use the more convenient Base.create and Base.mix methods instead
844      * @static
845      * @param {Function} name The name of the new class. Used to defined the NAME property for the new class.
846      * @param {Function} main The main class on which to base the built class
847      * @param {Function[]} extensions The set of extension classes which will be
848      * augmented/aggregated to the built class.
849      * @param {Object} cfg Optional. Build configuration for the class (see description).
850      * @return {Function} A custom class, created from the provided main and extension classes
851      */
852     Base.build = function(name, main, extensions, cfg) {
853         return build(name, main, extensions, null, null, cfg);
854     };
855
856     /**
857      * <p>Creates a new class (constructor function) which extends the base class passed in as the second argument, 
858      * and mixes in the array of extensions provided.</p>
859      * <p>Prototype properties or methods can be added to the new class, using the px argument (similar to Y.extend).</p>
860      * <p>Static properties or methods can be added to the new class, using the sx argument (similar to Y.extend).</p>
861      * <p>
862      * 
863      * </p>
864      * @method Base.create
865      * @static
866      * @param {Function} name The name of the newly created class. Used to defined the NAME property for the new class.
867      * @param {Function} main The base class which the new class should extend. This class needs to be Base or a class derived from base (e.g. Widget).
868      * @param {Function[]} extensions The list of extensions which will be mixed into the built class.
869      * @param {Object} px The set of prototype properties/methods to add to the built class.
870      * @param {Object} sx The set of static properties/methods to add to the built class.
871      * @return {Function} The newly created class.
872      */
873     Base.create = function(name, base, extensions, px, sx) {
874         return build(name, base, extensions, px, sx);
875     };
876
877     /**
878      * <p>Mixes in a list of extensions to an existing class.</p>
879      * @method Base.mix
880      * @static
881      * @param {Function} main The existing class into which the extensions should be mixed.  The class needs to be Base or class derived from base (e.g. Widget)
882      * @param {Function[]} extensions The set of extension classes which will mixed into the existing main class.
883      * @return {Function} The modified main class, with extensions mixed in.
884      */
885     Base.mix = function(main, extensions) {
886         return build(null, main, extensions, null, null, {dynamic:false});
887     };
888
889     /**
890      * The build configuration for the Base class.
891      *
892      * Defines the static fields which need to be aggregated
893      * when the Base class is used as the main class passed to
894      * the <a href="#method_Base.build">Base.build</a> method.
895      *
896      * @property Base._buildCfg
897      * @type Object
898      * @static
899      * @final
900      * @private
901      */
902     Base._buildCfg = {
903         custom : { 
904             ATTRS : function(prop, r, s) {
905
906                 r.ATTRS = r.ATTRS || {};
907
908                 if (s.ATTRS) {
909
910                     var sAttrs = s.ATTRS,
911                         rAttrs = r.ATTRS,
912                         a;
913
914                     for (a in sAttrs) {
915                         if (sAttrs.hasOwnProperty(a)) {
916                             rAttrs[a] = rAttrs[a] || {};
917                             Y.mix(rAttrs[a], sAttrs[a], true);
918                         }
919                     }
920                 }
921             }
922         },
923         aggregates : ["_PLUG", "_UNPLUG"]
924     };
925
926
927 }, '3.3.0' ,{requires:['base-base']});
928
929
930 YUI.add('base', function(Y){}, '3.3.0' ,{after:['attribute-complex'], use:['base-base', 'base-pluginhost', 'base-build']});
931