event-custom-complex.js revision bd03a79f6dc612d2940a331a52ee4cf0f364b1ba
fa9e4066f08beec538e775443c5be79dd423fcabahrensYUI.add('event-custom-complex', function(Y) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
0f2dc02ed2763dadc70bec1db8dd407e16db8e49ek * Adds event facades, preventable default behavior, and bubbling.
0f2dc02ed2763dadc70bec1db8dd407e16db8e49ek * events.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @module event-custom
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @submodule event-custom-complex
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens(function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvar FACADE, FACADE_KEYS, CEProto = Y.CustomEvent.prototype,
fa9e4066f08beec538e775443c5be79dd423fcabahrens ETProto = Y.EventTarget.prototype;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Wraps and protects a custom event for use when emitFacade is set to true.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Requires the event-custom-complex module
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @class EventFacade
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param e {Event} the custom event
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param currentTarget {HTMLElement} the element the listener was attached to
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum */
9adfa60d484ce2435f5af77cc99dcd4e692b6660Matthew Ahrens
0f92170f1ec2737ee5a0e51b5f74093904811452Dan McDonaldY.EventFacade = function(e, currentTarget) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens e = e || {};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The arguments passed to fire
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @property details
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @type Array
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.details = e.details;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The event type, this can be overridden by the fire() payload
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @property type
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @type string
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.type = e.type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The real event type
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @property type
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @type string
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this._type = e.type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens //////////////////////////////////////////////////////
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Node reference for the targeted eventtarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @propery target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @type Node
f18faf3f3e5def85fdfff681617d227703ace2adek */
f18faf3f3e5def85fdfff681617d227703ace2adek this.target = e.target;
f18faf3f3e5def85fdfff681617d227703ace2adek
f18faf3f3e5def85fdfff681617d227703ace2adek /**
f18faf3f3e5def85fdfff681617d227703ace2adek * Node reference for the element that the listener was attached to.
f18faf3f3e5def85fdfff681617d227703ace2adek * @propery currentTarget
f18faf3f3e5def85fdfff681617d227703ace2adek * @type Node
f18faf3f3e5def85fdfff681617d227703ace2adek */
f18faf3f3e5def85fdfff681617d227703ace2adek this.currentTarget = currentTarget;
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Node reference to the relatedTarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @propery relatedTarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @type Node
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.relatedTarget = e.relatedTarget;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stops the propagation to the next bubble target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method stopPropagation
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens this.stopPropagation = function() {
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks e.stopPropagation();
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.stopped = 1;
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timh };
fa9e4066f08beec538e775443c5be79dd423fcabahrens
6d1e0b89f3e34478a022854df6b0cfab82ccce66marks /**
6d1e0b89f3e34478a022854df6b0cfab82ccce66marks * Stops the propagation to the next bubble target and
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck * prevents any additional listeners from being exectued
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck * on the current target.
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck * @method stopImmediatePropagation
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck */
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck this.stopImmediatePropagation = function() {
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck e.stopImmediatePropagation();
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck this.stopped = 2;
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck };
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck /**
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck * Prevents the event's default behavior
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck * @method preventDefault
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.preventDefault = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens e.preventDefault();
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.prevented = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens };
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stops the event propagation and prevents the default
fa9e4066f08beec538e775443c5be79dd423fcabahrens * event behavior.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method halt
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param immediate {boolean} if true additional listeners
fa9e4066f08beec538e775443c5be79dd423fcabahrens * on the current target will not be executed
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.halt = function(immediate) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens e.halt(immediate);
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.prevented = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.stopped = (immediate) ? 2 : 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens };
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensCEProto.fireComplex = function(args) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens var es = Y.Env._eventstack, ef, q, queue, ce, ret, events, subs,
fa9e4066f08beec538e775443c5be79dd423fcabahrens self = this, host = self.host || self, next, oldbubble;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright if (es) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // queue this event if the current item in the queue bubbles
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (self.queuable && self.type != es.next.type) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.log('queue ' + self.type);
fa9e4066f08beec538e775443c5be79dd423fcabahrens es.queue.push([self, args]);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright return true;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright Y.Env._eventstack = {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // id of the first event in the stack
8bf40bf00a7564d0ccb4a33906734188cb2d1e9bck id: self.id,
fa9e4066f08beec538e775443c5be79dd423fcabahrens next: self,
fa9e4066f08beec538e775443c5be79dd423fcabahrens silent: self.silent,
fa9e4066f08beec538e775443c5be79dd423fcabahrens stopped: 0,
fa9e4066f08beec538e775443c5be79dd423fcabahrens prevented: 0,
fa9e4066f08beec538e775443c5be79dd423fcabahrens bubbling: null,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright type: self.type,
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright // defaultFnQueue: new Y.Queue(),
fa9e4066f08beec538e775443c5be79dd423fcabahrens afterQueue: new Y.Queue(),
fa9e4066f08beec538e775443c5be79dd423fcabahrens defaultTargetOnly: self.defaultTargetOnly,
fa9e4066f08beec538e775443c5be79dd423fcabahrens queue: []
fa9e4066f08beec538e775443c5be79dd423fcabahrens };
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright es = Y.Env._eventstack;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens subs = self.getSubs();
fa9e4066f08beec538e775443c5be79dd423fcabahrens
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright self.stopped = (self.type !== es.type) ? 0 : es.stopped;
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.prevented = (self.type !== es.type) ? 0 : es.prevented;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.target = self.target || host;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens events = new Y.EventTarget({
fa9e4066f08beec538e775443c5be79dd423fcabahrens fireOnce: true,
fa9e4066f08beec538e775443c5be79dd423fcabahrens context: host
fa9e4066f08beec538e775443c5be79dd423fcabahrens });
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.events = events;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (self.preventedFn) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens events.on('prevented', self.preventedFn);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (self.stoppedFn) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens events.on('stopped', self.stoppedFn);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.currentTarget = host;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.details = args.slice(); // original arguments in the details
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // self.log("Firing " + self + ", " + "args: " + args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.log("Firing " + self.type);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self._facade = null; // kill facade to eliminate stale properties
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef = self._getFacade(args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (Y.Lang.isObject(args[0])) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright args[0] = ef;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright } else {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright args.unshift(ef);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // if (subCount) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (subs[0]) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // self._procSubs(Y.merge(self.subscribers), args, ef);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright self._procSubs(subs[0], args, ef);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // bubble if this is hosted in an event target and propagation has not been stopped
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum if (self.bubbles && host.bubble && !self.stopped) {
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum oldbubble = es.bubbling;
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum // self.bubbling = true;
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum es.bubbling = self.type;
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum // if (host !== ef.target || es.type != self.type) {
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum if (es.type != self.type) {
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum es.stopped = 0;
d39ee142a97a7c58f60f7b52c62409f2ff64b234Mark Shellenbaum es.prevented = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright ret = host.bubble(self);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.stopped = Math.max(self.stopped, es.stopped);
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.prevented = Math.max(self.prevented, es.prevented);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // self.bubbling = false;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright es.bubbling = oldbubble;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright }
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright // execute the default behavior if not prevented
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright // console.log('defaultTargetOnly: ' + self.defaultTargetOnly);
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright // console.log('host === target: ' + (host === ef.target));
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright // if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly) || host === es.id === self.id)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (self.defaultFn && !self.prevented && ((!self.defaultTargetOnly && !es.defaultTargetOnly) || host === ef.target)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // if (es.id === self.id) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // self.defaultFn.apply(host, args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens // while ((next = es.defaultFnQueue.last())) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // next();
fa9e4066f08beec538e775443c5be79dd423fcabahrens // }
fa9e4066f08beec538e775443c5be79dd423fcabahrens // } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // es.defaultFnQueue.add(function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens // self.defaultFn.apply(host, args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens // });
a32fded1a905061abae92da5bcbab429cb6146f1ek // }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum self.defaultFn.apply(host, args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // broadcast listeners are fired as discreet events on the
fa9e4066f08beec538e775443c5be79dd423fcabahrens // YUI instance and potentially the YUI global.
fa9e4066f08beec538e775443c5be79dd423fcabahrens self._broadcast(args);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // process after listeners. If the default behavior was
fa9e4066f08beec538e775443c5be79dd423fcabahrens // prevented, the after events don't fire.
fa9e4066f08beec538e775443c5be79dd423fcabahrens // if (self.afterCount && !self.prevented && self.stopped < 2) {
a32fded1a905061abae92da5bcbab429cb6146f1ek
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum // if (subs[1] && !self.prevented && self.stopped < 2) {
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum // // self._procSubs(Y.merge(self.afters), args, ef);
0a586cea3ceec7e5e50e7e54c745082a7a333ac2Mark Shellenbaum // self._procSubs(subs[1], args, ef);
a32fded1a905061abae92da5bcbab429cb6146f1ek // }
a32fded1a905061abae92da5bcbab429cb6146f1ek
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // Queue the after
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (subs[1] && !self.prevented && self.stopped < 2) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (es.id === self.id || self.type != host._yuievt.bubbling) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens self._procSubs(subs[1], args, ef);
fa9e4066f08beec538e775443c5be79dd423fcabahrens while ((next = es.afterQueue.last())) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens next();
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens es.afterQueue.add(function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens self._procSubs(subs[1], args, ef);
8afd4dd66b1dd487290f73b2f35040343a3cb821perrin });
8afd4dd66b1dd487290f73b2f35040343a3cb821perrin }
8afd4dd66b1dd487290f73b2f35040343a3cb821perrin }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.target = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // es.stopped = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens // es.prevented = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (es.id === self.id) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens queue = es.queue;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (queue.length) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens q = queue.pop();
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce = q[0];
fa9e4066f08beec538e775443c5be79dd423fcabahrens // set up stack to allow the next item to be processed
fa9e4066f08beec538e775443c5be79dd423fcabahrens es.next = ce;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce.fire.apply(ce, q[1]);
fa9e4066f08beec538e775443c5be79dd423fcabahrens // es.stopped = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens // es.prevented = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens Y.Env._eventstack = null;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens ret = !(self.stopped);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (self.type != host._yuievt.bubbling) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw es.stopped = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens es.prevented = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens self.stopped = 0;
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens self.prevented = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return ret;
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensCEProto._getFacade = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens var ef = this._facade, o, o2,
fa9e4066f08beec538e775443c5be79dd423fcabahrens args = this.details;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!ef) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef = new Y.EventFacade(this, this.currentTarget);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // if the first argument is an object literal, apply the
fa9e4066f08beec538e775443c5be79dd423fcabahrens // properties to the event facade
fa9e4066f08beec538e775443c5be79dd423fcabahrens o = args && args[0];
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (Y.Lang.isObject(o, true)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw o2 = {};
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
fa9e4066f08beec538e775443c5be79dd423fcabahrens // protect the event facade properties
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum Y.mix(o2, ef, true, FACADE_KEYS);
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens // mix the data
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum Y.mix(ef, o, true);
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens // restore ef
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum Y.mix(ef, o2, true, FACADE_KEYS);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // Allow the event type to be faked
fa9e4066f08beec538e775443c5be79dd423fcabahrens // http://yuilibrary.com/projects/yui3/ticket/2528376
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.type = o.type || ef.type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // update the details field with the arguments
fa9e4066f08beec538e775443c5be79dd423fcabahrens // ef.type = this.type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.details = this.details;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
a32fded1a905061abae92da5bcbab429cb6146f1ek // use the original target when the event bubbled to this target
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.target = this.originalTarget || this.target;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.currentTarget = this.currentTarget;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.stopped = 0;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ef.prevented = 0;
71eb05381846ad14a2087631474e832d0f316654Chris Kirby
fa9e4066f08beec538e775443c5be79dd423fcabahrens this._facade = ef;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return this._facade;
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stop propagation to bubble targets
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @for CustomEvent
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method stopPropagation
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
a32fded1a905061abae92da5bcbab429cb6146f1ekCEProto.stopPropagation = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.stopped = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens Y.Env._eventstack.stopped = 1;
a32fded1a905061abae92da5bcbab429cb6146f1ek this.events.fire('stopped', this);
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stops propagation to bubble targets, and prevents any remaining
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * subscribers on the current target from executing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method stopImmediatePropagation
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensCEProto.stopImmediatePropagation = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.stopped = 2;
fa9e4066f08beec538e775443c5be79dd423fcabahrens Y.Env._eventstack.stopped = 2;
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.events.fire('stopped', this);
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Prevents the execution of this event's defaultFn
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method preventDefault
0f2dc02ed2763dadc70bec1db8dd407e16db8e49ek */
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew AhrensCEProto.preventDefault = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (this.preventable) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.prevented = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens Y.Env._eventstack.prevented = 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.events.fire('prevented', this);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Stops the event propagation and prevents the default
fa9e4066f08beec538e775443c5be79dd423fcabahrens * event behavior.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method halt
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param immediate {boolean} if true additional listeners
fa9e4066f08beec538e775443c5be79dd423fcabahrens * on the current target will not be executed
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensCEProto.halt = function(immediate) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (immediate) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens this.stopImmediatePropagation();
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright } else {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright this.stopPropagation();
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright }
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright this.preventDefault();
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright};
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright/**
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * Registers another EventTarget as a bubble target. Bubble order
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * is determined by the order registered. Multiple targets can
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * be specified.
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum *
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum * Events can only bubble if emitFacade is true.
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum *
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens * Included in the event-custom-complex submodule.
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum *
9e1320c015cea6985d2122bc1d654b79fa479f7aMark Shellenbaum * @method addTarget
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * @param o {EventTarget} the target to add
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright * @for EventTarget
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright */
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan WrightETProto.addTarget = function(o) {
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright this._yuievt.targets[Y.stamp(o)] = o;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright this._yuievt.hasTargets = true;
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright};
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wright
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Returns an array of bubble targets for this object.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method getTargets
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @return EventTarget[]
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensETProto.getTargets = function() {
fa9e4066f08beec538e775443c5be79dd423fcabahrens return Y.Object.values(this._yuievt.targets);
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/**
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Removes a bubble target
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method removeTarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param o {EventTarget} the target to remove
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @for EventTarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensETProto.removeTarget = function(o) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens delete this._yuievt.targets[Y.stamp(o)];
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/**
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Propagate an event. Requires the event-custom-complex module.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @method bubble
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @param evt {Event.Custom} the custom event to propagate
71eb05381846ad14a2087631474e832d0f316654Chris Kirby * @return {boolean} the aggregated return value from Event.Custom.fire
fa9e4066f08beec538e775443c5be79dd423fcabahrens * @for EventTarget
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensETProto.bubble = function(evt, args, target) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
71eb05381846ad14a2087631474e832d0f316654Chris Kirby var targs = this._yuievt.targets, ret = true,
fa9e4066f08beec538e775443c5be79dd423fcabahrens t, type = evt && evt.type, ce, i, bc, ce2,
fa9e4066f08beec538e775443c5be79dd423fcabahrens originalTarget = target || (evt && evt.target) || this,
fa9e4066f08beec538e775443c5be79dd423fcabahrens es = Y.Env._eventstack, oldbubble;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!evt || ((!evt.stopped) && targs)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens for (i in targs) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (targs.hasOwnProperty(i)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens t = targs[i];
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce = t.getEvent(type, true);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce2 = t.getSibling(type, ce);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ce2 && !ce) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ce = t.publish(type)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens oldbubble = t._yuievt.bubbling;
fa9e4066f08beec538e775443c5be79dd423fcabahrens t._yuievt.bubbling = type;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // if this event was not published on the bubble target,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw // continue propagating the event.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!ce) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (t._yuievt.hasTargets) {
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens t.bubble(evt, args, originalTarget);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
fa9e4066f08beec538e775443c5be79dd423fcabahrens } else {
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce.sibling = ce2;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // set the original target to that the target payload on the
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timh // facade is correct.
ab04eb8ef60d9dc9614d6cccffc474f24ca1d162timh ce.target = originalTarget;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce.originalTarget = originalTarget;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce.currentTarget = t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens bc = ce.broadcast;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ce.broadcast = false;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens // default publish may not have emitFacade true -- that
fa9e4066f08beec538e775443c5be79dd423fcabahrens // shouldn't be what the implementer meant to do
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum ce.emitFacade = true;
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum ret = ret && ce.fire.apply(ce, args || evt.details || []);
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum ce.broadcast = bc;
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum ce.originalTarget = null;
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum // stopPropagation() was called
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum if (ce.stopped) {
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum break;
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum }
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum }
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum t._yuievt.bubbling = oldbubble;
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum }
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum }
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb return ret;
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb};
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsbFACADE = new Y.EventFacade();
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsbFACADE_KEYS = Y.Object.keys(FACADE);
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb})();
60030f278c9b10a64cb18b6443f7e8d97d6e45e4Mark Shellenbaum
aa59c4cb15a6ac5d4e585dadf7a055b580abf579rsb
fa9e4066f08beec538e775443c5be79dd423fcabahrens}, '@VERSION@' ,{requires:['event-custom-base']});
fa9e4066f08beec538e775443c5be79dd423fcabahrens