2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('base-observable', function (Y, NAME) {
11
The `base-observable` submodule adds observability to Base's lifecycle and
12
attributes, and also make it an `EventTarget`.
15
@submodule base-observable
22
BUBBLETARGETS = "bubbleTargets",
23
_BUBBLETARGETS = "_bubbleTargets",
25
AttributeObservable = Y.AttributeObservable,
26
BaseCore = Y.BaseCore;
29
Provides an augmentable implementation of lifecycle and attribute events for
33
@extensionfor BaseCore
34
@uses AttributeObservable
38
function BaseObservable() {}
40
BaseObservable._ATTR_CFG = AttributeObservable._ATTR_CFG.concat();
41
BaseObservable._NON_ATTRS_CFG = ["on", "after", "bubbleTargets"];
43
BaseObservable.prototype = {
46
* Initializes Attribute
48
* @method _initAttribute
51
_initAttribute: function() {
52
BaseCore.prototype._initAttribute.apply(this, arguments);
53
AttributeObservable.call(this);
55
this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
56
this._yuievt.config.prefix = this._eventPrefix;
60
* Init lifecycle method, invoked during construction.
61
* Fires the init event prior to setting up attributes and
62
* invoking initializers for the class hierarchy.
66
* @param {Object} config Object with configuration property name/value pairs
67
* @return {Base} A reference to this object
69
init: function(config) {
73
* Lifecycle event for the init phase, fired prior to initialization.
74
* Invoking the preventDefault() method on the event object provided
75
* to subscribers will prevent initialization from occuring.
78
* Subscribers to the "after" momemt of this event, will be notified
79
* after initialization of the object is complete (and therefore
80
* cannot prevent initialization).
84
* @preventable _defInitFn
85
* @param {EventFacade} e Event object, with a cfg property which
86
* refers to the configuration object passed to the constructor.
89
// PERF: Using lower level _publish() for
90
// critical path performance
92
var type = this._getFullType(INIT),
93
e = this._publish(type);
97
e.defaultTargetOnly = true;
98
e.defaultFn = this._defInitFn;
100
this._preInitEventCfg(config);
102
this.fire(type, {cfg: config});
108
* Handles the special on, after and target properties which allow the user to
109
* easily configure on and after listeners as well as bubble targets during
110
* construction, prior to init.
113
* @method _preInitEventCfg
114
* @param {Object} config The user configuration object
116
_preInitEventCfg : function(config) {
122
this.after(config.after);
127
userTargets = (config && BUBBLETARGETS in config);
129
if (userTargets || _BUBBLETARGETS in this) {
130
target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
132
if (L.isArray(target)) {
133
for (i = 0, l = target.length; i < l; i++) {
134
this.addTarget(target[i]);
137
this.addTarget(target);
144
* Destroy lifecycle method. Fires the destroy
145
* event, prior to invoking destructors for the
149
* Subscribers to the destroy
150
* event can invoke preventDefault on the event object, to prevent destruction
154
* @return {Base} A reference to this object
157
destroy: function() {
161
* Lifecycle event for the destroy phase,
162
* fired prior to destruction. Invoking the preventDefault
163
* method on the event object provided to subscribers will
164
* prevent destruction from proceeding.
167
* Subscribers to the "after" moment of this event, will be notified
168
* after destruction is complete (and as a result cannot prevent
172
* @preventable _defDestroyFn
173
* @param {EventFacade} e Event object
175
this.publish(DESTROY, {
177
defaultTargetOnly:true,
178
defaultFn: this._defDestroyFn
187
* Default init event handler
190
* @param {EventFacade} e Event object, with a cfg property which
191
* refers to the configuration object passed to the constructor.
194
_defInitFn : function(e) {
195
this._baseInit(e.cfg);
199
* Default destroy event handler
201
* @method _defDestroyFn
202
* @param {EventFacade} e Event object
205
_defDestroyFn : function(e) {
206
this._baseDestroy(e.cfg);
210
Y.mix(BaseObservable, AttributeObservable, false, null, 1);
212
Y.BaseObservable = BaseObservable;
215
}, '3.10.3', {"requires": ["attribute-observable"]});