event-facade.js revision e281a15571f07a6b4da34d2ffd674dbeb5dfd612
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Adds event facades, preventable default behavior, and bubbling.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @module event-custom
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @submodule event-custom-complex
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Wraps and protects a custom event for use when emitFacade is set to true.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Requires the event-custom-complex module
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @class EventFacade
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param e {Event} the custom event
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param currentTarget {HTMLElement} the element the listener was attached to
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The arguments passed to fire
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property details
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Array
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The event type, this can be overridden by the fire() payload
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property type
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type string
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The real event type
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @property type
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type string
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp //////////////////////////////////////////////////////
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Node reference for the targeted eventtarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @propery target
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Node reference for the element that the listener was attached to.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @propery currentTarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Node reference to the relatedTarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @propery relatedTarget
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @type Node
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Stops the propagation to the next bubble target
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method stopPropagation
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp stopPropagation: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Stops the propagation to the next bubble target and
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * prevents any additional listeners from being exectued
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * on the current target.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method stopImmediatePropagation
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Prevents the event's default behavior
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method preventDefault
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp preventDefault: function() {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Stops the event propagation and prevents the default
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * event behavior.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method halt
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param immediate {boolean} if true additional listeners
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * on the current target will not be executed
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var es, ef, q, queue, ce, ret, events, subs, postponed,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self = this, host = self.host || self, next, oldbubble;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // queue this event if the current item in the queue bubbles
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (self.queuable && self.type != self.stack.next.type) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // id of the first event in the stack
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // defaultFnQueue: new Y.Queue(),
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self.stopped = (self.type !== es.type) ? 0 : es.stopped;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self.prevented = (self.type !== es.type) ? 0 : es.prevented;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self.details = args.slice(); // original arguments in the details
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // self.log("Firing " + self + ", " + "args: " + args);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self._facade = null; // kill facade to eliminate stale properties
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // if (subCount) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // self._procSubs(Y.merge(self.subscribers), args, ef);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // bubble if this is hosted in an event target and propagation has not been stopped
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // self.bubbling = true;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // if (host !== ef.target || es.type != self.type) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp self.prevented = Math.max(self.prevented, es.prevented);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // self.bubbling = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp ((!self.defaultTargetOnly && !es.defaultTargetOnly) ||
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // broadcast listeners are fired as discreet events on the
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // YUI instance and potentially the YUI global.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // Queue the after
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (es.id === self.id || self.type != host._yuievt.bubbling) {
return ret;
if (!ef) {
o2 = {};
return this._facade;
if (this.stack) {
if (this.stack) {
if (this.preventable) {
if (this.stack) {
if (immediate) {
this.stopImmediatePropagation();
this.stopPropagation();
this.preventDefault();
for (i in targs) {
t = targs[i];
if (!ce) {
return ret;