120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1 |
/*
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2 |
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
3 |
Code licensed under the BSD License:
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
4 |
http://developer.yahoo.com/yui/license.html
|
166.19.1
by Paul Hummer
New YUI 3.2 |
5 |
version: 3.2.0
|
6 |
build: 2676
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
7 |
*/
|
8 |
YUI.add('event-custom-base', function(Y) { |
|
9 |
||
10 |
/**
|
|
11 |
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
|
|
12 |
* events.
|
|
13 |
* @module event-custom
|
|
14 |
*/
|
|
15 |
||
16 |
Y.Env.evt = { |
|
17 |
handles: {}, |
|
18 |
plugins: {} |
|
19 |
};
|
|
20 |
||
21 |
||
22 |
/**
|
|
23 |
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
|
|
24 |
* events.
|
|
25 |
* @module event-custom
|
|
26 |
* @submodule event-custom-base
|
|
27 |
*/
|
|
28 |
(function() { |
|
29 |
||
30 |
/**
|
|
31 |
* Allows for the insertion of methods that are executed before or after
|
|
32 |
* a specified method
|
|
33 |
* @class Do
|
|
34 |
* @static
|
|
35 |
*/
|
|
36 |
||
37 |
var BEFORE = 0, |
|
38 |
AFTER = 1; |
|
39 |
||
40 |
Y.Do = { |
|
41 |
||
42 |
/**
|
|
43 |
* Cache of objects touched by the utility
|
|
44 |
* @property objs
|
|
45 |
* @static
|
|
46 |
*/
|
|
47 |
objs: {}, |
|
48 |
||
49 |
/**
|
|
50 |
* Execute the supplied method before the specified function
|
|
51 |
* @method before
|
|
52 |
* @param fn {Function} the function to execute
|
|
53 |
* @param obj the object hosting the method to displace
|
|
54 |
* @param sFn {string} the name of the method to displace
|
|
55 |
* @param c The execution context for fn
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
56 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
57 |
* when the event fires.
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
58 |
* @return {string} handle for the subscription
|
59 |
* @static
|
|
60 |
*/
|
|
61 |
before: function(fn, obj, sFn, c) { |
|
62 |
// Y.log('Do before: ' + sFn, 'info', 'event');
|
|
63 |
var f = fn, a; |
|
64 |
if (c) { |
|
65 |
a = [fn, c].concat(Y.Array(arguments, 4, true)); |
|
66 |
f = Y.rbind.apply(Y, a); |
|
67 |
}
|
|
68 |
||
69 |
return this._inject(BEFORE, f, obj, sFn); |
|
70 |
},
|
|
71 |
||
72 |
/**
|
|
73 |
* Execute the supplied method after the specified function
|
|
74 |
* @method after
|
|
75 |
* @param fn {Function} the function to execute
|
|
76 |
* @param obj the object hosting the method to displace
|
|
77 |
* @param sFn {string} the name of the method to displace
|
|
78 |
* @param c The execution context for fn
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
79 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
80 |
* @return {string} handle for the subscription
|
81 |
* @static
|
|
82 |
*/
|
|
83 |
after: function(fn, obj, sFn, c) { |
|
84 |
var f = fn, a; |
|
85 |
if (c) { |
|
86 |
a = [fn, c].concat(Y.Array(arguments, 4, true)); |
|
87 |
f = Y.rbind.apply(Y, a); |
|
88 |
}
|
|
89 |
||
90 |
return this._inject(AFTER, f, obj, sFn); |
|
91 |
},
|
|
92 |
||
93 |
/**
|
|
94 |
* Execute the supplied method after the specified function
|
|
95 |
* @method _inject
|
|
96 |
* @param when {string} before or after
|
|
97 |
* @param fn {Function} the function to execute
|
|
98 |
* @param obj the object hosting the method to displace
|
|
99 |
* @param sFn {string} the name of the method to displace
|
|
100 |
* @param c The execution context for fn
|
|
101 |
* @return {string} handle for the subscription
|
|
102 |
* @private
|
|
103 |
* @static
|
|
104 |
*/
|
|
105 |
_inject: function(when, fn, obj, sFn) { |
|
106 |
||
107 |
// object id
|
|
108 |
var id = Y.stamp(obj), o, sid; |
|
109 |
||
110 |
if (! this.objs[id]) { |
|
111 |
// create a map entry for the obj if it doesn't exist
|
|
112 |
this.objs[id] = {}; |
|
113 |
}
|
|
114 |
||
115 |
o = this.objs[id]; |
|
116 |
||
117 |
if (! o[sFn]) { |
|
118 |
// create a map entry for the method if it doesn't exist
|
|
119 |
o[sFn] = new Y.Do.Method(obj, sFn); |
|
120 |
||
121 |
// re-route the method to our wrapper
|
|
122 |
obj[sFn] = |
|
123 |
function() { |
|
124 |
return o[sFn].exec.apply(o[sFn], arguments); |
|
125 |
};
|
|
126 |
}
|
|
127 |
||
128 |
// subscriber id
|
|
129 |
sid = id + Y.stamp(fn) + sFn; |
|
130 |
||
131 |
// register the callback
|
|
132 |
o[sFn].register(sid, fn, when); |
|
133 |
||
134 |
return new Y.EventHandle(o[sFn], sid); |
|
135 |
||
136 |
},
|
|
137 |
||
138 |
/**
|
|
139 |
* Detach a before or after subscription
|
|
140 |
* @method detach
|
|
141 |
* @param handle {string} the subscription handle
|
|
142 |
*/
|
|
143 |
detach: function(handle) { |
|
144 |
||
145 |
if (handle.detach) { |
|
146 |
handle.detach(); |
|
147 |
}
|
|
148 |
||
149 |
},
|
|
150 |
||
151 |
_unload: function(e, me) { |
|
152 |
||
153 |
}
|
|
154 |
};
|
|
155 |
||
156 |
//////////////////////////////////////////////////////////////////////////
|
|
157 |
||
158 |
/**
|
|
159 |
* Wrapper for a displaced method with aop enabled
|
|
160 |
* @class Do.Method
|
|
161 |
* @constructor
|
|
162 |
* @param obj The object to operate on
|
|
163 |
* @param sFn The name of the method to displace
|
|
164 |
*/
|
|
165 |
Y.Do.Method = function(obj, sFn) { |
|
166 |
this.obj = obj; |
|
167 |
this.methodName = sFn; |
|
168 |
this.method = obj[sFn]; |
|
169 |
this.before = {}; |
|
170 |
this.after = {}; |
|
171 |
};
|
|
172 |
||
173 |
/**
|
|
174 |
* Register a aop subscriber
|
|
175 |
* @method register
|
|
176 |
* @param sid {string} the subscriber id
|
|
177 |
* @param fn {Function} the function to execute
|
|
178 |
* @param when {string} when to execute the function
|
|
179 |
*/
|
|
180 |
Y.Do.Method.prototype.register = function (sid, fn, when) { |
|
181 |
if (when) { |
|
182 |
this.after[sid] = fn; |
|
183 |
} else { |
|
184 |
this.before[sid] = fn; |
|
185 |
}
|
|
186 |
};
|
|
187 |
||
188 |
/**
|
|
189 |
* Unregister a aop subscriber
|
|
190 |
* @method delete
|
|
191 |
* @param sid {string} the subscriber id
|
|
192 |
* @param fn {Function} the function to execute
|
|
193 |
* @param when {string} when to execute the function
|
|
194 |
*/
|
|
195 |
Y.Do.Method.prototype._delete = function (sid) { |
|
196 |
// Y.log('Y.Do._delete: ' + sid, 'info', 'Event');
|
|
197 |
delete this.before[sid]; |
|
198 |
delete this.after[sid]; |
|
199 |
};
|
|
200 |
||
201 |
/**
|
|
202 |
* Execute the wrapped method
|
|
203 |
* @method exec
|
|
204 |
*/
|
|
205 |
Y.Do.Method.prototype.exec = function () { |
|
206 |
||
207 |
var args = Y.Array(arguments, 0, true), |
|
208 |
i, ret, newRet, |
|
209 |
bf = this.before, |
|
210 |
af = this.after, |
|
211 |
prevented = false; |
|
212 |
||
213 |
// execute before
|
|
214 |
for (i in bf) { |
|
215 |
if (bf.hasOwnProperty(i)) { |
|
216 |
ret = bf[i].apply(this.obj, args); |
|
217 |
if (ret) { |
|
218 |
switch (ret.constructor) { |
|
219 |
case Y.Do.Halt: |
|
220 |
return ret.retVal; |
|
221 |
case Y.Do.AlterArgs: |
|
222 |
args = ret.newArgs; |
|
223 |
break; |
|
224 |
case Y.Do.Prevent: |
|
225 |
prevented = true; |
|
226 |
break; |
|
227 |
default: |
|
228 |
}
|
|
229 |
}
|
|
230 |
}
|
|
231 |
}
|
|
232 |
||
233 |
// execute method
|
|
234 |
if (!prevented) { |
|
235 |
ret = this.method.apply(this.obj, args); |
|
236 |
}
|
|
237 |
||
238 |
// execute after methods.
|
|
239 |
for (i in af) { |
|
240 |
if (af.hasOwnProperty(i)) { |
|
241 |
newRet = af[i].apply(this.obj, args); |
|
242 |
// Stop processing if a Halt object is returned
|
|
243 |
if (newRet && newRet.constructor == Y.Do.Halt) { |
|
244 |
return newRet.retVal; |
|
245 |
// Check for a new return value
|
|
246 |
} else if (newRet && newRet.constructor == Y.Do.AlterReturn) { |
|
247 |
ret = newRet.newRetVal; |
|
248 |
}
|
|
249 |
}
|
|
250 |
}
|
|
251 |
||
252 |
return ret; |
|
253 |
};
|
|
254 |
||
255 |
//////////////////////////////////////////////////////////////////////////
|
|
256 |
||
257 |
||
258 |
/**
|
|
259 |
* Return an AlterArgs object when you want to change the arguments that
|
|
260 |
* were passed into the function. An example would be a service that scrubs
|
|
261 |
* out illegal characters prior to executing the core business logic.
|
|
262 |
* @class Do.AlterArgs
|
|
263 |
*/
|
|
264 |
Y.Do.AlterArgs = function(msg, newArgs) { |
|
265 |
this.msg = msg; |
|
266 |
this.newArgs = newArgs; |
|
267 |
};
|
|
268 |
||
269 |
/**
|
|
270 |
* Return an AlterReturn object when you want to change the result returned
|
|
271 |
* from the core method to the caller
|
|
272 |
* @class Do.AlterReturn
|
|
273 |
*/
|
|
274 |
Y.Do.AlterReturn = function(msg, newRetVal) { |
|
275 |
this.msg = msg; |
|
276 |
this.newRetVal = newRetVal; |
|
277 |
};
|
|
278 |
||
279 |
/**
|
|
280 |
* Return a Halt object when you want to terminate the execution
|
|
281 |
* of all subsequent subscribers as well as the wrapped method
|
|
282 |
* if it has not exectued yet.
|
|
283 |
* @class Do.Halt
|
|
284 |
*/
|
|
285 |
Y.Do.Halt = function(msg, retVal) { |
|
286 |
this.msg = msg; |
|
287 |
this.retVal = retVal; |
|
288 |
};
|
|
289 |
||
290 |
/**
|
|
291 |
* Return a Prevent object when you want to prevent the wrapped function
|
|
292 |
* from executing, but want the remaining listeners to execute
|
|
293 |
* @class Do.Prevent
|
|
294 |
*/
|
|
295 |
Y.Do.Prevent = function(msg) { |
|
296 |
this.msg = msg; |
|
297 |
};
|
|
298 |
||
299 |
/**
|
|
300 |
* Return an Error object when you want to terminate the execution
|
|
301 |
* of all subsequent method calls.
|
|
302 |
* @class Do.Error
|
|
303 |
* @deprecated use Y.Do.Halt or Y.Do.Prevent
|
|
304 |
*/
|
|
305 |
Y.Do.Error = Y.Do.Halt; |
|
306 |
||
307 |
//////////////////////////////////////////////////////////////////////////
|
|
308 |
||
309 |
// Y["Event"] && Y.Event.addListener(window, "unload", Y.Do._unload, Y.Do);
|
|
310 |
||
311 |
})();
|
|
312 |
||
313 |
/**
|
|
314 |
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
|
|
315 |
* events.
|
|
316 |
* @module event-custom
|
|
317 |
* @submodule event-custom-base
|
|
318 |
*/
|
|
319 |
||
320 |
/**
|
|
321 |
* Return value from all subscribe operations
|
|
322 |
* @class EventHandle
|
|
323 |
* @constructor
|
|
324 |
* @param evt {CustomEvent} the custom event
|
|
325 |
* @param sub {Subscriber} the subscriber
|
|
326 |
*/
|
|
327 |
||
328 |
// var onsubscribeType = "_event:onsub",
|
|
329 |
var AFTER = 'after', |
|
330 |
CONFIGS = [ |
|
331 |
'broadcast', |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
332 |
'monitored', |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
333 |
'bubbles', |
334 |
'context', |
|
335 |
'contextFn', |
|
336 |
'currentTarget', |
|
337 |
'defaultFn', |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
338 |
'defaultTargetOnly', |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
339 |
'details', |
340 |
'emitFacade', |
|
341 |
'fireOnce', |
|
166.8.15
by Sidnei da Silva
- Update to yui-3.1.1 |
342 |
'async', |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
343 |
'host', |
344 |
'preventable', |
|
345 |
'preventedFn', |
|
346 |
'queuable', |
|
347 |
'silent', |
|
348 |
'stoppedFn', |
|
349 |
'target', |
|
350 |
'type'
|
|
351 |
],
|
|
352 |
||
353 |
YUI3_SIGNATURE = 9, |
|
354 |
YUI_LOG = 'yui:log'; |
|
355 |
||
356 |
Y.EventHandle = function(evt, sub) { |
|
357 |
||
358 |
/**
|
|
359 |
* The custom event
|
|
360 |
* @type CustomEvent
|
|
361 |
*/
|
|
362 |
this.evt = evt; |
|
363 |
||
364 |
/**
|
|
365 |
* The subscriber object
|
|
366 |
* @type Subscriber
|
|
367 |
*/
|
|
368 |
this.sub = sub; |
|
369 |
};
|
|
370 |
||
371 |
Y.EventHandle.prototype = { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
372 |
each: function(f) { |
373 |
f(this); |
|
374 |
if (Y.Lang.isArray(this.evt)) { |
|
375 |
Y.Array.each(this.evt, function(h) { |
|
376 |
h.each(f); |
|
377 |
});
|
|
378 |
}
|
|
379 |
},
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
380 |
|
381 |
/**
|
|
382 |
* Detaches this subscriber
|
|
383 |
* @method detach
|
|
384 |
*/
|
|
385 |
detach: function() { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
386 |
var evt = this.evt, detached = 0, i; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
387 |
if (evt) { |
388 |
// Y.log('EventHandle.detach: ' + this.sub, 'info', 'Event');
|
|
389 |
if (Y.Lang.isArray(evt)) { |
|
390 |
for (i=0; i<evt.length; i++) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
391 |
detached += evt[i].detach(); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
392 |
}
|
393 |
} else { |
|
394 |
evt._delete(this.sub); |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
395 |
detached = 1; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
396 |
}
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
397 |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
398 |
}
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
399 |
|
400 |
return detached; |
|
401 |
},
|
|
402 |
||
403 |
/**
|
|
404 |
* Monitor the event state for the subscribed event. The first parameter
|
|
405 |
* is what should be monitored, the rest are the normal parameters when
|
|
406 |
* subscribing to an event.
|
|
407 |
* @method monitor
|
|
408 |
* @param what {string} what to monitor ('attach', 'detach', 'publish')
|
|
409 |
* @return {EventHandle} return value from the monitor event subscription
|
|
410 |
*/
|
|
411 |
monitor: function(what) { |
|
412 |
return this.evt.monitor.apply(this.evt, arguments); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
413 |
}
|
414 |
};
|
|
415 |
||
416 |
/**
|
|
417 |
* The CustomEvent class lets you define events for your application
|
|
418 |
* that can be subscribed to by one or more independent component.
|
|
419 |
*
|
|
420 |
* @param {String} type The type of event, which is passed to the callback
|
|
421 |
* when the event fires
|
|
422 |
* @param o configuration object
|
|
423 |
* @class CustomEvent
|
|
424 |
* @constructor
|
|
425 |
*/
|
|
426 |
Y.CustomEvent = function(type, o) { |
|
427 |
||
428 |
// if (arguments.length > 2) {
|
|
429 |
// this.log('CustomEvent context and silent are now in the config', 'warn', 'Event');
|
|
430 |
// }
|
|
431 |
||
432 |
o = o || {}; |
|
433 |
||
434 |
this.id = Y.stamp(this); |
|
435 |
||
436 |
/**
|
|
437 |
* The type of event, returned to subscribers when the event fires
|
|
438 |
* @property type
|
|
439 |
* @type string
|
|
440 |
*/
|
|
441 |
this.type = type; |
|
442 |
||
443 |
/**
|
|
444 |
* The context the the event will fire from by default. Defaults to the YUI
|
|
445 |
* instance.
|
|
446 |
* @property context
|
|
447 |
* @type object
|
|
448 |
*/
|
|
449 |
this.context = Y; |
|
450 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
451 |
/**
|
452 |
* Monitor when an event is attached or detached.
|
|
453 |
*
|
|
454 |
* @property monitored
|
|
455 |
* @type boolean
|
|
456 |
*/
|
|
457 |
// this.monitored = false;
|
|
458 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
459 |
this.logSystem = (type == YUI_LOG); |
460 |
||
461 |
/**
|
|
462 |
* If 0, this event does not broadcast. If 1, the YUI instance is notified
|
|
463 |
* every time this event fires. If 2, the YUI instance and the YUI global
|
|
464 |
* (if event is enabled on the global) are notified every time this event
|
|
465 |
* fires.
|
|
466 |
* @property broadcast
|
|
467 |
* @type int
|
|
468 |
*/
|
|
469 |
// this.broadcast = 0;
|
|
470 |
||
471 |
/**
|
|
472 |
* By default all custom events are logged in the debug build, set silent
|
|
473 |
* to true to disable debug outpu for this event.
|
|
474 |
* @property silent
|
|
475 |
* @type boolean
|
|
476 |
*/
|
|
477 |
this.silent = this.logSystem; |
|
478 |
||
479 |
/**
|
|
480 |
* Specifies whether this event should be queued when the host is actively
|
|
481 |
* processing an event. This will effect exectution order of the callbacks
|
|
482 |
* for the various events.
|
|
483 |
* @property queuable
|
|
484 |
* @type boolean
|
|
485 |
* @default false
|
|
486 |
*/
|
|
487 |
// this.queuable = false;
|
|
488 |
||
489 |
/**
|
|
490 |
* The subscribers to this event
|
|
491 |
* @property subscribers
|
|
492 |
* @type Subscriber{}
|
|
493 |
*/
|
|
494 |
this.subscribers = {}; |
|
495 |
||
496 |
/**
|
|
497 |
* 'After' subscribers
|
|
498 |
* @property afters
|
|
499 |
* @type Subscriber{}
|
|
500 |
*/
|
|
501 |
this.afters = {}; |
|
502 |
||
503 |
/**
|
|
504 |
* This event has fired if true
|
|
505 |
*
|
|
506 |
* @property fired
|
|
507 |
* @type boolean
|
|
508 |
* @default false;
|
|
509 |
*/
|
|
510 |
// this.fired = false;
|
|
511 |
||
512 |
/**
|
|
513 |
* An array containing the arguments the custom event
|
|
514 |
* was last fired with.
|
|
515 |
* @property firedWith
|
|
516 |
* @type Array
|
|
517 |
*/
|
|
518 |
// this.firedWith;
|
|
519 |
||
520 |
/**
|
|
521 |
* This event should only fire one time if true, and if
|
|
522 |
* it has fired, any new subscribers should be notified
|
|
523 |
* immediately.
|
|
524 |
*
|
|
525 |
* @property fireOnce
|
|
526 |
* @type boolean
|
|
527 |
* @default false;
|
|
528 |
*/
|
|
529 |
// this.fireOnce = false;
|
|
166.8.15
by Sidnei da Silva
- Update to yui-3.1.1 |
530 |
|
531 |
/**
|
|
532 |
* fireOnce listeners will fire syncronously unless async
|
|
533 |
* is set to true
|
|
534 |
* @property async
|
|
535 |
* @type boolean
|
|
536 |
* @default false
|
|
537 |
*/
|
|
538 |
//this.async = false;
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
539 |
|
540 |
/**
|
|
541 |
* Flag for stopPropagation that is modified during fire()
|
|
542 |
* 1 means to stop propagation to bubble targets. 2 means
|
|
543 |
* to also stop additional subscribers on this target.
|
|
544 |
* @property stopped
|
|
545 |
* @type int
|
|
546 |
*/
|
|
547 |
// this.stopped = 0;
|
|
548 |
||
549 |
/**
|
|
550 |
* Flag for preventDefault that is modified during fire().
|
|
551 |
* if it is not 0, the default behavior for this event
|
|
552 |
* @property prevented
|
|
553 |
* @type int
|
|
554 |
*/
|
|
555 |
// this.prevented = 0;
|
|
556 |
||
557 |
/**
|
|
558 |
* Specifies the host for this custom event. This is used
|
|
559 |
* to enable event bubbling
|
|
560 |
* @property host
|
|
561 |
* @type EventTarget
|
|
562 |
*/
|
|
563 |
// this.host = null;
|
|
564 |
||
565 |
/**
|
|
566 |
* The default function to execute after event listeners
|
|
567 |
* have fire, but only if the default action was not
|
|
568 |
* prevented.
|
|
569 |
* @property defaultFn
|
|
570 |
* @type Function
|
|
571 |
*/
|
|
572 |
// this.defaultFn = null;
|
|
573 |
||
574 |
/**
|
|
575 |
* The function to execute if a subscriber calls
|
|
576 |
* stopPropagation or stopImmediatePropagation
|
|
577 |
* @property stoppedFn
|
|
578 |
* @type Function
|
|
579 |
*/
|
|
580 |
// this.stoppedFn = null;
|
|
581 |
||
582 |
/**
|
|
583 |
* The function to execute if a subscriber calls
|
|
584 |
* preventDefault
|
|
585 |
* @property preventedFn
|
|
586 |
* @type Function
|
|
587 |
*/
|
|
588 |
// this.preventedFn = null;
|
|
589 |
||
590 |
/**
|
|
591 |
* Specifies whether or not this event's default function
|
|
592 |
* can be cancelled by a subscriber by executing preventDefault()
|
|
593 |
* on the event facade
|
|
594 |
* @property preventable
|
|
595 |
* @type boolean
|
|
596 |
* @default true
|
|
597 |
*/
|
|
598 |
this.preventable = true; |
|
599 |
||
600 |
/**
|
|
601 |
* Specifies whether or not a subscriber can stop the event propagation
|
|
602 |
* via stopPropagation(), stopImmediatePropagation(), or halt()
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
603 |
*
|
604 |
* Events can only bubble if emitFacade is true.
|
|
605 |
*
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
606 |
* @property bubbles
|
607 |
* @type boolean
|
|
608 |
* @default true
|
|
609 |
*/
|
|
610 |
this.bubbles = true; |
|
611 |
||
612 |
/**
|
|
613 |
* Supports multiple options for listener signatures in order to
|
|
614 |
* port YUI 2 apps.
|
|
615 |
* @property signature
|
|
616 |
* @type int
|
|
617 |
* @default 9
|
|
618 |
*/
|
|
619 |
this.signature = YUI3_SIGNATURE; |
|
620 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
621 |
this.subCount = 0; |
622 |
this.afterCount = 0; |
|
623 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
624 |
// this.hasSubscribers = false;
|
625 |
||
626 |
// this.hasAfters = false;
|
|
627 |
||
628 |
/**
|
|
629 |
* If set to true, the custom event will deliver an EventFacade object
|
|
630 |
* that is similar to a DOM event object.
|
|
631 |
* @property emitFacade
|
|
632 |
* @type boolean
|
|
633 |
* @default false
|
|
634 |
*/
|
|
635 |
// this.emitFacade = false;
|
|
636 |
||
637 |
this.applyConfig(o, true); |
|
638 |
||
639 |
// this.log("Creating " + this.type);
|
|
640 |
||
641 |
};
|
|
642 |
||
643 |
Y.CustomEvent.prototype = { |
|
644 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
645 |
hasSubs: function(when) { |
646 |
var s = this.subCount, a = this.afterCount, sib = this.sibling; |
|
647 |
||
648 |
if (sib) { |
|
649 |
s += sib.subCount; |
|
650 |
a += sib.afterCount; |
|
651 |
}
|
|
652 |
||
653 |
if (when) { |
|
654 |
return (when == 'after') ? a : s; |
|
655 |
}
|
|
656 |
||
657 |
return (s + a); |
|
658 |
},
|
|
659 |
||
660 |
/**
|
|
661 |
* Monitor the event state for the subscribed event. The first parameter
|
|
662 |
* is what should be monitored, the rest are the normal parameters when
|
|
663 |
* subscribing to an event.
|
|
664 |
* @method monitor
|
|
665 |
* @param what {string} what to monitor ('detach', 'attach', 'publish')
|
|
666 |
* @return {EventHandle} return value from the monitor event subscription
|
|
667 |
*/
|
|
668 |
monitor: function(what) { |
|
669 |
this.monitored = true; |
|
670 |
var type = this.id + '|' + this.type + '_' + what, |
|
671 |
args = Y.Array(arguments, 0, true); |
|
672 |
args[0] = type; |
|
673 |
return this.host.on.apply(this.host, args); |
|
674 |
},
|
|
675 |
||
676 |
/**
|
|
677 |
* Get all of the subscribers to this event and any sibling event
|
|
678 |
* @return {Array} first item is the on subscribers, second the after
|
|
679 |
*/
|
|
680 |
getSubs: function() { |
|
681 |
var s = Y.merge(this.subscribers), a = Y.merge(this.afters), sib = this.sibling; |
|
682 |
||
683 |
if (sib) { |
|
684 |
Y.mix(s, sib.subscribers); |
|
685 |
Y.mix(a, sib.afters); |
|
686 |
}
|
|
687 |
||
688 |
return [s, a]; |
|
689 |
},
|
|
690 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
691 |
/**
|
692 |
* Apply configuration properties. Only applies the CONFIG whitelist
|
|
693 |
* @method applyConfig
|
|
694 |
* @param o hash of properties to apply
|
|
695 |
* @param force {boolean} if true, properties that exist on the event
|
|
696 |
* will be overwritten.
|
|
697 |
*/
|
|
698 |
applyConfig: function(o, force) { |
|
699 |
if (o) { |
|
700 |
Y.mix(this, o, force, CONFIGS); |
|
701 |
}
|
|
702 |
},
|
|
703 |
||
704 |
_on: function(fn, context, args, when) { |
|
705 |
||
706 |
if (!fn) { |
|
707 |
this.log("Invalid callback for CE: " + this.type); |
|
708 |
}
|
|
709 |
||
710 |
var s = new Y.Subscriber(fn, context, args, when); |
|
711 |
||
712 |
if (this.fireOnce && this.fired) { |
|
166.8.15
by Sidnei da Silva
- Update to yui-3.1.1 |
713 |
if (this.async) { |
714 |
setTimeout(Y.bind(this._notify, this, s, this.firedWith), 0); |
|
715 |
} else { |
|
716 |
this._notify(s, this.firedWith); |
|
717 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
718 |
}
|
719 |
||
720 |
if (when == AFTER) { |
|
721 |
this.afters[s.id] = s; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
722 |
this.afterCount++; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
723 |
} else { |
724 |
this.subscribers[s.id] = s; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
725 |
this.subCount++; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
726 |
}
|
727 |
||
728 |
return new Y.EventHandle(this, s); |
|
729 |
||
730 |
},
|
|
731 |
||
732 |
/**
|
|
733 |
* Listen for this event
|
|
734 |
* @method subscribe
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
735 |
* @param {Function} fn The function to execute
|
736 |
* @return {EventHandle} Unsubscribe handle
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
737 |
* @deprecated use on
|
738 |
*/
|
|
739 |
subscribe: function(fn, context) { |
|
740 |
Y.log('ce.subscribe deprecated, use "on"', 'warn', 'deprecated'); |
|
741 |
var a = (arguments.length > 2) ? Y.Array(arguments, 2, true): null; |
|
742 |
return this._on(fn, context, a, true); |
|
743 |
},
|
|
744 |
||
745 |
/**
|
|
746 |
* Listen for this event
|
|
747 |
* @method on
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
748 |
* @param {Function} fn The function to execute
|
749 |
* @param context {object} optional execution context.
|
|
750 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
|
751 |
* when the event fires.
|
|
752 |
* @return {EventHandle} An object with a detach method to detch the handler(s)
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
753 |
*/
|
754 |
on: function(fn, context) { |
|
755 |
var a = (arguments.length > 2) ? Y.Array(arguments, 2, true): null; |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
756 |
if (this.host) { |
757 |
this.host._monitor('attach', this.type, { |
|
758 |
args: arguments |
|
759 |
});
|
|
760 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
761 |
return this._on(fn, context, a, true); |
762 |
},
|
|
763 |
||
764 |
/**
|
|
765 |
* Listen for this event after the normal subscribers have been notified and
|
|
766 |
* the default behavior has been applied. If a normal subscriber prevents the
|
|
767 |
* default behavior, it also prevents after listeners from firing.
|
|
768 |
* @method after
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
769 |
* @param {Function} fn The function to execute
|
770 |
* @param context {object} optional execution context.
|
|
771 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
|
772 |
* when the event fires.
|
|
773 |
* @return {EventHandle} handle Unsubscribe handle
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
774 |
*/
|
775 |
after: function(fn, context) { |
|
776 |
var a = (arguments.length > 2) ? Y.Array(arguments, 2, true): null; |
|
777 |
return this._on(fn, context, a, AFTER); |
|
778 |
},
|
|
779 |
||
780 |
/**
|
|
781 |
* Detach listeners.
|
|
782 |
* @method detach
|
|
783 |
* @param {Function} fn The subscribed function to remove, if not supplied
|
|
784 |
* all will be removed
|
|
785 |
* @param {Object} context The context object passed to subscribe.
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
786 |
* @return {int} returns the number of subscribers unsubscribed
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
787 |
*/
|
788 |
detach: function(fn, context) { |
|
789 |
// unsubscribe handle
|
|
790 |
if (fn && fn.detach) { |
|
791 |
return fn.detach(); |
|
792 |
}
|
|
793 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
794 |
var i, s, |
795 |
found = 0, |
|
796 |
subs = Y.merge(this.subscribers, this.afters); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
797 |
|
798 |
for (i in subs) { |
|
799 |
if (subs.hasOwnProperty(i)) { |
|
800 |
s = subs[i]; |
|
801 |
if (s && (!fn || fn === s.fn)) { |
|
802 |
this._delete(s); |
|
803 |
found++; |
|
804 |
}
|
|
805 |
}
|
|
806 |
}
|
|
807 |
||
808 |
return found; |
|
809 |
},
|
|
810 |
||
811 |
/**
|
|
812 |
* Detach listeners.
|
|
813 |
* @method unsubscribe
|
|
814 |
* @param {Function} fn The subscribed function to remove, if not supplied
|
|
815 |
* all will be removed
|
|
816 |
* @param {Object} context The context object passed to subscribe.
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
817 |
* @return {int|undefined} returns the number of subscribers unsubscribed
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
818 |
* @deprecated use detach
|
819 |
*/
|
|
820 |
unsubscribe: function() { |
|
821 |
return this.detach.apply(this, arguments); |
|
822 |
},
|
|
823 |
||
824 |
/**
|
|
825 |
* Notify a single subscriber
|
|
826 |
* @method _notify
|
|
827 |
* @param s {Subscriber} the subscriber
|
|
828 |
* @param args {Array} the arguments array to apply to the listener
|
|
829 |
* @private
|
|
830 |
*/
|
|
831 |
_notify: function(s, args, ef) { |
|
832 |
||
833 |
this.log(this.type + "->" + "sub: " + s.id); |
|
834 |
||
835 |
var ret; |
|
836 |
||
837 |
ret = s.notify(args, this); |
|
838 |
||
839 |
if (false === ret || this.stopped > 1) { |
|
840 |
this.log(this.type + " cancelled by subscriber"); |
|
841 |
return false; |
|
842 |
}
|
|
843 |
||
844 |
return true; |
|
845 |
},
|
|
846 |
||
847 |
/**
|
|
848 |
* Logger abstraction to centralize the application of the silent flag
|
|
849 |
* @method log
|
|
850 |
* @param msg {string} message to log
|
|
851 |
* @param cat {string} log category
|
|
852 |
*/
|
|
853 |
log: function(msg, cat) { |
|
854 |
if (!this.silent) { |
|
855 |
Y.log(this.id + ': ' + msg, cat || "info", "event"); |
|
856 |
}
|
|
857 |
},
|
|
858 |
||
859 |
/**
|
|
860 |
* Notifies the subscribers. The callback functions will be executed
|
|
861 |
* from the context specified when the event was created, and with the
|
|
862 |
* following parameters:
|
|
863 |
* <ul>
|
|
864 |
* <li>The type of event</li>
|
|
865 |
* <li>All of the arguments fire() was executed with as an array</li>
|
|
866 |
* <li>The custom object (if any) that was passed into the subscribe()
|
|
867 |
* method</li>
|
|
868 |
* </ul>
|
|
869 |
* @method fire
|
|
870 |
* @param {Object*} arguments an arbitrary set of parameters to pass to
|
|
871 |
* the handler.
|
|
872 |
* @return {boolean} false if one of the subscribers returned false,
|
|
873 |
* true otherwise
|
|
874 |
*
|
|
875 |
*/
|
|
876 |
fire: function() { |
|
877 |
if (this.fireOnce && this.fired) { |
|
878 |
this.log('fireOnce event: ' + this.type + ' already fired'); |
|
879 |
return true; |
|
880 |
} else { |
|
881 |
||
882 |
var args = Y.Array(arguments, 0, true); |
|
883 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
884 |
// this doesn't happen if the event isn't published
|
885 |
// this.host._monitor('fire', this.type, args);
|
|
886 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
887 |
this.fired = true; |
888 |
this.firedWith = args; |
|
889 |
||
890 |
if (this.emitFacade) { |
|
891 |
return this.fireComplex(args); |
|
892 |
} else { |
|
893 |
return this.fireSimple(args); |
|
894 |
}
|
|
895 |
}
|
|
896 |
},
|
|
897 |
||
898 |
fireSimple: function(args) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
899 |
this.stopped = 0; |
900 |
this.prevented = 0; |
|
901 |
if (this.hasSubs()) { |
|
902 |
// this._procSubs(Y.merge(this.subscribers, this.afters), args);
|
|
903 |
var subs = this.getSubs(); |
|
904 |
this._procSubs(subs[0], args); |
|
905 |
this._procSubs(subs[1], args); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
906 |
}
|
907 |
this._broadcast(args); |
|
908 |
return this.stopped ? false : true; |
|
909 |
},
|
|
910 |
||
911 |
// Requires the event-custom-complex module for full funcitonality.
|
|
912 |
fireComplex: function(args) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
913 |
Y.log('Missing event-custom-complex needed to emit a facade for: ' + this.type); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
914 |
args[0] = args[0] || {}; |
915 |
return this.fireSimple(args); |
|
916 |
},
|
|
917 |
||
918 |
_procSubs: function(subs, args, ef) { |
|
919 |
var s, i; |
|
920 |
for (i in subs) { |
|
921 |
if (subs.hasOwnProperty(i)) { |
|
922 |
s = subs[i]; |
|
923 |
if (s && s.fn) { |
|
924 |
if (false === this._notify(s, args, ef)) { |
|
925 |
this.stopped = 2; |
|
926 |
}
|
|
927 |
if (this.stopped == 2) { |
|
928 |
return false; |
|
929 |
}
|
|
930 |
}
|
|
931 |
}
|
|
932 |
}
|
|
933 |
||
934 |
return true; |
|
935 |
},
|
|
936 |
||
937 |
_broadcast: function(args) { |
|
938 |
if (!this.stopped && this.broadcast) { |
|
939 |
||
940 |
var a = Y.Array(args); |
|
941 |
a.unshift(this.type); |
|
942 |
||
943 |
if (this.host !== Y) { |
|
944 |
Y.fire.apply(Y, a); |
|
945 |
}
|
|
946 |
||
947 |
if (this.broadcast == 2) { |
|
948 |
Y.Global.fire.apply(Y.Global, a); |
|
949 |
}
|
|
950 |
}
|
|
951 |
},
|
|
952 |
||
953 |
/**
|
|
954 |
* Removes all listeners
|
|
955 |
* @method unsubscribeAll
|
|
956 |
* @return {int} The number of listeners unsubscribed
|
|
957 |
* @deprecated use detachAll
|
|
958 |
*/
|
|
959 |
unsubscribeAll: function() { |
|
960 |
return this.detachAll.apply(this, arguments); |
|
961 |
},
|
|
962 |
||
963 |
/**
|
|
964 |
* Removes all listeners
|
|
965 |
* @method detachAll
|
|
966 |
* @return {int} The number of listeners unsubscribed
|
|
967 |
*/
|
|
968 |
detachAll: function() { |
|
969 |
return this.detach(); |
|
970 |
},
|
|
971 |
||
972 |
/**
|
|
973 |
* @method _delete
|
|
974 |
* @param subscriber object
|
|
975 |
* @private
|
|
976 |
*/
|
|
977 |
_delete: function(s) { |
|
978 |
if (s) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
979 |
if (this.subscribers[s.id]) { |
980 |
delete this.subscribers[s.id]; |
|
981 |
this.subCount--; |
|
982 |
}
|
|
983 |
if (this.afters[s.id]) { |
|
984 |
delete this.afters[s.id]; |
|
985 |
this.afterCount--; |
|
986 |
}
|
|
987 |
}
|
|
988 |
||
989 |
if (this.host) { |
|
990 |
this.host._monitor('detach', this.type, { |
|
991 |
ce: this, |
|
992 |
sub: s |
|
993 |
});
|
|
994 |
}
|
|
995 |
||
996 |
if (s) { |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
997 |
delete s.fn; |
998 |
delete s.context; |
|
999 |
}
|
|
1000 |
}
|
|
1001 |
};
|
|
1002 |
||
1003 |
/////////////////////////////////////////////////////////////////////
|
|
1004 |
||
1005 |
/**
|
|
1006 |
* Stores the subscriber information to be used when the event fires.
|
|
1007 |
* @param {Function} fn The wrapped function to execute
|
|
1008 |
* @param {Object} context The value of the keyword 'this' in the listener
|
|
1009 |
* @param {Array} args* 0..n additional arguments to supply the listener
|
|
1010 |
*
|
|
1011 |
* @class Subscriber
|
|
1012 |
* @constructor
|
|
1013 |
*/
|
|
1014 |
Y.Subscriber = function(fn, context, args) { |
|
1015 |
||
1016 |
/**
|
|
1017 |
* The callback that will be execute when the event fires
|
|
1018 |
* This is wrapped by Y.rbind if obj was supplied.
|
|
1019 |
* @property fn
|
|
1020 |
* @type Function
|
|
1021 |
*/
|
|
1022 |
this.fn = fn; |
|
1023 |
||
1024 |
/**
|
|
1025 |
* Optional 'this' keyword for the listener
|
|
1026 |
* @property context
|
|
1027 |
* @type Object
|
|
1028 |
*/
|
|
1029 |
this.context = context; |
|
1030 |
||
1031 |
/**
|
|
1032 |
* Unique subscriber id
|
|
1033 |
* @property id
|
|
1034 |
* @type String
|
|
1035 |
*/
|
|
1036 |
this.id = Y.stamp(this); |
|
1037 |
||
1038 |
/**
|
|
1039 |
* Additional arguments to propagate to the subscriber
|
|
1040 |
* @property args
|
|
1041 |
* @type Array
|
|
1042 |
*/
|
|
1043 |
this.args = args; |
|
1044 |
||
1045 |
/**
|
|
1046 |
* Custom events for a given fire transaction.
|
|
1047 |
* @property events
|
|
1048 |
* @type {EventTarget}
|
|
1049 |
*/
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1050 |
// this.events = null;
|
1051 |
||
1052 |
/**
|
|
1053 |
* This listener only reacts to the event once
|
|
1054 |
* @property once
|
|
1055 |
*/
|
|
1056 |
// this.once = false;
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1057 |
|
1058 |
};
|
|
1059 |
||
1060 |
Y.Subscriber.prototype = { |
|
1061 |
||
1062 |
_notify: function(c, args, ce) { |
|
1063 |
var a = this.args, ret; |
|
1064 |
switch (ce.signature) { |
|
1065 |
case 0: |
|
1066 |
ret = this.fn.call(c, ce.type, args, c); |
|
1067 |
break; |
|
1068 |
case 1: |
|
1069 |
ret = this.fn.call(c, args[0] || null, c); |
|
1070 |
break; |
|
1071 |
default: |
|
1072 |
if (a || args) { |
|
1073 |
args = args || []; |
|
1074 |
a = (a) ? args.concat(a) : args; |
|
1075 |
ret = this.fn.apply(c, a); |
|
1076 |
} else { |
|
1077 |
ret = this.fn.call(c); |
|
1078 |
}
|
|
1079 |
}
|
|
1080 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1081 |
if (this.once) { |
1082 |
ce._delete(this); |
|
1083 |
}
|
|
1084 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1085 |
return ret; |
1086 |
},
|
|
1087 |
||
1088 |
/**
|
|
1089 |
* Executes the subscriber.
|
|
1090 |
* @method notify
|
|
1091 |
* @param args {Array} Arguments array for the subscriber
|
|
1092 |
* @param ce {CustomEvent} The custom event that sent the notification
|
|
1093 |
*/
|
|
1094 |
notify: function(args, ce) { |
|
1095 |
var c = this.context, |
|
1096 |
ret = true; |
|
1097 |
||
1098 |
if (!c) { |
|
1099 |
c = (ce.contextFn) ? ce.contextFn() : ce.context; |
|
1100 |
}
|
|
1101 |
||
1102 |
// only catch errors if we will not re-throw them.
|
|
1103 |
if (Y.config.throwFail) { |
|
1104 |
ret = this._notify(c, args, ce); |
|
1105 |
} else { |
|
1106 |
try { |
|
1107 |
ret = this._notify(c, args, ce); |
|
1108 |
} catch(e) { |
|
1109 |
Y.error(this + ' failed: ' + e.message, e); |
|
1110 |
}
|
|
1111 |
}
|
|
1112 |
||
1113 |
return ret; |
|
1114 |
},
|
|
1115 |
||
1116 |
/**
|
|
1117 |
* Returns true if the fn and obj match this objects properties.
|
|
1118 |
* Used by the unsubscribe method to match the right subscriber.
|
|
1119 |
*
|
|
1120 |
* @method contains
|
|
1121 |
* @param {Function} fn the function to execute
|
|
1122 |
* @param {Object} context optional 'this' keyword for the listener
|
|
1123 |
* @return {boolean} true if the supplied arguments match this
|
|
1124 |
* subscriber's signature.
|
|
1125 |
*/
|
|
1126 |
contains: function(fn, context) { |
|
1127 |
if (context) { |
|
1128 |
return ((this.fn == fn) && this.context == context); |
|
1129 |
} else { |
|
1130 |
return (this.fn == fn); |
|
1131 |
}
|
|
1132 |
}
|
|
1133 |
||
1134 |
};
|
|
1135 |
||
1136 |
/**
|
|
1137 |
* Custom event engine, DOM event listener abstraction layer, synthetic DOM
|
|
1138 |
* events.
|
|
1139 |
* @module event-custom
|
|
1140 |
* @submodule event-custom-base
|
|
1141 |
*/
|
|
1142 |
(function() { |
|
1143 |
||
1144 |
/**
|
|
1145 |
* EventTarget provides the implementation for any object to
|
|
1146 |
* publish, subscribe and fire to custom events, and also
|
|
1147 |
* alows other EventTargets to target the object with events
|
|
1148 |
* sourced from the other object.
|
|
1149 |
* EventTarget is designed to be used with Y.augment to wrap
|
|
1150 |
* EventCustom in an interface that allows events to be listened to
|
|
1151 |
* and fired by name. This makes it possible for implementing code to
|
|
1152 |
* subscribe to an event that either has not been created yet, or will
|
|
1153 |
* not be created at all.
|
|
1154 |
* @class EventTarget
|
|
1155 |
* @param opts a configuration object
|
|
1156 |
* @config emitFacade {boolean} if true, all events will emit event
|
|
1157 |
* facade payloads by default (default false)
|
|
1158 |
* @config prefix {string} the prefix to apply to non-prefixed event names
|
|
1159 |
* @config chain {boolean} if true, on/after/detach return the host to allow
|
|
1160 |
* chaining, otherwise they return an EventHandle (default false)
|
|
1161 |
*/
|
|
1162 |
||
1163 |
var L = Y.Lang, |
|
1164 |
PREFIX_DELIMITER = ':', |
|
1165 |
CATEGORY_DELIMITER = '|', |
|
1166 |
AFTER_PREFIX = '~AFTER~', |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1167 |
YArray = Y.Array, |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1168 |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1169 |
_wildType = Y.cached(function(type) { |
1170 |
return type.replace(/(.*)(:)(.*)/, "*$2$3"); |
|
1171 |
}),
|
|
1172 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1173 |
/**
|
1174 |
* If the instance has a prefix attribute and the
|
|
1175 |
* event type is not prefixed, the instance prefix is
|
|
1176 |
* applied to the supplied type.
|
|
1177 |
* @method _getType
|
|
1178 |
* @private
|
|
1179 |
*/
|
|
1180 |
_getType = Y.cached(function(type, pre) { |
|
1181 |
||
1182 |
if (!pre || !L.isString(type) || type.indexOf(PREFIX_DELIMITER) > -1) { |
|
1183 |
return type; |
|
1184 |
}
|
|
1185 |
||
1186 |
return pre + PREFIX_DELIMITER + type; |
|
1187 |
}),
|
|
1188 |
||
1189 |
/**
|
|
1190 |
* Returns an array with the detach key (if provided),
|
|
1191 |
* and the prefixed event name from _getType
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1192 |
* Y.on('detachcategory| menu:click', fn)
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1193 |
* @method _parseType
|
1194 |
* @private
|
|
1195 |
*/
|
|
1196 |
_parseType = Y.cached(function(type, pre) { |
|
1197 |
||
1198 |
var t = type, detachcategory, after, i; |
|
1199 |
||
1200 |
if (!L.isString(t)) { |
|
1201 |
return t; |
|
1202 |
}
|
|
1203 |
||
1204 |
i = t.indexOf(AFTER_PREFIX); |
|
1205 |
||
1206 |
if (i > -1) { |
|
1207 |
after = true; |
|
1208 |
t = t.substr(AFTER_PREFIX.length); |
|
1209 |
// Y.log(t);
|
|
1210 |
}
|
|
1211 |
||
1212 |
i = t.indexOf(CATEGORY_DELIMITER); |
|
1213 |
||
1214 |
if (i > -1) { |
|
1215 |
detachcategory = t.substr(0, (i)); |
|
1216 |
t = t.substr(i+1); |
|
1217 |
if (t == '*') { |
|
1218 |
t = null; |
|
1219 |
}
|
|
1220 |
}
|
|
1221 |
||
1222 |
// detach category, full type with instance prefix, is this an after listener, short type
|
|
1223 |
return [detachcategory, (pre) ? _getType(t, pre) : t, after, t]; |
|
1224 |
}),
|
|
1225 |
||
1226 |
ET = function(opts) { |
|
1227 |
||
1228 |
// Y.log('EventTarget constructor executed: ' + this._yuid);
|
|
1229 |
||
1230 |
var o = (L.isObject(opts)) ? opts : {}; |
|
1231 |
||
1232 |
this._yuievt = this._yuievt || { |
|
1233 |
||
1234 |
id: Y.guid(), |
|
1235 |
||
1236 |
events: {}, |
|
1237 |
||
1238 |
targets: {}, |
|
1239 |
||
1240 |
config: o, |
|
1241 |
||
1242 |
chain: ('chain' in o) ? o.chain : Y.config.chain, |
|
1243 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1244 |
bubbling: false, |
1245 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1246 |
defaults: { |
1247 |
context: o.context || this, |
|
1248 |
host: this, |
|
1249 |
emitFacade: o.emitFacade, |
|
1250 |
fireOnce: o.fireOnce, |
|
1251 |
queuable: o.queuable, |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1252 |
monitored: o.monitored, |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1253 |
broadcast: o.broadcast, |
166.19.1
by Paul Hummer
New YUI 3.2 |
1254 |
defaultTargetOnly: o.defaultTargetOnly, |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1255 |
bubbles: ('bubbles' in o) ? o.bubbles : true |
1256 |
}
|
|
1257 |
};
|
|
1258 |
||
1259 |
};
|
|
1260 |
||
1261 |
||
1262 |
ET.prototype = { |
|
1263 |
||
1264 |
/**
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1265 |
* Listen to a custom event hosted by this object one time.
|
1266 |
* This is the equivalent to <code>on</code> except the
|
|
1267 |
* listener is immediatelly detached when it is executed.
|
|
1268 |
* @method once
|
|
1269 |
* @param type {string} The type of the event
|
|
1270 |
* @param fn {Function} The callback
|
|
1271 |
* @param context {object} optional execution context.
|
|
1272 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
|
1273 |
* @return the event target or a detach handle per 'chain' config
|
|
1274 |
*/
|
|
1275 |
once: function() { |
|
1276 |
var handle = this.on.apply(this, arguments); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1277 |
handle.each(function(hand) { |
1278 |
if (hand.sub) { |
|
1279 |
hand.sub.once = true; |
|
1280 |
}
|
|
1281 |
});
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1282 |
return handle; |
1283 |
},
|
|
1284 |
||
1285 |
/**
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1286 |
* Subscribe to a custom event hosted by this object
|
1287 |
* @method on
|
|
1288 |
* @param type {string} The type of the event
|
|
1289 |
* @param fn {Function} The callback
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1290 |
* @param context {object} optional execution context.
|
1291 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1292 |
* @return the event target or a detach handle per 'chain' config
|
1293 |
*/
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1294 |
on: function(type, fn, context) { |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1295 |
|
1296 |
var parts = _parseType(type, this._yuievt.config.prefix), f, c, args, ret, ce, |
|
1297 |
detachcategory, handle, store = Y.Env.evt.handles, after, adapt, shorttype, |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1298 |
Node = Y.Node, n, domevent, isArr; |
1299 |
||
1300 |
// full name, args, detachcategory, after
|
|
1301 |
this._monitor('attach', parts[1], { |
|
1302 |
args: arguments, |
|
1303 |
category: parts[0], |
|
1304 |
after: parts[2] |
|
1305 |
});
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1306 |
|
1307 |
if (L.isObject(type)) { |
|
1308 |
||
1309 |
if (L.isFunction(type)) { |
|
1310 |
return Y.Do.before.apply(Y.Do, arguments); |
|
1311 |
}
|
|
1312 |
||
1313 |
f = fn; |
|
1314 |
c = context; |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1315 |
args = YArray(arguments, 0, true); |
1316 |
ret = []; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1317 |
|
1318 |
if (L.isArray(type)) { |
|
1319 |
isArr = true; |
|
1320 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1321 |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1322 |
after = type._after; |
1323 |
delete type._after; |
|
1324 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1325 |
Y.each(type, function(v, k) { |
1326 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1327 |
if (L.isObject(v)) { |
1328 |
f = v.fn || ((L.isFunction(v)) ? v : f); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1329 |
c = v.context || c; |
1330 |
}
|
|
1331 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1332 |
var nv = (after) ? AFTER_PREFIX : ''; |
1333 |
||
1334 |
args[0] = nv + ((isArr) ? v : k); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1335 |
args[1] = f; |
1336 |
args[2] = c; |
|
1337 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1338 |
ret.push(this.on.apply(this, args)); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1339 |
|
1340 |
}, this); |
|
1341 |
||
1342 |
return (this._yuievt.chain) ? this : new Y.EventHandle(ret); |
|
1343 |
||
1344 |
}
|
|
1345 |
||
1346 |
detachcategory = parts[0]; |
|
1347 |
after = parts[2]; |
|
1348 |
shorttype = parts[3]; |
|
1349 |
||
1350 |
// extra redirection so we catch adaptor events too. take a look at this.
|
|
1351 |
if (Node && (this instanceof Node) && (shorttype in Node.DOM_EVENTS)) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1352 |
args = YArray(arguments, 0, true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1353 |
args.splice(2, 0, Node.getDOMNode(this)); |
1354 |
// Y.log("Node detected, redirecting with these args: " + args);
|
|
1355 |
return Y.on.apply(Y, args); |
|
1356 |
}
|
|
1357 |
||
1358 |
type = parts[1]; |
|
1359 |
||
1360 |
if (this instanceof YUI) { |
|
1361 |
||
1362 |
adapt = Y.Env.evt.plugins[type]; |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1363 |
args = YArray(arguments, 0, true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1364 |
args[0] = shorttype; |
1365 |
||
1366 |
if (Node) { |
|
1367 |
n = args[2]; |
|
1368 |
||
1369 |
if (n instanceof Y.NodeList) { |
|
1370 |
n = Y.NodeList.getDOMNodes(n); |
|
1371 |
} else if (n instanceof Node) { |
|
1372 |
n = Node.getDOMNode(n); |
|
1373 |
}
|
|
1374 |
||
1375 |
domevent = (shorttype in Node.DOM_EVENTS); |
|
1376 |
||
1377 |
// Captures both DOM events and event plugins.
|
|
1378 |
if (domevent) { |
|
1379 |
args[2] = n; |
|
1380 |
}
|
|
1381 |
}
|
|
1382 |
||
1383 |
// check for the existance of an event adaptor
|
|
1384 |
if (adapt) { |
|
1385 |
Y.log('Using adaptor for ' + shorttype + ', ' + n, 'info', 'event'); |
|
1386 |
handle = adapt.on.apply(Y, args); |
|
1387 |
} else if ((!type) || domevent) { |
|
1388 |
handle = Y.Event._attach(args); |
|
1389 |
}
|
|
1390 |
||
1391 |
}
|
|
1392 |
||
1393 |
if (!handle) { |
|
1394 |
ce = this._yuievt.events[type] || this.publish(type); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1395 |
handle = ce._on(fn, context, (arguments.length > 3) ? YArray(arguments, 3, true) : null, (after) ? 'after' : true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1396 |
}
|
1397 |
||
1398 |
if (detachcategory) { |
|
1399 |
store[detachcategory] = store[detachcategory] || {}; |
|
1400 |
store[detachcategory][type] = store[detachcategory][type] || []; |
|
1401 |
store[detachcategory][type].push(handle); |
|
1402 |
}
|
|
1403 |
||
1404 |
return (this._yuievt.chain) ? this : handle; |
|
1405 |
||
1406 |
},
|
|
1407 |
||
1408 |
/**
|
|
1409 |
* subscribe to an event
|
|
1410 |
* @method subscribe
|
|
1411 |
* @deprecated use on
|
|
1412 |
*/
|
|
1413 |
subscribe: function() { |
|
1414 |
Y.log('EventTarget subscribe() is deprecated, use on()', 'warn', 'deprecated'); |
|
1415 |
return this.on.apply(this, arguments); |
|
1416 |
},
|
|
1417 |
||
1418 |
/**
|
|
1419 |
* Detach one or more listeners the from the specified event
|
|
1420 |
* @method detach
|
|
1421 |
* @param type {string|Object} Either the handle to the subscriber or the
|
|
1422 |
* type of event. If the type
|
|
1423 |
* is not specified, it will attempt to remove
|
|
1424 |
* the listener from all hosted events.
|
|
1425 |
* @param fn {Function} The subscribed function to unsubscribe, if not
|
|
1426 |
* supplied, all subscribers will be removed.
|
|
1427 |
* @param context {Object} The custom object passed to subscribe. This is
|
|
1428 |
* optional, but if supplied will be used to
|
|
1429 |
* disambiguate multiple listeners that are the same
|
|
1430 |
* (e.g., you subscribe many object using a function
|
|
1431 |
* that lives on the prototype)
|
|
1432 |
* @return {EventTarget} the host
|
|
1433 |
*/
|
|
1434 |
detach: function(type, fn, context) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1435 |
var evts = this._yuievt.events, i, |
1436 |
Node = Y.Node, isNode = Node && (this instanceof Node); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1437 |
|
1438 |
// detachAll disabled on the Y instance.
|
|
1439 |
if (!type && (this !== Y)) { |
|
1440 |
for (i in evts) { |
|
1441 |
if (evts.hasOwnProperty(i)) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1442 |
evts[i].detach(fn, context); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1443 |
}
|
1444 |
}
|
|
1445 |
if (isNode) { |
|
1446 |
Y.Event.purgeElement(Node.getDOMNode(this)); |
|
1447 |
}
|
|
1448 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1449 |
return this; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1450 |
}
|
1451 |
||
1452 |
var parts = _parseType(type, this._yuievt.config.prefix), |
|
1453 |
detachcategory = L.isArray(parts) ? parts[0] : null, |
|
1454 |
shorttype = (parts) ? parts[3] : null, |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1455 |
adapt, store = Y.Env.evt.handles, detachhost, cat, args, |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1456 |
ce, |
1457 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1458 |
keyDetacher = function(lcat, ltype, host) { |
1459 |
var handles = lcat[ltype], ce, i; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1460 |
if (handles) { |
166.19.1
by Paul Hummer
New YUI 3.2 |
1461 |
for (i = handles.length - 1; i >= 0; --i) { |
1462 |
ce = handles[i].evt; |
|
1463 |
if (ce.host === host || ce.el === host) { |
|
1464 |
handles[i].detach(); |
|
1465 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1466 |
}
|
1467 |
}
|
|
1468 |
};
|
|
1469 |
||
1470 |
if (detachcategory) { |
|
1471 |
||
1472 |
cat = store[detachcategory]; |
|
1473 |
type = parts[1]; |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1474 |
detachhost = (isNode) ? Y.Node.getDOMNode(this) : this; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1475 |
|
1476 |
if (cat) { |
|
1477 |
if (type) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1478 |
keyDetacher(cat, type, detachhost); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1479 |
} else { |
1480 |
for (i in cat) { |
|
1481 |
if (cat.hasOwnProperty(i)) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1482 |
keyDetacher(cat, i, detachhost); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1483 |
}
|
1484 |
}
|
|
1485 |
}
|
|
1486 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1487 |
return this; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1488 |
}
|
1489 |
||
1490 |
// If this is an event handle, use it to detach
|
|
1491 |
} else if (L.isObject(type) && type.detach) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1492 |
type.detach(); |
1493 |
return this; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1494 |
// extra redirection so we catch adaptor events too. take a look at this.
|
1495 |
} else if (isNode && ((!shorttype) || (shorttype in Node.DOM_EVENTS))) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1496 |
args = YArray(arguments, 0, true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1497 |
args[2] = Node.getDOMNode(this); |
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1498 |
Y.detach.apply(Y, args); |
1499 |
return this; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1500 |
}
|
1501 |
||
1502 |
adapt = Y.Env.evt.plugins[shorttype]; |
|
1503 |
||
1504 |
// The YUI instance handles DOM events and adaptors
|
|
1505 |
if (this instanceof YUI) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1506 |
args = YArray(arguments, 0, true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1507 |
// use the adaptor specific detach code if
|
1508 |
if (adapt && adapt.detach) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1509 |
adapt.detach.apply(Y, args); |
1510 |
return this; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1511 |
// DOM event fork
|
1512 |
} else if (!type || (!adapt && Node && (type in Node.DOM_EVENTS))) { |
|
1513 |
args[0] = type; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1514 |
Y.Event.detach.apply(Y.Event, args); |
1515 |
return this; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1516 |
}
|
1517 |
}
|
|
1518 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1519 |
// ce = evts[type];
|
1520 |
ce = evts[parts[1]]; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1521 |
if (ce) { |
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1522 |
ce.detach(fn, context); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1523 |
}
|
1524 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1525 |
return this; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1526 |
},
|
1527 |
||
1528 |
/**
|
|
1529 |
* detach a listener
|
|
1530 |
* @method unsubscribe
|
|
1531 |
* @deprecated use detach
|
|
1532 |
*/
|
|
1533 |
unsubscribe: function() { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1534 |
Y.log('EventTarget unsubscribe() is deprecated, use detach()', 'warn', 'deprecated'); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1535 |
return this.detach.apply(this, arguments); |
1536 |
},
|
|
1537 |
||
1538 |
/**
|
|
1539 |
* Removes all listeners from the specified event. If the event type
|
|
1540 |
* is not specified, all listeners from all hosted custom events will
|
|
1541 |
* be removed.
|
|
1542 |
* @method detachAll
|
|
1543 |
* @param type {string} The type, or name of the event
|
|
1544 |
*/
|
|
1545 |
detachAll: function(type) { |
|
1546 |
return this.detach(type); |
|
1547 |
},
|
|
1548 |
||
1549 |
/**
|
|
1550 |
* Removes all listeners from the specified event. If the event type
|
|
1551 |
* is not specified, all listeners from all hosted custom events will
|
|
1552 |
* be removed.
|
|
1553 |
* @method unsubscribeAll
|
|
1554 |
* @param type {string} The type, or name of the event
|
|
1555 |
* @deprecated use detachAll
|
|
1556 |
*/
|
|
1557 |
unsubscribeAll: function() { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1558 |
Y.log('EventTarget unsubscribeAll() is deprecated, use detachAll()', 'warn', 'deprecated'); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1559 |
return this.detachAll.apply(this, arguments); |
1560 |
},
|
|
1561 |
||
1562 |
/**
|
|
1563 |
* Creates a new custom event of the specified type. If a custom event
|
|
1564 |
* by that name already exists, it will not be re-created. In either
|
|
1565 |
* case the custom event is returned.
|
|
1566 |
*
|
|
1567 |
* @method publish
|
|
1568 |
*
|
|
1569 |
* @param type {string} the type, or name of the event
|
|
1570 |
* @param opts {object} optional config params. Valid properties are:
|
|
1571 |
*
|
|
1572 |
* <ul>
|
|
1573 |
* <li>
|
|
1574 |
* 'broadcast': whether or not the YUI instance and YUI global are notified when the event is fired (false)
|
|
1575 |
* </li>
|
|
1576 |
* <li>
|
|
1577 |
* 'bubbles': whether or not this event bubbles (true)
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1578 |
* Events can only bubble if emitFacade is true.
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1579 |
* </li>
|
1580 |
* <li>
|
|
1581 |
* 'context': the default execution context for the listeners (this)
|
|
1582 |
* </li>
|
|
1583 |
* <li>
|
|
1584 |
* 'defaultFn': the default function to execute when this event fires if preventDefault was not called
|
|
1585 |
* </li>
|
|
1586 |
* <li>
|
|
1587 |
* 'emitFacade': whether or not this event emits a facade (false)
|
|
1588 |
* </li>
|
|
1589 |
* <li>
|
|
1590 |
* 'prefix': the prefix for this targets events, e.g., 'menu' in 'menu:click'
|
|
1591 |
* </li>
|
|
1592 |
* <li>
|
|
1593 |
* 'fireOnce': if an event is configured to fire once, new subscribers after
|
|
1594 |
* the fire will be notified immediately.
|
|
1595 |
* </li>
|
|
1596 |
* <li>
|
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1597 |
* 'async': fireOnce event listeners will fire synchronously if the event has already
|
1598 |
* fired unless async is true.
|
|
1599 |
* </li>
|
|
1600 |
* <li>
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1601 |
* 'preventable': whether or not preventDefault() has an effect (true)
|
1602 |
* </li>
|
|
1603 |
* <li>
|
|
1604 |
* 'preventedFn': a function that is executed when preventDefault is called
|
|
1605 |
* </li>
|
|
1606 |
* <li>
|
|
1607 |
* 'queuable': whether or not this event can be queued during bubbling (false)
|
|
1608 |
* </li>
|
|
1609 |
* <li>
|
|
1610 |
* 'silent': if silent is true, debug messages are not provided for this event.
|
|
1611 |
* </li>
|
|
1612 |
* <li>
|
|
1613 |
* 'stoppedFn': a function that is executed when stopPropagation is called
|
|
1614 |
* </li>
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1615 |
*
|
1616 |
* <li>
|
|
1617 |
* 'monitored': specifies whether or not this event should send notifications about
|
|
1618 |
* when the event has been attached, detached, or published.
|
|
1619 |
* </li>
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1620 |
* <li>
|
1621 |
* 'type': the event type (valid option if not provided as the first parameter to publish)
|
|
1622 |
* </li>
|
|
1623 |
* </ul>
|
|
1624 |
*
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1625 |
* @return {CustomEvent} the custom event
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1626 |
*
|
1627 |
*/
|
|
1628 |
publish: function(type, opts) { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1629 |
var events, ce, ret, defaults, |
1630 |
edata = this._yuievt, |
|
1631 |
pre = edata.config.prefix; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1632 |
|
1633 |
type = (pre) ? _getType(type, pre) : type; |
|
1634 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1635 |
this._monitor('publish', type, { |
1636 |
args: arguments |
|
1637 |
});
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1638 |
|
1639 |
if (L.isObject(type)) { |
|
1640 |
ret = {}; |
|
1641 |
Y.each(type, function(v, k) { |
|
1642 |
ret[k] = this.publish(k, v || opts); |
|
1643 |
}, this); |
|
1644 |
||
1645 |
return ret; |
|
1646 |
}
|
|
1647 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1648 |
events = edata.events; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1649 |
ce = events[type]; |
1650 |
||
1651 |
if (ce) { |
|
1652 |
// ce.log("publish applying new config to published event: '"+type+"' exists", 'info', 'event');
|
|
1653 |
if (opts) { |
|
1654 |
ce.applyConfig(opts, true); |
|
1655 |
}
|
|
1656 |
} else { |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1657 |
|
1658 |
defaults = edata.defaults; |
|
1659 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1660 |
// apply defaults
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1661 |
ce = new Y.CustomEvent(type, |
1662 |
(opts) ? Y.merge(defaults, opts) : defaults); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1663 |
events[type] = ce; |
1664 |
}
|
|
1665 |
||
1666 |
// make sure we turn the broadcast flag off if this
|
|
1667 |
// event was published as a result of bubbling
|
|
1668 |
// if (opts instanceof Y.CustomEvent) {
|
|
1669 |
// events[type].broadcast = false;
|
|
1670 |
// }
|
|
1671 |
||
1672 |
return events[type]; |
|
1673 |
},
|
|
1674 |
||
1675 |
/**
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1676 |
* This is the entry point for the event monitoring system.
|
1677 |
* You can monitor 'attach', 'detach', 'fire', and 'publish'.
|
|
1678 |
* When configured, these events generate an event. click ->
|
|
1679 |
* click_attach, click_detach, click_publish -- these can
|
|
1680 |
* be subscribed to like other events to monitor the event
|
|
1681 |
* system. Inividual published events can have monitoring
|
|
1682 |
* turned on or off (publish can't be turned off before it
|
|
1683 |
* it published) by setting the events 'monitor' config.
|
|
1684 |
*
|
|
1685 |
* @private
|
|
1686 |
*/
|
|
1687 |
_monitor: function(what, type, o) { |
|
1688 |
var monitorevt, ce = this.getEvent(type); |
|
1689 |
if ((this._yuievt.config.monitored && (!ce || ce.monitored)) || (ce && ce.monitored)) { |
|
1690 |
monitorevt = type + '_' + what; |
|
1691 |
// Y.log('monitoring: ' + monitorevt);
|
|
1692 |
o.monitored = what; |
|
1693 |
this.fire.call(this, monitorevt, o); |
|
1694 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1695 |
},
|
1696 |
||
1697 |
/**
|
|
1698 |
* Fire a custom event by name. The callback functions will be executed
|
|
1699 |
* from the context specified when the event was created, and with the
|
|
1700 |
* following parameters.
|
|
1701 |
*
|
|
1702 |
* If the custom event object hasn't been created, then the event hasn't
|
|
1703 |
* been published and it has no subscribers. For performance sake, we
|
|
1704 |
* immediate exit in this case. This means the event won't bubble, so
|
|
1705 |
* if the intention is that a bubble target be notified, the event must
|
|
1706 |
* be published on this object first.
|
|
1707 |
*
|
|
1708 |
* The first argument is the event type, and any additional arguments are
|
|
1709 |
* passed to the listeners as parameters. If the first of these is an
|
|
1710 |
* object literal, and the event is configured to emit an event facade,
|
|
1711 |
* that object is mixed into the event facade and the facade is provided
|
|
1712 |
* in place of the original object.
|
|
1713 |
*
|
|
1714 |
* @method fire
|
|
1715 |
* @param type {String|Object} The type of the event, or an object that contains
|
|
1716 |
* a 'type' property.
|
|
1717 |
* @param arguments {Object*} an arbitrary set of parameters to pass to
|
|
1718 |
* the handler. If the first of these is an object literal and the event is
|
|
1719 |
* configured to emit an event facade, the event facade will replace that
|
|
1720 |
* parameter after the properties the object literal contains are copied to
|
|
1721 |
* the event facade.
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1722 |
* @return {EventTarget} the event host
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1723 |
*
|
1724 |
*/
|
|
1725 |
fire: function(type) { |
|
1726 |
||
1727 |
var typeIncluded = L.isString(type), |
|
1728 |
t = (typeIncluded) ? type : (type && type.type), |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1729 |
ce, ret, pre = this._yuievt.config.prefix, ce2, |
166.19.1
by Paul Hummer
New YUI 3.2 |
1730 |
args = (typeIncluded) ? YArray(arguments, 1, true) : arguments; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1731 |
|
1732 |
t = (pre) ? _getType(t, pre) : t; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1733 |
|
1734 |
this._monitor('fire', t, { |
|
1735 |
args: args |
|
1736 |
});
|
|
1737 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1738 |
ce = this.getEvent(t, true); |
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1739 |
ce2 = this.getSibling(t, ce); |
1740 |
||
1741 |
if (ce2 && !ce) { |
|
1742 |
ce = this.publish(t); |
|
1743 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1744 |
|
1745 |
// this event has not been published or subscribed to
|
|
1746 |
if (!ce) { |
|
1747 |
if (this._yuievt.hasTargets) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1748 |
return this.bubble({ type: t }, args, this); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1749 |
}
|
1750 |
||
1751 |
// otherwise there is nothing to be done
|
|
1752 |
ret = true; |
|
1753 |
} else { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1754 |
ce.sibling = ce2; |
1755 |
ret = ce.fire.apply(ce, args); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1756 |
}
|
1757 |
||
1758 |
return (this._yuievt.chain) ? this : ret; |
|
1759 |
},
|
|
1760 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1761 |
getSibling: function(type, ce) { |
1762 |
var ce2; |
|
1763 |
// delegate to *:type events if there are subscribers
|
|
1764 |
if (type.indexOf(PREFIX_DELIMITER) > -1) { |
|
1765 |
type = _wildType(type); |
|
1766 |
// console.log(type);
|
|
1767 |
ce2 = this.getEvent(type, true); |
|
1768 |
if (ce2) { |
|
1769 |
// console.log("GOT ONE: " + type);
|
|
1770 |
ce2.applyConfig(ce); |
|
1771 |
ce2.bubbles = false; |
|
1772 |
ce2.broadcast = 0; |
|
1773 |
// ret = ce2.fire.apply(ce2, a);
|
|
1774 |
}
|
|
1775 |
}
|
|
1776 |
||
1777 |
return ce2; |
|
1778 |
},
|
|
1779 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1780 |
/**
|
1781 |
* Returns the custom event of the provided type has been created, a
|
|
1782 |
* falsy value otherwise
|
|
1783 |
* @method getEvent
|
|
1784 |
* @param type {string} the type, or name of the event
|
|
1785 |
* @param prefixed {string} if true, the type is prefixed already
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1786 |
* @return {CustomEvent} the custom event or null
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1787 |
*/
|
1788 |
getEvent: function(type, prefixed) { |
|
1789 |
var pre, e; |
|
1790 |
if (!prefixed) { |
|
1791 |
pre = this._yuievt.config.prefix; |
|
1792 |
type = (pre) ? _getType(type, pre) : type; |
|
1793 |
}
|
|
1794 |
e = this._yuievt.events; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1795 |
return e[type] || null; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1796 |
},
|
1797 |
||
1798 |
/**
|
|
1799 |
* Subscribe to a custom event hosted by this object. The
|
|
1800 |
* supplied callback will execute after any listeners add
|
|
1801 |
* via the subscribe method, and after the default function,
|
|
1802 |
* if configured for the event, has executed.
|
|
1803 |
* @method after
|
|
1804 |
* @param type {string} The type of the event
|
|
1805 |
* @param fn {Function} The callback
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1806 |
* @param context {object} optional execution context.
|
1807 |
* @param arg* {mixed} 0..n additional arguments to supply to the subscriber
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1808 |
* @return the event target or a detach handle per 'chain' config
|
1809 |
*/
|
|
1810 |
after: function(type, fn) { |
|
1811 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1812 |
var a = YArray(arguments, 0, true); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1813 |
|
1814 |
switch (L.type(type)) { |
|
1815 |
case 'function': |
|
1816 |
return Y.Do.after.apply(Y.Do, arguments); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1817 |
case 'array': |
1818 |
// YArray.each(a[0], function(v) {
|
|
1819 |
// v = AFTER_PREFIX + v;
|
|
1820 |
// });
|
|
1821 |
// break;
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1822 |
case 'object': |
1823 |
a[0]._after = true; |
|
1824 |
break; |
|
1825 |
default: |
|
1826 |
a[0] = AFTER_PREFIX + type; |
|
1827 |
}
|
|
1828 |
||
1829 |
return this.on.apply(this, a); |
|
1830 |
||
1831 |
},
|
|
1832 |
||
1833 |
/**
|
|
1834 |
* Executes the callback before a DOM event, custom event
|
|
1835 |
* or method. If the first argument is a function, it
|
|
1836 |
* is assumed the target is a method. For DOM and custom
|
|
1837 |
* events, this is an alias for Y.on.
|
|
1838 |
*
|
|
1839 |
* For DOM and custom events:
|
|
1840 |
* type, callback, context, 0-n arguments
|
|
1841 |
*
|
|
1842 |
* For methods:
|
|
1843 |
* callback, object (method host), methodName, context, 0-n arguments
|
|
1844 |
*
|
|
1845 |
* @method before
|
|
1846 |
* @return detach handle
|
|
1847 |
*/
|
|
1848 |
before: function() { |
|
1849 |
return this.on.apply(this, arguments); |
|
1850 |
}
|
|
1851 |
||
1852 |
};
|
|
1853 |
||
1854 |
Y.EventTarget = ET; |
|
1855 |
||
1856 |
// make Y an event target
|
|
1857 |
Y.mix(Y, ET.prototype, false, false, { |
|
1858 |
bubbles: false |
|
1859 |
});
|
|
1860 |
||
1861 |
ET.call(Y); |
|
1862 |
||
1863 |
YUI.Env.globalEvents = YUI.Env.globalEvents || new ET(); |
|
1864 |
||
1865 |
/**
|
|
1866 |
* Hosts YUI page level events. This is where events bubble to
|
|
1867 |
* when the broadcast config is set to 2. This property is
|
|
1868 |
* only available if the custom event module is loaded.
|
|
1869 |
* @property Global
|
|
1870 |
* @type EventTarget
|
|
1871 |
* @for YUI
|
|
1872 |
*/
|
|
1873 |
Y.Global = YUI.Env.globalEvents; |
|
1874 |
||
1875 |
// @TODO implement a global namespace function on Y.Global?
|
|
1876 |
||
1877 |
})();
|
|
1878 |
||
1879 |
/**
|
|
1880 |
* <code>YUI</code>'s <code>on</code> method is a unified interface for subscribing to
|
|
1881 |
* most events exposed by YUI. This includes custom events, DOM events, and
|
|
1882 |
* function events. <code>detach</code> is also provided to remove listeners
|
|
1883 |
* serviced by this function.
|
|
1884 |
*
|
|
1885 |
* The signature that <code>on</code> accepts varies depending on the type
|
|
1886 |
* of event being consumed. Refer to the specific methods that will
|
|
1887 |
* service a specific request for additional information about subscribing
|
|
1888 |
* to that type of event.
|
|
1889 |
*
|
|
1890 |
* <ul>
|
|
1891 |
* <li>Custom events. These events are defined by various
|
|
1892 |
* modules in the library. This type of event is delegated to
|
|
1893 |
* <code>EventTarget</code>'s <code>on</code> method.
|
|
1894 |
* <ul>
|
|
1895 |
* <li>The type of the event</li>
|
|
1896 |
* <li>The callback to execute</li>
|
|
1897 |
* <li>An optional context object</li>
|
|
1898 |
* <li>0..n additional arguments to supply the callback.</li>
|
|
1899 |
* </ul>
|
|
1900 |
* Example:
|
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1901 |
* <code>Y.on('drag:drophit', function() { // start work });</code>
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1902 |
* </li>
|
1903 |
* <li>DOM events. These are moments reported by the browser related
|
|
1904 |
* to browser functionality and user interaction.
|
|
1905 |
* This type of event is delegated to <code>Event</code>'s
|
|
1906 |
* <code>attach</code> method.
|
|
1907 |
* <ul>
|
|
1908 |
* <li>The type of the event</li>
|
|
1909 |
* <li>The callback to execute</li>
|
|
1910 |
* <li>The specification for the Node(s) to attach the listener
|
|
1911 |
* to. This can be a selector, collections, or Node/Element
|
|
1912 |
* refereces.</li>
|
|
1913 |
* <li>An optional context object</li>
|
|
1914 |
* <li>0..n additional arguments to supply the callback.</li>
|
|
1915 |
* </ul>
|
|
1916 |
* Example:
|
|
1917 |
* <code>Y.on('click', function(e) { // something was clicked }, '#someelement');</code>
|
|
1918 |
* </li>
|
|
1919 |
* <li>Function events. These events can be used to react before or after a
|
|
1920 |
* function is executed. This type of event is delegated to <code>Event.Do</code>'s
|
|
1921 |
* <code>before</code> method.
|
|
1922 |
* <ul>
|
|
1923 |
* <li>The callback to execute</li>
|
|
1924 |
* <li>The object that has the function that will be listened for.</li>
|
|
1925 |
* <li>The name of the function to listen for.</li>
|
|
1926 |
* <li>An optional context object</li>
|
|
1927 |
* <li>0..n additional arguments to supply the callback.</li>
|
|
1928 |
* </ul>
|
|
1929 |
* Example <code>Y.on(function(arg1, arg2, etc) { // obj.methodname was executed }, obj 'methodname');</code>
|
|
1930 |
* </li>
|
|
1931 |
* </ul>
|
|
1932 |
*
|
|
1933 |
* <code>on</code> corresponds to the moment before any default behavior of
|
|
1934 |
* the event. <code>after</code> works the same way, but these listeners
|
|
1935 |
* execute after the event's default behavior. <code>before</code> is an
|
|
1936 |
* alias for <code>on</code>.
|
|
1937 |
*
|
|
1938 |
* @method on
|
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1939 |
* @param type event type (this parameter does not apply for function events)
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1940 |
* @param fn the callback
|
1941 |
* @param context optionally change the value of 'this' in the callback
|
|
1942 |
* @param args* 0..n additional arguments to pass to the callback.
|
|
1943 |
* @return the event target or a detach handle per 'chain' config
|
|
1944 |
* @for YUI
|
|
1945 |
*/
|
|
1946 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1947 |
/**
|
1948 |
* Listen for an event one time. Equivalent to <code>on</code>, except that
|
|
1949 |
* the listener is immediately detached when executed.
|
|
1950 |
* @see on
|
|
1951 |
* @method once
|
|
166.19.1
by Paul Hummer
New YUI 3.2 |
1952 |
* @param type event type (this parameter does not apply for function events)
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1953 |
* @param fn the callback
|
1954 |
* @param context optionally change the value of 'this' in the callback
|
|
1955 |
* @param args* 0..n additional arguments to pass to the callback.
|
|
1956 |
* @return the event target or a detach handle per 'chain' config
|
|
1957 |
* @for YUI
|
|
1958 |
*/
|
|
1959 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1960 |
/**
|
1961 |
* after() is a unified interface for subscribing to
|
|
1962 |
* most events exposed by YUI. This includes custom events,
|
|
1963 |
* DOM events, and AOP events. This works the same way as
|
|
1964 |
* the on() function, only it operates after any default
|
|
1965 |
* behavior for the event has executed. @see <code>on</code> for more
|
|
1966 |
* information.
|
|
1967 |
* @method after
|
|
1968 |
* @param type event type (this parameter does not apply for function events)
|
|
1969 |
* @param fn the callback
|
|
1970 |
* @param context optionally change the value of 'this' in the callback
|
|
1971 |
* @param args* 0..n additional arguments to pass to the callback.
|
|
1972 |
* @return the event target or a detach handle per 'chain' config
|
|
1973 |
* @for YUI
|
|
1974 |
*/
|
|
1975 |
||
1976 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
1977 |
}, '3.2.0' ,{requires:['oop']}); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1978 |
YUI.add('event-custom-complex', function(Y) { |
1979 |
||
1980 |
||
1981 |
/**
|
|
1982 |
* Adds event facades, preventable default behavior, and bubbling.
|
|
1983 |
* events.
|
|
1984 |
* @module event-custom
|
|
1985 |
* @submodule event-custom-complex
|
|
1986 |
*/
|
|
1987 |
||
1988 |
(function() { |
|
1989 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
1990 |
var FACADE, FACADE_KEYS, CEProto = Y.CustomEvent.prototype, |
1991 |
ETProto = Y.EventTarget.prototype; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
1992 |
|
1993 |
/**
|
|
1994 |
* Wraps and protects a custom event for use when emitFacade is set to true.
|
|
1995 |
* Requires the event-custom-complex module
|
|
1996 |
* @class EventFacade
|
|
1997 |
* @param e {Event} the custom event
|
|
1998 |
* @param currentTarget {HTMLElement} the element the listener was attached to
|
|
1999 |
*/
|
|
2000 |
||
2001 |
Y.EventFacade = function(e, currentTarget) { |
|
2002 |
||
2003 |
e = e || {}; |
|
2004 |
||
2005 |
/**
|
|
2006 |
* The arguments passed to fire
|
|
2007 |
* @property details
|
|
2008 |
* @type Array
|
|
2009 |
*/
|
|
2010 |
this.details = e.details; |
|
2011 |
||
2012 |
/**
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2013 |
* The event type, this can be overridden by the fire() payload
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2014 |
* @property type
|
2015 |
* @type string
|
|
2016 |
*/
|
|
2017 |
this.type = e.type; |
|
2018 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2019 |
/**
|
2020 |
* The real event type
|
|
2021 |
* @property type
|
|
2022 |
* @type string
|
|
2023 |
*/
|
|
2024 |
this._type = e.type; |
|
2025 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2026 |
//////////////////////////////////////////////////////
|
2027 |
||
2028 |
/**
|
|
2029 |
* Node reference for the targeted eventtarget
|
|
2030 |
* @propery target
|
|
2031 |
* @type Node
|
|
2032 |
*/
|
|
2033 |
this.target = e.target; |
|
2034 |
||
2035 |
/**
|
|
2036 |
* Node reference for the element that the listener was attached to.
|
|
2037 |
* @propery currentTarget
|
|
2038 |
* @type Node
|
|
2039 |
*/
|
|
2040 |
this.currentTarget = currentTarget; |
|
2041 |
||
2042 |
/**
|
|
2043 |
* Node reference to the relatedTarget
|
|
2044 |
* @propery relatedTarget
|
|
2045 |
* @type Node
|
|
2046 |
*/
|
|
2047 |
this.relatedTarget = e.relatedTarget; |
|
2048 |
||
2049 |
/**
|
|
2050 |
* Stops the propagation to the next bubble target
|
|
2051 |
* @method stopPropagation
|
|
2052 |
*/
|
|
2053 |
this.stopPropagation = function() { |
|
2054 |
e.stopPropagation(); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2055 |
this.stopped = 1; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2056 |
};
|
2057 |
||
2058 |
/**
|
|
2059 |
* Stops the propagation to the next bubble target and
|
|
2060 |
* prevents any additional listeners from being exectued
|
|
2061 |
* on the current target.
|
|
2062 |
* @method stopImmediatePropagation
|
|
2063 |
*/
|
|
2064 |
this.stopImmediatePropagation = function() { |
|
2065 |
e.stopImmediatePropagation(); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2066 |
this.stopped = 2; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2067 |
};
|
2068 |
||
2069 |
/**
|
|
2070 |
* Prevents the event's default behavior
|
|
2071 |
* @method preventDefault
|
|
2072 |
*/
|
|
2073 |
this.preventDefault = function() { |
|
2074 |
e.preventDefault(); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2075 |
this.prevented = 1; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2076 |
};
|
2077 |
||
2078 |
/**
|
|
2079 |
* Stops the event propagation and prevents the default
|
|
2080 |
* event behavior.
|
|
2081 |
* @method halt
|
|
2082 |
* @param immediate {boolean} if true additional listeners
|
|
2083 |
* on the current target will not be executed
|
|
2084 |
*/
|
|
2085 |
this.halt = function(immediate) { |
|
2086 |
e.halt(immediate); |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2087 |
this.prevented = 1; |
2088 |
this.stopped = (immediate) ? 2 : 1; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2089 |
};
|
2090 |
||
2091 |
};
|
|
2092 |
||
2093 |
CEProto.fireComplex = function(args) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2094 |
var es = Y.Env._eventstack, ef, q, queue, ce, ret, events, subs, |
2095 |
self = this, host = self.host || self, next, oldbubble; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2096 |
|
2097 |
if (es) { |
|
2098 |
// queue this event if the current item in the queue bubbles
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2099 |
if (self.queuable && self.type != es.next.type) { |
2100 |
self.log('queue ' + self.type); |
|
2101 |
es.queue.push([self, args]); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2102 |
return true; |
2103 |
}
|
|
2104 |
} else { |
|
2105 |
Y.Env._eventstack = { |
|
2106 |
// id of the first event in the stack
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2107 |
id: self.id, |
2108 |
next: self, |
|
2109 |
silent: self.silent, |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2110 |
stopped: 0, |
2111 |
prevented: 0, |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2112 |
bubbling: null, |
2113 |
type: self.type, |
|
2114 |
// defaultFnQueue: new Y.Queue(),
|
|
2115 |
afterQueue: new Y.Queue(), |
|
2116 |
defaultTargetOnly: self.defaultTargetOnly, |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2117 |
queue: [] |
2118 |
};
|
|
2119 |
es = Y.Env._eventstack; |
|
2120 |
}
|
|
2121 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2122 |
subs = self.getSubs(); |
2123 |
||
2124 |
self.stopped = (self.type !== es.type) ? 0 : es.stopped; |
|
2125 |
self.prevented = (self.type !== es.type) ? 0 : es.prevented; |
|
2126 |
||
2127 |
self.target = self.target || host; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2128 |
|
2129 |
events = new Y.EventTarget({ |
|
2130 |
fireOnce: true, |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2131 |
context: host |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2132 |
});
|
2133 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2134 |
self.events = events; |
2135 |
||
2136 |
if (self.preventedFn) { |
|
2137 |
events.on('prevented', self.preventedFn); |
|
2138 |
}
|
|
2139 |
||
2140 |
if (self.stoppedFn) { |
|
2141 |
events.on('stopped', self.stoppedFn); |
|
2142 |
}
|
|
2143 |
||
2144 |
self.currentTarget = host; |
|
2145 |
||
2146 |
self.details = args.slice(); // original arguments in the details |
|
2147 |
||
2148 |
// self.log("Firing " + self + ", " + "args: " + args);
|
|
2149 |
self.log("Firing " + self.type); |
|
2150 |
||
2151 |
self._facade = null; // kill facade to eliminate stale properties |
|
2152 |
||
2153 |
ef = self._getFacade(args); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2154 |
|
2155 |
if (Y.Lang.isObject(args[0])) { |
|
2156 |
args[0] = ef; |
|
2157 |
} else { |
|
2158 |
args.unshift(ef); |
|
2159 |
}
|
|
2160 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2161 |
// if (subCount) {
|
2162 |
if (subs[0]) { |
|
2163 |
// self._procSubs(Y.merge(self.subscribers), args, ef);
|
|
2164 |
self._procSubs(subs[0], args, ef); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2165 |
}
|
2166 |
||
2167 |
// bubble if this is hosted in an event target and propagation has not been stopped
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2168 |
if (self.bubbles && host.bubble && !self.stopped) { |
2169 |
||
2170 |
oldbubble = es.bubbling; |
|
2171 |
||
2172 |
// self.bubbling = true;
|
|
2173 |
es.bubbling = self.type; |
|
2174 |
||
2175 |
// if (host !== ef.target || es.type != self.type) {
|
|
2176 |
if (es.type != self.type) { |
|
2177 |
es.stopped = 0; |
|
2178 |
es.prevented = 0; |
|
2179 |
}
|
|
2180 |
||
2181 |
ret = host.bubble(self); |
|
2182 |
||
2183 |
self.stopped = Math.max(self.stopped, es.stopped); |
|
2184 |
self.prevented = Math.max(self.prevented, es.prevented); |
|
2185 |
||
2186 |
// self.bubbling = false;
|
|
2187 |
es.bubbling = oldbubble; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2188 |
|
2189 |
}
|
|
2190 |
||
2191 |
// execute the default behavior if not prevented
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2192 |
// console.log('defaultTargetOnly: ' + self.defaultTargetOnly);
|
2193 |
// console.log('host === target: ' + (host === ef.target));
|
|
2194 |
// if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly) || host === es.id === self.id)) {
|
|
2195 |
if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly && !es.defaultTargetOnly) || host === ef.target)) { |
|
2196 |
||
2197 |
// if (es.id === self.id) {
|
|
2198 |
// self.defaultFn.apply(host, args);
|
|
2199 |
// while ((next = es.defaultFnQueue.last())) {
|
|
2200 |
// next();
|
|
2201 |
// }
|
|
2202 |
// } else {
|
|
2203 |
// es.defaultFnQueue.add(function() {
|
|
2204 |
// self.defaultFn.apply(host, args);
|
|
2205 |
// });
|
|
2206 |
// }
|
|
2207 |
||
2208 |
self.defaultFn.apply(host, args); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2209 |
}
|
2210 |
||
2211 |
// broadcast listeners are fired as discreet events on the
|
|
2212 |
// YUI instance and potentially the YUI global.
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2213 |
self._broadcast(args); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2214 |
|
2215 |
// process after listeners. If the default behavior was
|
|
2216 |
// prevented, the after events don't fire.
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2217 |
// if (self.afterCount && !self.prevented && self.stopped < 2) {
|
2218 |
||
2219 |
// if (subs[1] && !self.prevented && self.stopped < 2) {
|
|
2220 |
// // self._procSubs(Y.merge(self.afters), args, ef);
|
|
2221 |
// self._procSubs(subs[1], args, ef);
|
|
2222 |
// }
|
|
2223 |
||
2224 |
||
2225 |
// Queue the after
|
|
2226 |
if (subs[1] && !self.prevented && self.stopped < 2) { |
|
2227 |
if (es.id === self.id || self.type != host._yuievt.bubbling) { |
|
2228 |
self._procSubs(subs[1], args, ef); |
|
2229 |
while ((next = es.afterQueue.last())) { |
|
2230 |
next(); |
|
2231 |
}
|
|
2232 |
} else { |
|
2233 |
es.afterQueue.add(function() { |
|
2234 |
self._procSubs(subs[1], args, ef); |
|
2235 |
});
|
|
2236 |
}
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2237 |
}
|
2238 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2239 |
self.target = null; |
2240 |
||
2241 |
// es.stopped = 0;
|
|
2242 |
// es.prevented = 0;
|
|
2243 |
||
2244 |
if (es.id === self.id) { |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2245 |
queue = es.queue; |
2246 |
||
2247 |
while (queue.length) { |
|
2248 |
q = queue.pop(); |
|
2249 |
ce = q[0]; |
|
2250 |
// set up stack to allow the next item to be processed
|
|
2251 |
es.next = ce; |
|
2252 |
ce.fire.apply(ce, q[1]); |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2253 |
// es.stopped = 0;
|
2254 |
// es.prevented = 0;
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2255 |
}
|
2256 |
||
2257 |
Y.Env._eventstack = null; |
|
2258 |
}
|
|
2259 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2260 |
ret = !(self.stopped); |
2261 |
||
2262 |
if (self.type != host._yuievt.bubbling) { |
|
2263 |
es.stopped = 0; |
|
2264 |
es.prevented = 0; |
|
2265 |
self.stopped = 0; |
|
2266 |
self.prevented = 0; |
|
2267 |
}
|
|
2268 |
||
2269 |
return ret; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2270 |
};
|
2271 |
||
2272 |
CEProto._getFacade = function() { |
|
2273 |
||
2274 |
var ef = this._facade, o, o2, |
|
2275 |
args = this.details; |
|
2276 |
||
2277 |
if (!ef) { |
|
2278 |
ef = new Y.EventFacade(this, this.currentTarget); |
|
2279 |
}
|
|
2280 |
||
2281 |
// if the first argument is an object literal, apply the
|
|
2282 |
// properties to the event facade
|
|
2283 |
o = args && args[0]; |
|
2284 |
||
2285 |
if (Y.Lang.isObject(o, true)) { |
|
2286 |
||
2287 |
o2 = {}; |
|
2288 |
||
2289 |
// protect the event facade properties
|
|
2290 |
Y.mix(o2, ef, true, FACADE_KEYS); |
|
2291 |
||
2292 |
// mix the data
|
|
2293 |
Y.mix(ef, o, true); |
|
2294 |
||
2295 |
// restore ef
|
|
2296 |
Y.mix(ef, o2, true, FACADE_KEYS); |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2297 |
|
2298 |
// Allow the event type to be faked
|
|
2299 |
// http://yuilibrary.com/projects/yui3/ticket/2528376
|
|
2300 |
ef.type = o.type || ef.type; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2301 |
}
|
2302 |
||
2303 |
// update the details field with the arguments
|
|
2304 |
// ef.type = this.type;
|
|
2305 |
ef.details = this.details; |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2306 |
|
2307 |
// use the original target when the event bubbled to this target
|
|
2308 |
ef.target = this.originalTarget || this.target; |
|
2309 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2310 |
ef.currentTarget = this.currentTarget; |
2311 |
ef.stopped = 0; |
|
2312 |
ef.prevented = 0; |
|
2313 |
||
2314 |
this._facade = ef; |
|
2315 |
||
2316 |
return this._facade; |
|
2317 |
};
|
|
2318 |
||
2319 |
/**
|
|
2320 |
* Stop propagation to bubble targets
|
|
2321 |
* @for CustomEvent
|
|
2322 |
* @method stopPropagation
|
|
2323 |
*/
|
|
2324 |
CEProto.stopPropagation = function() { |
|
2325 |
this.stopped = 1; |
|
2326 |
Y.Env._eventstack.stopped = 1; |
|
2327 |
this.events.fire('stopped', this); |
|
2328 |
};
|
|
2329 |
||
2330 |
/**
|
|
2331 |
* Stops propagation to bubble targets, and prevents any remaining
|
|
2332 |
* subscribers on the current target from executing.
|
|
2333 |
* @method stopImmediatePropagation
|
|
2334 |
*/
|
|
2335 |
CEProto.stopImmediatePropagation = function() { |
|
2336 |
this.stopped = 2; |
|
2337 |
Y.Env._eventstack.stopped = 2; |
|
2338 |
this.events.fire('stopped', this); |
|
2339 |
};
|
|
2340 |
||
2341 |
/**
|
|
2342 |
* Prevents the execution of this event's defaultFn
|
|
2343 |
* @method preventDefault
|
|
2344 |
*/
|
|
2345 |
CEProto.preventDefault = function() { |
|
2346 |
if (this.preventable) { |
|
2347 |
this.prevented = 1; |
|
2348 |
Y.Env._eventstack.prevented = 1; |
|
2349 |
this.events.fire('prevented', this); |
|
2350 |
}
|
|
2351 |
};
|
|
2352 |
||
2353 |
/**
|
|
2354 |
* Stops the event propagation and prevents the default
|
|
2355 |
* event behavior.
|
|
2356 |
* @method halt
|
|
2357 |
* @param immediate {boolean} if true additional listeners
|
|
2358 |
* on the current target will not be executed
|
|
2359 |
*/
|
|
2360 |
CEProto.halt = function(immediate) { |
|
2361 |
if (immediate) { |
|
2362 |
this.stopImmediatePropagation(); |
|
2363 |
} else { |
|
2364 |
this.stopPropagation(); |
|
2365 |
}
|
|
2366 |
this.preventDefault(); |
|
2367 |
};
|
|
2368 |
||
2369 |
/**
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2370 |
* Registers another EventTarget as a bubble target. Bubble order
|
2371 |
* is determined by the order registered. Multiple targets can
|
|
2372 |
* be specified.
|
|
2373 |
*
|
|
2374 |
* Events can only bubble if emitFacade is true.
|
|
2375 |
*
|
|
2376 |
* Included in the event-custom-complex submodule.
|
|
2377 |
*
|
|
2378 |
* @method addTarget
|
|
2379 |
* @param o {EventTarget} the target to add
|
|
2380 |
* @for EventTarget
|
|
2381 |
*/
|
|
2382 |
ETProto.addTarget = function(o) { |
|
2383 |
this._yuievt.targets[Y.stamp(o)] = o; |
|
2384 |
this._yuievt.hasTargets = true; |
|
2385 |
};
|
|
2386 |
||
2387 |
/**
|
|
2388 |
* Returns an array of bubble targets for this object.
|
|
2389 |
* @method getTargets
|
|
2390 |
* @return EventTarget[]
|
|
2391 |
*/
|
|
2392 |
ETProto.getTargets = function() { |
|
2393 |
return Y.Object.values(this._yuievt.targets); |
|
2394 |
};
|
|
2395 |
||
2396 |
/**
|
|
2397 |
* Removes a bubble target
|
|
2398 |
* @method removeTarget
|
|
2399 |
* @param o {EventTarget} the target to remove
|
|
2400 |
* @for EventTarget
|
|
2401 |
*/
|
|
2402 |
ETProto.removeTarget = function(o) { |
|
2403 |
delete this._yuievt.targets[Y.stamp(o)]; |
|
2404 |
};
|
|
2405 |
||
2406 |
/**
|
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2407 |
* Propagate an event. Requires the event-custom-complex module.
|
2408 |
* @method bubble
|
|
2409 |
* @param evt {Event.Custom} the custom event to propagate
|
|
2410 |
* @return {boolean} the aggregated return value from Event.Custom.fire
|
|
2411 |
* @for EventTarget
|
|
2412 |
*/
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2413 |
ETProto.bubble = function(evt, args, target) { |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2414 |
|
2415 |
var targs = this._yuievt.targets, ret = true, |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2416 |
t, type = evt && evt.type, ce, i, bc, ce2, |
2417 |
originalTarget = target || (evt && evt.target) || this, |
|
2418 |
es = Y.Env._eventstack, oldbubble; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2419 |
|
2420 |
if (!evt || ((!evt.stopped) && targs)) { |
|
2421 |
||
2422 |
// Y.log('Bubbling ' + evt.type);
|
|
2423 |
for (i in targs) { |
|
2424 |
if (targs.hasOwnProperty(i)) { |
|
2425 |
t = targs[i]; |
|
2426 |
ce = t.getEvent(type, true); |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2427 |
ce2 = t.getSibling(type, ce); |
2428 |
||
2429 |
if (ce2 && !ce) { |
|
2430 |
ce = t.publish(type); |
|
2431 |
}
|
|
2432 |
||
2433 |
oldbubble = t._yuievt.bubbling; |
|
2434 |
t._yuievt.bubbling = type; |
|
2435 |
||
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2436 |
// if this event was not published on the bubble target,
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2437 |
// continue propagating the event.
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2438 |
if (!ce) { |
2439 |
if (t._yuievt.hasTargets) { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2440 |
t.bubble(evt, args, originalTarget); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2441 |
}
|
2442 |
} else { |
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2443 |
|
2444 |
ce.sibling = ce2; |
|
2445 |
||
2446 |
// set the original target to that the target payload on the
|
|
2447 |
// facade is correct.
|
|
2448 |
ce.target = originalTarget; |
|
2449 |
ce.originalTarget = originalTarget; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2450 |
ce.currentTarget = t; |
2451 |
bc = ce.broadcast; |
|
2452 |
ce.broadcast = false; |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2453 |
|
2454 |
// default publish may not have emitFacade true -- that
|
|
2455 |
// shouldn't be what the implementer meant to do
|
|
2456 |
ce.emitFacade = true; |
|
2457 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2458 |
ret = ret && ce.fire.apply(ce, args || evt.details || []); |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2459 |
ce.broadcast = bc; |
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2460 |
ce.originalTarget = null; |
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2461 |
|
166.19.1
by Paul Hummer
New YUI 3.2 |
2462 |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2463 |
// stopPropagation() was called
|
2464 |
if (ce.stopped) { |
|
2465 |
break; |
|
2466 |
}
|
|
2467 |
}
|
|
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2468 |
|
2469 |
t._yuievt.bubbling = oldbubble; |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2470 |
}
|
2471 |
}
|
|
2472 |
}
|
|
2473 |
||
2474 |
return ret; |
|
2475 |
};
|
|
2476 |
||
2477 |
FACADE = new Y.EventFacade(); |
|
2478 |
FACADE_KEYS = Y.Object.keys(FACADE); |
|
2479 |
||
166.8.4
by Sidnei da Silva
- Add yui 3.1.0 in place of 3.0.0 |
2480 |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2481 |
})();
|
2482 |
||
2483 |
||
166.19.1
by Paul Hummer
New YUI 3.2 |
2484 |
}, '3.2.0' ,{requires:['event-custom-base']}); |
2485 |
||
2486 |
||
2487 |
YUI.add('event-custom', function(Y){}, '3.2.0' ,{use:['event-custom-base', 'event-custom-complex']}); |
|
120.2.4
by Sidnei da Silva
- Merge from jstestdriver-support and pull in yui 3.0.0 |
2488 |