~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/event-custom-complex/event-custom-complex-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.4.1 (build 4118)
 
3
Copyright 2011 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('event-custom-complex', function(Y) {
 
8
 
 
9
 
 
10
/**
 
11
 * Adds event facades, preventable default behavior, and bubbling.
 
12
 * events.
 
13
 * @module event-custom
 
14
 * @submodule event-custom-complex
 
15
 */
 
16
 
 
17
var FACADE,
 
18
    FACADE_KEYS,
 
19
    EMPTY = {},
 
20
    CEProto = Y.CustomEvent.prototype,
 
21
    ETProto = Y.EventTarget.prototype;
 
22
 
 
23
/**
 
24
 * Wraps and protects a custom event for use when emitFacade is set to true.
 
25
 * Requires the event-custom-complex module
 
26
 * @class EventFacade
 
27
 * @param e {Event} the custom event
 
28
 * @param currentTarget {HTMLElement} the element the listener was attached to
 
29
 */
 
30
 
 
31
Y.EventFacade = function(e, currentTarget) {
 
32
 
 
33
    e = e || EMPTY;
 
34
 
 
35
    this._event = e;
 
36
 
 
37
    /**
 
38
     * The arguments passed to fire
 
39
     * @property details
 
40
     * @type Array
 
41
     */
 
42
    this.details = e.details;
 
43
 
 
44
    /**
 
45
     * The event type, this can be overridden by the fire() payload
 
46
     * @property type
 
47
     * @type string
 
48
     */
 
49
    this.type = e.type;
 
50
 
 
51
    /**
 
52
     * The real event type
 
53
     * @property _type
 
54
     * @type string
 
55
     * @private
 
56
     */
 
57
    this._type = e.type;
 
58
 
 
59
    //////////////////////////////////////////////////////
 
60
 
 
61
    /**
 
62
     * Node reference for the targeted eventtarget
 
63
     * @property target
 
64
     * @type Node
 
65
     */
 
66
    this.target = e.target;
 
67
 
 
68
    /**
 
69
     * Node reference for the element that the listener was attached to.
 
70
     * @property currentTarget
 
71
     * @type Node
 
72
     */
 
73
    this.currentTarget = currentTarget;
 
74
 
 
75
    /**
 
76
     * Node reference to the relatedTarget
 
77
     * @property relatedTarget
 
78
     * @type Node
 
79
     */
 
80
    this.relatedTarget = e.relatedTarget;
 
81
 
 
82
};
 
83
 
 
84
Y.extend(Y.EventFacade, Object, {
 
85
 
 
86
    /**
 
87
     * Stops the propagation to the next bubble target
 
88
     * @method stopPropagation
 
89
     */
 
90
    stopPropagation: function() {
 
91
        this._event.stopPropagation();
 
92
        this.stopped = 1;
 
93
    },
 
94
 
 
95
    /**
 
96
     * Stops the propagation to the next bubble target and
 
97
     * prevents any additional listeners from being exectued
 
98
     * on the current target.
 
99
     * @method stopImmediatePropagation
 
100
     */
 
101
    stopImmediatePropagation: function() {
 
102
        this._event.stopImmediatePropagation();
 
103
        this.stopped = 2;
 
104
    },
 
105
 
 
106
    /**
 
107
     * Prevents the event's default behavior
 
108
     * @method preventDefault
 
109
     */
 
110
    preventDefault: function() {
 
111
        this._event.preventDefault();
 
112
        this.prevented = 1;
 
113
    },
 
114
 
 
115
    /**
 
116
     * Stops the event propagation and prevents the default
 
117
     * event behavior.
 
118
     * @method halt
 
119
     * @param immediate {boolean} if true additional listeners
 
120
     * on the current target will not be executed
 
121
     */
 
122
    halt: function(immediate) {
 
123
        this._event.halt(immediate);
 
124
        this.prevented = 1;
 
125
        this.stopped = (immediate) ? 2 : 1;
 
126
    }
 
127
 
 
128
});
 
129
 
 
130
CEProto.fireComplex = function(args) {
 
131
 
 
132
    var es, ef, q, queue, ce, ret, events, subs, postponed,
 
133
        self = this, host = self.host || self, next, oldbubble;
 
134
 
 
135
    if (self.stack) {
 
136
        // queue this event if the current item in the queue bubbles
 
137
        if (self.queuable && self.type != self.stack.next.type) {
 
138
            self.log('queue ' + self.type);
 
139
            self.stack.queue.push([self, args]);
 
140
            return true;
 
141
        }
 
142
    }
 
143
 
 
144
    es = self.stack || {
 
145
       // id of the first event in the stack
 
146
       id: self.id,
 
147
       next: self,
 
148
       silent: self.silent,
 
149
       stopped: 0,
 
150
       prevented: 0,
 
151
       bubbling: null,
 
152
       type: self.type,
 
153
       // defaultFnQueue: new Y.Queue(),
 
154
       afterQueue: new Y.Queue(),
 
155
       defaultTargetOnly: self.defaultTargetOnly,
 
156
       queue: []
 
157
    };
 
158
 
 
159
    subs = self.getSubs();
 
160
 
 
161
    self.stopped = (self.type !== es.type) ? 0 : es.stopped;
 
162
    self.prevented = (self.type !== es.type) ? 0 : es.prevented;
 
163
 
 
164
    self.target = self.target || host;
 
165
 
 
166
    events = new Y.EventTarget({
 
167
        fireOnce: true,
 
168
        context: host
 
169
    });
 
170
 
 
171
    self.events = events;
 
172
 
 
173
    if (self.stoppedFn) {
 
174
        events.on('stopped', self.stoppedFn);
 
175
    }
 
176
 
 
177
    self.currentTarget = host;
 
178
 
 
179
    self.details = args.slice(); // original arguments in the details
 
180
 
 
181
    // self.log("Firing " + self  + ", " + "args: " + args);
 
182
    self.log("Firing " + self.type);
 
183
 
 
184
    self._facade = null; // kill facade to eliminate stale properties
 
185
 
 
186
    ef = self._getFacade(args);
 
187
 
 
188
    if (Y.Lang.isObject(args[0])) {
 
189
        args[0] = ef;
 
190
    } else {
 
191
        args.unshift(ef);
 
192
    }
 
193
 
 
194
    // if (subCount) {
 
195
    if (subs[0]) {
 
196
        // self._procSubs(Y.merge(self.subscribers), args, ef);
 
197
        self._procSubs(subs[0], args, ef);
 
198
    }
 
199
 
 
200
    // bubble if this is hosted in an event target and propagation has not been stopped
 
201
    if (self.bubbles && host.bubble && !self.stopped) {
 
202
 
 
203
        oldbubble = es.bubbling;
 
204
 
 
205
        // self.bubbling = true;
 
206
        es.bubbling = self.type;
 
207
 
 
208
        // if (host !== ef.target || es.type != self.type) {
 
209
        if (es.type != self.type) {
 
210
            es.stopped = 0;
 
211
            es.prevented = 0;
 
212
        }
 
213
 
 
214
        ret = host.bubble(self, args, null, es);
 
215
 
 
216
        self.stopped = Math.max(self.stopped, es.stopped);
 
217
        self.prevented = Math.max(self.prevented, es.prevented);
 
218
 
 
219
        // self.bubbling = false;
 
220
        es.bubbling = oldbubble;
 
221
 
 
222
    }
 
223
 
 
224
    if (self.prevented) {
 
225
        if (self.preventedFn) {
 
226
            self.preventedFn.apply(host, args);
 
227
        }
 
228
    } else if (self.defaultFn &&
 
229
              ((!self.defaultTargetOnly && !es.defaultTargetOnly) ||
 
230
                host === ef.target)) {
 
231
        self.defaultFn.apply(host, args);
 
232
    }
 
233
 
 
234
    // broadcast listeners are fired as discreet events on the
 
235
    // YUI instance and potentially the YUI global.
 
236
    self._broadcast(args);
 
237
 
 
238
    // Queue the after
 
239
    if (subs[1] && !self.prevented && self.stopped < 2) {
 
240
        if (es.id === self.id || self.type != host._yuievt.bubbling) {
 
241
            self._procSubs(subs[1], args, ef);
 
242
            while ((next = es.afterQueue.last())) {
 
243
                next();
 
244
            }
 
245
        } else {
 
246
            postponed = subs[1];
 
247
            if (es.execDefaultCnt) {
 
248
                postponed = Y.merge(postponed);
 
249
                Y.each(postponed, function(s) {
 
250
                    s.postponed = true;
 
251
                });
 
252
            }
 
253
 
 
254
            es.afterQueue.add(function() {
 
255
                self._procSubs(postponed, args, ef);
 
256
            });
 
257
        }
 
258
    }
 
259
 
 
260
    self.target = null;
 
261
 
 
262
    if (es.id === self.id) {
 
263
        queue = es.queue;
 
264
 
 
265
        while (queue.length) {
 
266
            q = queue.pop();
 
267
            ce = q[0];
 
268
            // set up stack to allow the next item to be processed
 
269
            es.next = ce;
 
270
            ce.fire.apply(ce, q[1]);
 
271
        }
 
272
 
 
273
        self.stack = null;
 
274
    }
 
275
 
 
276
    ret = !(self.stopped);
 
277
 
 
278
    if (self.type != host._yuievt.bubbling) {
 
279
        es.stopped = 0;
 
280
        es.prevented = 0;
 
281
        self.stopped = 0;
 
282
        self.prevented = 0;
 
283
    }
 
284
 
 
285
    return ret;
 
286
};
 
287
 
 
288
CEProto._getFacade = function() {
 
289
 
 
290
    var ef = this._facade, o, o2,
 
291
    args = this.details;
 
292
 
 
293
    if (!ef) {
 
294
        ef = new Y.EventFacade(this, this.currentTarget);
 
295
    }
 
296
 
 
297
    // if the first argument is an object literal, apply the
 
298
    // properties to the event facade
 
299
    o = args && args[0];
 
300
 
 
301
    if (Y.Lang.isObject(o, true)) {
 
302
 
 
303
        o2 = {};
 
304
 
 
305
        // protect the event facade properties
 
306
        Y.mix(o2, ef, true, FACADE_KEYS);
 
307
 
 
308
        // mix the data
 
309
        Y.mix(ef, o, true);
 
310
 
 
311
        // restore ef
 
312
        Y.mix(ef, o2, true, FACADE_KEYS);
 
313
 
 
314
        // Allow the event type to be faked
 
315
        // http://yuilibrary.com/projects/yui3/ticket/2528376
 
316
        ef.type = o.type || ef.type;
 
317
    }
 
318
 
 
319
    // update the details field with the arguments
 
320
    // ef.type = this.type;
 
321
    ef.details = this.details;
 
322
 
 
323
    // use the original target when the event bubbled to this target
 
324
    ef.target = this.originalTarget || this.target;
 
325
 
 
326
    ef.currentTarget = this.currentTarget;
 
327
    ef.stopped = 0;
 
328
    ef.prevented = 0;
 
329
 
 
330
    this._facade = ef;
 
331
 
 
332
    return this._facade;
 
333
};
 
334
 
 
335
/**
 
336
 * Stop propagation to bubble targets
 
337
 * @for CustomEvent
 
338
 * @method stopPropagation
 
339
 */
 
340
CEProto.stopPropagation = function() {
 
341
    this.stopped = 1;
 
342
    if (this.stack) {
 
343
        this.stack.stopped = 1;
 
344
    }
 
345
    this.events.fire('stopped', this);
 
346
};
 
347
 
 
348
/**
 
349
 * Stops propagation to bubble targets, and prevents any remaining
 
350
 * subscribers on the current target from executing.
 
351
 * @method stopImmediatePropagation
 
352
 */
 
353
CEProto.stopImmediatePropagation = function() {
 
354
    this.stopped = 2;
 
355
    if (this.stack) {
 
356
        this.stack.stopped = 2;
 
357
    }
 
358
    this.events.fire('stopped', this);
 
359
};
 
360
 
 
361
/**
 
362
 * Prevents the execution of this event's defaultFn
 
363
 * @method preventDefault
 
364
 */
 
365
CEProto.preventDefault = function() {
 
366
    if (this.preventable) {
 
367
        this.prevented = 1;
 
368
        if (this.stack) {
 
369
            this.stack.prevented = 1;
 
370
        }
 
371
    }
 
372
};
 
373
 
 
374
/**
 
375
 * Stops the event propagation and prevents the default
 
376
 * event behavior.
 
377
 * @method halt
 
378
 * @param immediate {boolean} if true additional listeners
 
379
 * on the current target will not be executed
 
380
 */
 
381
CEProto.halt = function(immediate) {
 
382
    if (immediate) {
 
383
        this.stopImmediatePropagation();
 
384
    } else {
 
385
        this.stopPropagation();
 
386
    }
 
387
    this.preventDefault();
 
388
};
 
389
 
 
390
/**
 
391
 * Registers another EventTarget as a bubble target.  Bubble order
 
392
 * is determined by the order registered.  Multiple targets can
 
393
 * be specified.
 
394
 *
 
395
 * Events can only bubble if emitFacade is true.
 
396
 *
 
397
 * Included in the event-custom-complex submodule.
 
398
 *
 
399
 * @method addTarget
 
400
 * @param o {EventTarget} the target to add
 
401
 * @for EventTarget
 
402
 */
 
403
ETProto.addTarget = function(o) {
 
404
    this._yuievt.targets[Y.stamp(o)] = o;
 
405
    this._yuievt.hasTargets = true;
 
406
};
 
407
 
 
408
/**
 
409
 * Returns an array of bubble targets for this object.
 
410
 * @method getTargets
 
411
 * @return EventTarget[]
 
412
 */
 
413
ETProto.getTargets = function() {
 
414
    return Y.Object.values(this._yuievt.targets);
 
415
};
 
416
 
 
417
/**
 
418
 * Removes a bubble target
 
419
 * @method removeTarget
 
420
 * @param o {EventTarget} the target to remove
 
421
 * @for EventTarget
 
422
 */
 
423
ETProto.removeTarget = function(o) {
 
424
    delete this._yuievt.targets[Y.stamp(o)];
 
425
};
 
426
 
 
427
/**
 
428
 * Propagate an event.  Requires the event-custom-complex module.
 
429
 * @method bubble
 
430
 * @param evt {CustomEvent} the custom event to propagate
 
431
 * @return {boolean} the aggregated return value from Event.Custom.fire
 
432
 * @for EventTarget
 
433
 */
 
434
ETProto.bubble = function(evt, args, target, es) {
 
435
 
 
436
    var targs = this._yuievt.targets, ret = true,
 
437
        t, type = evt && evt.type, ce, i, bc, ce2,
 
438
        originalTarget = target || (evt && evt.target) || this,
 
439
        oldbubble;
 
440
 
 
441
    if (!evt || ((!evt.stopped) && targs)) {
 
442
 
 
443
        // Y.log('Bubbling ' + evt.type);
 
444
        for (i in targs) {
 
445
            if (targs.hasOwnProperty(i)) {
 
446
                t = targs[i];
 
447
                ce = t.getEvent(type, true);
 
448
                ce2 = t.getSibling(type, ce);
 
449
 
 
450
                if (ce2 && !ce) {
 
451
                    ce = t.publish(type);
 
452
                }
 
453
 
 
454
                oldbubble = t._yuievt.bubbling;
 
455
                t._yuievt.bubbling = type;
 
456
 
 
457
                // if this event was not published on the bubble target,
 
458
                // continue propagating the event.
 
459
                if (!ce) {
 
460
                    if (t._yuievt.hasTargets) {
 
461
                        t.bubble(evt, args, originalTarget, es);
 
462
                    }
 
463
                } else {
 
464
 
 
465
                    ce.sibling = ce2;
 
466
 
 
467
                    // set the original target to that the target payload on the
 
468
                    // facade is correct.
 
469
                    ce.target = originalTarget;
 
470
                    ce.originalTarget = originalTarget;
 
471
                    ce.currentTarget = t;
 
472
                    bc = ce.broadcast;
 
473
                    ce.broadcast = false;
 
474
 
 
475
                    // default publish may not have emitFacade true -- that
 
476
                    // shouldn't be what the implementer meant to do
 
477
                    ce.emitFacade = true;
 
478
 
 
479
                    ce.stack = es;
 
480
 
 
481
                    ret = ret && ce.fire.apply(ce, args || evt.details || []);
 
482
                    ce.broadcast = bc;
 
483
                    ce.originalTarget = null;
 
484
 
 
485
 
 
486
                    // stopPropagation() was called
 
487
                    if (ce.stopped) {
 
488
                        break;
 
489
                    }
 
490
                }
 
491
 
 
492
                t._yuievt.bubbling = oldbubble;
 
493
            }
 
494
        }
 
495
    }
 
496
 
 
497
    return ret;
 
498
};
 
499
 
 
500
FACADE = new Y.EventFacade();
 
501
FACADE_KEYS = Y.Object.keys(FACADE);
 
502
 
 
503
 
 
504
 
 
505
}, '3.4.1' ,{requires:['event-custom-base']});