~michael.nelson/ubuntu-webcatalog/1267731-import-sca-apps-error

« back to all changes in this revision

Viewing changes to src/webcatalog/static/yui/3.10.3/build/base-observable/base-observable.js

  • Committer: Tarmac
  • Author(s): Stephen Stewart
  • Date: 2013-06-26 09:19:32 UTC
  • mfrom: (184.1.4 ubuntu-global-nav)
  • Revision ID: tarmac-20130626091932-8urtuli368k8p7ds
[r=beuno,jonas-drange] add ubuntu global nav to apps.ubuntu.com

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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/
 
6
*/
 
7
 
 
8
YUI.add('base-observable', function (Y, NAME) {
 
9
 
 
10
    /**
 
11
    The `base-observable` submodule adds observability to Base's lifecycle and
 
12
    attributes, and also make it an `EventTarget`.
 
13
 
 
14
    @module base
 
15
    @submodule base-observable
 
16
    **/
 
17
    var L = Y.Lang,
 
18
 
 
19
        DESTROY = "destroy",
 
20
        INIT = "init",
 
21
 
 
22
        BUBBLETARGETS = "bubbleTargets",
 
23
        _BUBBLETARGETS = "_bubbleTargets",
 
24
 
 
25
        AttributeObservable = Y.AttributeObservable,
 
26
        BaseCore            = Y.BaseCore;
 
27
 
 
28
    /**
 
29
    Provides an augmentable implementation of lifecycle and attribute events for
 
30
    `BaseCore`.
 
31
 
 
32
    @class BaseObservable
 
33
    @extensionfor BaseCore
 
34
    @uses AttributeObservable
 
35
    @uses EventTarget
 
36
    @since 3.8.0
 
37
    **/
 
38
    function BaseObservable() {}
 
39
 
 
40
    BaseObservable._ATTR_CFG      = AttributeObservable._ATTR_CFG.concat();
 
41
    BaseObservable._NON_ATTRS_CFG = ["on", "after", "bubbleTargets"];
 
42
 
 
43
    BaseObservable.prototype = {
 
44
 
 
45
        /**
 
46
         * Initializes Attribute
 
47
         *
 
48
         * @method _initAttribute
 
49
         * @private
 
50
         */
 
51
        _initAttribute: function() {
 
52
            BaseCore.prototype._initAttribute.apply(this, arguments);
 
53
            AttributeObservable.call(this);
 
54
 
 
55
            this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
 
56
            this._yuievt.config.prefix = this._eventPrefix;
 
57
        },
 
58
 
 
59
        /**
 
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.
 
63
         *
 
64
         * @method init
 
65
         * @chainable
 
66
         * @param {Object} config Object with configuration property name/value pairs
 
67
         * @return {Base} A reference to this object
 
68
         */
 
69
        init: function(config) {
 
70
 
 
71
            /**
 
72
             * <p>
 
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.
 
76
             * </p>
 
77
             * <p>
 
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).
 
81
             * </p>
 
82
             *
 
83
             * @event init
 
84
             * @preventable _defInitFn
 
85
             * @param {EventFacade} e Event object, with a cfg property which
 
86
             * refers to the configuration object passed to the constructor.
 
87
             */
 
88
 
 
89
            // PERF: Using lower level _publish() for
 
90
            // critical path performance
 
91
 
 
92
            var type = this._getFullType(INIT),
 
93
                e = this._publish(type);
 
94
 
 
95
            e.emitFacade = true;
 
96
            e.fireOnce = true;
 
97
            e.defaultTargetOnly = true;
 
98
            e.defaultFn = this._defInitFn;
 
99
 
 
100
            this._preInitEventCfg(config);
 
101
 
 
102
            this.fire(type, {cfg: config});
 
103
 
 
104
            return this;
 
105
        },
 
106
 
 
107
        /**
 
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.
 
111
         *
 
112
         * @private
 
113
         * @method _preInitEventCfg
 
114
         * @param {Object} config The user configuration object
 
115
         */
 
116
        _preInitEventCfg : function(config) {
 
117
            if (config) {
 
118
                if (config.on) {
 
119
                    this.on(config.on);
 
120
                }
 
121
                if (config.after) {
 
122
                    this.after(config.after);
 
123
                }
 
124
            }
 
125
 
 
126
            var i, l, target,
 
127
                userTargets = (config && BUBBLETARGETS in config);
 
128
 
 
129
            if (userTargets || _BUBBLETARGETS in this) {
 
130
                target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
 
131
 
 
132
                if (L.isArray(target)) {
 
133
                    for (i = 0, l = target.length; i < l; i++) {
 
134
                        this.addTarget(target[i]);
 
135
                    }
 
136
                } else if (target) {
 
137
                    this.addTarget(target);
 
138
                }
 
139
            }
 
140
        },
 
141
 
 
142
        /**
 
143
         * <p>
 
144
         * Destroy lifecycle method. Fires the destroy
 
145
         * event, prior to invoking destructors for the
 
146
         * class hierarchy.
 
147
         * </p>
 
148
         * <p>
 
149
         * Subscribers to the destroy
 
150
         * event can invoke preventDefault on the event object, to prevent destruction
 
151
         * from proceeding.
 
152
         * </p>
 
153
         * @method destroy
 
154
         * @return {Base} A reference to this object
 
155
         * @chainable
 
156
         */
 
157
        destroy: function() {
 
158
 
 
159
            /**
 
160
             * <p>
 
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.
 
165
             * </p>
 
166
             * <p>
 
167
             * Subscribers to the "after" moment of this event, will be notified
 
168
             * after destruction is complete (and as a result cannot prevent
 
169
             * destruction).
 
170
             * </p>
 
171
             * @event destroy
 
172
             * @preventable _defDestroyFn
 
173
             * @param {EventFacade} e Event object
 
174
             */
 
175
            this.publish(DESTROY, {
 
176
                fireOnce:true,
 
177
                defaultTargetOnly:true,
 
178
                defaultFn: this._defDestroyFn
 
179
            });
 
180
            this.fire(DESTROY);
 
181
 
 
182
            this.detachAll();
 
183
            return this;
 
184
        },
 
185
 
 
186
        /**
 
187
         * Default init event handler
 
188
         *
 
189
         * @method _defInitFn
 
190
         * @param {EventFacade} e Event object, with a cfg property which
 
191
         * refers to the configuration object passed to the constructor.
 
192
         * @protected
 
193
         */
 
194
        _defInitFn : function(e) {
 
195
            this._baseInit(e.cfg);
 
196
        },
 
197
 
 
198
        /**
 
199
         * Default destroy event handler
 
200
         *
 
201
         * @method _defDestroyFn
 
202
         * @param {EventFacade} e Event object
 
203
         * @protected
 
204
         */
 
205
        _defDestroyFn : function(e) {
 
206
            this._baseDestroy(e.cfg);
 
207
        }
 
208
    };
 
209
 
 
210
    Y.mix(BaseObservable, AttributeObservable, false, null, 1);
 
211
 
 
212
    Y.BaseObservable = BaseObservable;
 
213
 
 
214
 
 
215
}, '3.10.3', {"requires": ["attribute-observable"]});