event-custom-complex.js revision 489bce3559e4350381baae866c6d3d9fd89985ca
/**
* Adds event facades, preventable default behavior, and bubbling.
* events.
* @module event-custom
* @submodule event-custom-complex
*/
(function() {
/**
* Wraps and protects a custom event for use when emitFacade is set to true.
* Requires the event-custom-complex module
* @class EventFacade
* @param e {Event} the custom event
* @param currentTarget {HTMLElement} the element the listener was attached to
*/
Y.EventFacade = function(e, currentTarget) {
e = e || {};
/**
* The arguments passed to fire
* @property details
* @type Array
*/
/**
* The event type, this can be overridden by the fire() payload
* @property type
* @type string
*/
/**
* The real event type
* @property type
* @type string
*/
//////////////////////////////////////////////////////
/**
* Node reference for the targeted eventtarget
* @propery target
* @type Node
*/
/**
* Node reference for the element that the listener was attached to.
* @propery currentTarget
* @type Node
*/
this.currentTarget = currentTarget;
/**
* Node reference to the relatedTarget
* @propery relatedTarget
* @type Node
*/
this.relatedTarget = e.relatedTarget;
/**
* Stops the propagation to the next bubble target
* @method stopPropagation
*/
this.stopPropagation = function() {
e.stopPropagation();
};
/**
* Stops the propagation to the next bubble target and
* prevents any additional listeners from being exectued
* on the current target.
* @method stopImmediatePropagation
*/
this.stopImmediatePropagation = function() {
};
/**
* Prevents the event's default behavior
* @method preventDefault
*/
this.preventDefault = function() {
e.preventDefault();
};
/**
* Stops the event propagation and prevents the default
* event behavior.
* @method halt
* @param immediate {boolean} if true additional listeners
* on the current target will not be executed
*/
};
};
if (es) {
// queue this event if the current item in the queue bubbles
return true;
}
} else {
Y.Env._eventstack = {
// id of the first event in the stack
stopped: 0,
prevented: 0,
// defaultFnQueue: new Y.Queue(),
afterQueue: new Y.Queue(),
queue: []
};
}
events = new Y.EventTarget({
fireOnce: true,
});
if (self.preventedFn) {
}
}
// self.log("Firing " + self + ", " + "args: " + args);
} else {
}
// if (subCount) {
if (subs[0]) {
// self._procSubs(Y.merge(self.subscribers), args, ef);
}
// bubble if this is hosted in an event target and propagation has not been stopped
// self.bubbling = true;
// if (host !== ef.target || es.type != self.type) {
}
// self.bubbling = false;
}
// execute the default behavior if not prevented
// console.log('defaultTargetOnly: ' + self.defaultTargetOnly);
// console.log('host === target: ' + (host === ef.target));
// if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly) || host === es.id === self.id)) {
if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly && !es.defaultTargetOnly) || host === ef.target)) {
// if (es.id === self.id) {
// self.defaultFn.apply(host, args);
// while ((next = es.defaultFnQueue.last())) {
// next();
// }
// } else {
// es.defaultFnQueue.add(function() {
// self.defaultFn.apply(host, args);
// });
// }
}
// broadcast listeners are fired as discreet events on the
// YUI instance and potentially the YUI global.
// process after listeners. If the default behavior was
// prevented, the after events don't fire.
// if (self.afterCount && !self.prevented && self.stopped < 2) {
// if (subs[1] && !self.prevented && self.stopped < 2) {
// // self._procSubs(Y.merge(self.afters), args, ef);
// self._procSubs(subs[1], args, ef);
// }
// Queue the after
next();
}
} else {
});
}
}
// es.stopped = 0;
// es.prevented = 0;
ce = q[0];
// set up stack to allow the next item to be processed
// es.stopped = 0;
// es.prevented = 0;
}
Y.Env._eventstack = null;
}
}
return ret;
};
CEProto._getFacade = function() {
if (!ef) {
}
// if the first argument is an object literal, apply the
// properties to the event facade
o2 = {};
// protect the event facade properties
// mix the data
// restore ef
// Allow the event type to be faked
}
// update the details field with the arguments
// ef.type = this.type;
// use the original target when the event bubbled to this target
return this._facade;
};
/**
* Stop propagation to bubble targets
* @for CustomEvent
* @method stopPropagation
*/
CEProto.stopPropagation = function() {
this.stopped = 1;
};
/**
* Stops propagation to bubble targets, and prevents any remaining
* subscribers on the current target from executing.
* @method stopImmediatePropagation
*/
CEProto.stopImmediatePropagation = function() {
this.stopped = 2;
};
/**
* Prevents the execution of this event's defaultFn
* @method preventDefault
*/
CEProto.preventDefault = function() {
if (this.preventable) {
this.prevented = 1;
}
};
/**
* Stops the event propagation and prevents the default
* event behavior.
* @method halt
* @param immediate {boolean} if true additional listeners
* on the current target will not be executed
*/
if (immediate) {
this.stopImmediatePropagation();
} else {
this.stopPropagation();
}
this.preventDefault();
};
/**
* Registers another EventTarget as a bubble target. Bubble order
* is determined by the order registered. Multiple targets can
* be specified.
*
* Events can only bubble if emitFacade is true.
*
* Included in the event-custom-complex submodule.
*
* @method addTarget
* @param o {EventTarget} the target to add
* @for EventTarget
*/
this._yuievt.hasTargets = true;
};
/**
* Removes a bubble target
* @method removeTarget
* @param o {EventTarget} the target to remove
* @for EventTarget
*/
ETProto.removeTarget = function(o) {
};
/**
* Propagate an event. Requires the event-custom-complex module.
* @method bubble
* @param evt {Event.Custom} the custom event to propagate
* @return {boolean} the aggregated return value from Event.Custom.fire
* @for EventTarget
*/
for (i in targs) {
if (targs.hasOwnProperty(i)) {
t = targs[i];
}
// if this event was not published on the bubble target,
// continue propagating the event.
if (!ce) {
if (t._yuievt.hasTargets) {
}
} else {
// set the original target to that the target payload on the
// facade is correct.
ce.currentTarget = t;
ce.originalTarget = null;
// stopPropagation() was called
break;
}
}
}
}
}
return ret;
};
FACADE = new Y.EventFacade();
})();