Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
YUI.add('base-base', function (Y, NAME) {
2
 
3
    /**
4
     * The base module provides the Base class, which objects requiring attribute and custom event support can extend.
5
     * The module also provides two ways to reuse code - It augments Base with the Plugin.Host interface which provides
6
     * plugin support and also provides the BaseCore.build method which provides a way to build custom classes using extensions.
7
     *
8
     * @module base
9
     */
10
 
11
    /**
12
     * The base-base submodule provides the Base class without the Plugin support, provided by Plugin.Host,
13
     * and without the extension support provided by BaseCore.build.
14
     *
15
     * @module base
16
     * @submodule base-base
17
     */
18
 
19
    var AttributeCore   = Y.AttributeCore,
20
        AttributeExtras = Y.AttributeExtras,
21
        BaseCore        = Y.BaseCore,
22
        BaseObservable  = Y.BaseObservable;
23
 
24
    /**
25
     * <p>
26
     * A base class which objects requiring attributes and custom event support can
27
     * extend. Base also handles the chaining of initializer and destructor methods across
28
     * the hierarchy as part of object construction and destruction. Additionally, attributes configured
29
     * through the static <a href="#property_ATTRS">ATTRS</a> property for each class
30
     * in the hierarchy will be initialized by Base.
31
     * </p>
32
     *
33
     * <p>
34
     * **NOTE:** Prior to version 3.11.0, ATTRS would get added a class at a time. That is,
35
     * Base would loop through each class in the hierarchy, and add the class' ATTRS, and
36
     * then call it's initializer, and move on to the subclass' ATTRS and initializer. As of
37
     * 3.11.0, ATTRS from all classes in the hierarchy are added in one `addAttrs` call before
38
     * any initializers are called. This fixes subtle edge-case issues with subclass ATTRS overriding
39
     * superclass `setter`, `getter` or `valueFn` definitions and being unable to get/set attributes
40
     * defined by the subclass. This order of operation change may impact `setter`, `getter` or `valueFn`
41
     * code which expects a superclass' initializer to have run. This is expected to be rare, but to support
42
     * it, Base supports a `_preAddAttrs()`, method hook (same signature as `addAttrs`). Components can
43
     * implement this method on their prototype for edge cases which do require finer control over
44
     * the order in which attributes are added (see widget-htmlparser).
45
     * </p>
46
     *
47
     * <p>
48
     * The static <a href="#property_NAME">NAME</a> property of each class extending
49
     * from Base will be used as the identifier for the class, and is used by Base to prefix
50
     * all events fired by instances of that class.
51
     * </p>
52
     *
53
     * @class Base
54
     * @constructor
55
     * @uses BaseCore
56
     * @uses BaseObservable
57
     * @uses AttributeCore
58
     * @uses AttributeObservable
59
     * @uses AttributeExtras
60
     * @uses EventTarget
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.
73
     *       A constructor convenience property for the <a href="Base.html#method_on">on</a> method.</dd>
74
     *   <dt>after</dt>
75
     *   <dd>An event name to listener function map, to register event listeners for the "after" moment of the event.
76
     *       A constructor convenience property for the <a href="Base.html#method_after">after</a> method.</dd>
77
     *   <dt>bubbleTargets</dt>
78
     *   <dd>An object, or array of objects, to register as bubble targets for bubbled events fired by this instance.
79
     *       A constructor convenience property for the <a href="EventTarget.html#method_addTarget">addTarget</a> method.</dd>
80
     *   <dt>plugins</dt>
81
     *   <dd>A plugin, or array of plugins to be plugged into the instance (see PluginHost's plug method for signature details).
82
     *       A constructor convenience property for the <a href="Plugin.Host.html#method_plug">plug</a> method.</dd>
83
     * </dl>
84
     */
85
    function Base() {
86
        BaseCore.apply(this, arguments);
87
        BaseObservable.apply(this, arguments);
88
        AttributeExtras.apply(this, arguments);
89
    }
90
 
91
    /**
92
     * The list of properties which can be configured for
93
     * each attribute (e.g. setter, getter, writeOnce, readOnly etc.)
94
     *
95
     * @property _ATTR_CFG
96
     * @type Array
97
     * @static
98
     * @private
99
     */
100
    Base._ATTR_CFG = BaseCore._ATTR_CFG.concat(BaseObservable._ATTR_CFG);
101
 
102
    /**
103
     * The array of non-attribute configuration properties supported by this class.
104
     *
105
     * `Base` supports "on", "after", "plugins" and "bubbleTargets" properties,
106
     * which are not set up as attributes.
107
     *
108
     * This property is primarily required so that when
109
     * <a href="#property__allowAdHocAttrs">`_allowAdHocAttrs`</a> is enabled by
110
     * a class, non-attribute configurations don't get added as ad-hoc attributes.
111
     *
112
     * @property _NON_ATTRS_CFG
113
     * @type Array
114
     * @static
115
     * @private
116
     */
117
    Base._NON_ATTRS_CFG = BaseCore._NON_ATTRS_CFG.concat(BaseObservable._NON_ATTRS_CFG);
118
 
119
    /**
120
     * <p>
121
     * The string to be used to identify instances of
122
     * this class, for example in prefixing events.
123
     * </p>
124
     * <p>
125
     * Classes extending Base, should define their own
126
     * static NAME property, which should be camelCase by
127
     * convention (e.g. MyClass.NAME = "myClass";).
128
     * </p>
129
     * @property NAME
130
     * @type String
131
     * @static
132
     */
133
    Base.NAME = 'base';
134
 
135
    /**
136
     * The default set of attributes which will be available for instances of this class, and
137
     * their configuration. In addition to the configuration properties listed by
138
     * Attribute's <a href="Attribute.html#method_addAttr">addAttr</a> method, the attribute
139
     * can also be configured with a "cloneDefaultValue" property, which defines how the statically
140
     * defined value field should be protected ("shallow", "deep" and false are supported values).
141
     *
142
     * By default if the value is an object literal or an array it will be "shallow" cloned, to
143
     * protect the default value.
144
     *
145
     * @property ATTRS
146
     * @type Object
147
     * @static
148
     */
149
    Base.ATTRS = AttributeCore.protectAttrs(BaseCore.ATTRS);
150
 
151
    /**
152
    Provides a way to safely modify a `Y.Base` subclass' static `ATTRS` after
153
    the class has been defined or created.
154
 
155
    Base-based classes cache information about the class hierarchy in order to
156
    efficiently create instances. This cache includes includes the aggregated
157
    `ATTRS` configs. If the static `ATTRS` configs need to be modified after the
158
    class has been defined or create, then use this method which will make sure
159
    to clear any cached data before making any modifications.
160
 
161
    @method modifyAttrs
162
    @param {Function} [ctor] The constructor function whose `ATTRS` should be
163
        modified. If a `ctor` function is not specified, then `this` is assumed
164
        to be the constructor which hosts the `ATTRS`.
165
    @param {Object} configs The collection of `ATTRS` configs to mix with the
166
        existing attribute configurations.
167
    @static
168
    @since 3.10.0
169
    **/
170
    Base.modifyAttrs = BaseCore.modifyAttrs;
171
 
172
    Y.mix(Base, BaseCore, false, null, 1);
173
    Y.mix(Base, AttributeExtras, false, null, 1);
174
 
175
    // Needs to be `true`, to overwrite methods from `BaseCore`.
176
    Y.mix(Base, BaseObservable, true, null, 1);
177
 
178
    // Fix constructor
179
    Base.prototype.constructor = Base;
180
 
181
    Y.Base = Base;
182
 
183
 
184
}, '3.18.1', {"requires": ["attribute-base", "base-core", "base-observable"]});