event-facade.js revision f5272da05b11f2b116e4bd62353472a187367714
/**
* 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
next: this,
stopped: 0,
prevented: 0,
queue: []
};
}
events = new Y.EventTarget({
fireOnce: true,
});
if (this.preventedFn) {
}
if (this.stoppedFn) {
}
this.currentTarget = host;
// this.log("Firing " + this + ", " + "args: " + args);
this._facade = null; // kill facade to eliminate stale properties
} else {
}
// if (subCount) {
if (subs[0]) {
// this._procSubs(Y.merge(this.subscribers), args, ef);
}
// bubble if this is hosted in an event target and propagation has not been stopped
// this.bubbling = true;
// if (host !== ef.target || es.type != this.type) {
}
// this.bubbling = false;
}
// execute the default behavior if not prevented
// console.log('defaultTargetOnly: ' + this.defaultTargetOnly);
// console.log('host === target: ' + (host === ef.target));
}
// broadcast listeners are fired as discreet events on the
// YUI instance and potentially the YUI global.
this._broadcast(args);
// process after listeners. If the default behavior was
// prevented, the after events don't fire.
// if (this.afterCount && !this.prevented && this.stopped < 2) {
// this._procSubs(Y.merge(this.afters), args, ef);
}
// 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;
}
this.stopped = 0;
this.prevented = 0;
}
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
*/
// Y.log('Bubbling ' + evt.type);
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();
})();