da7cf0982c42a7fff5edfae159358418fe4ed2acLuke Smith * Define new DOM events that can be subscribed to from Nodes.
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @module event
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @submodule event-synthetic
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith noop = function () {};
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * <p>The triggering mechanism used by SyntheticEvents.</p>
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * <p>Implementers should not instantiate these directly. Use the Notifier
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * provided to the event's implemented <code>on(node, sub, notifier)</code> or
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * <code>delegate(node, sub, notifier, filter)</code> methods.</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @class SyntheticEvent.Notifier
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @constructor
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @param handle {EventHandle} the detach handle for the subscription to an
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * internal custom event used to execute the callback passed to
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * on(..) or delegate(..)
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @param emitFacade {Boolean} take steps to ensure the first arg received by
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * the subscription callback is an event facade
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * @since 3.2.0
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * <p>Executes the subscription callback, passing the firing arguments as the
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * first parameters to that callback. For events that are configured with
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * emitFacade=true, it is common practice to pass the triggering DOMEventFacade
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * as the first parameter. Barring a proper DOMEventFacade or EventFacade
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * (from a CustomEvent), a new EventFacade will be generated. In that case, if
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * fire() is called with a simple object, it will be mixed into the facade.
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * Otherwise, the facade will be prepended to the callback parameters.</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * <p>For notifiers provided to delegate logic, the first argument should be an
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * object with a "currentTarget" property to identify what object to
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * default as 'this' in the callback. Typically this is gleaned from the
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * DOMEventFacade or EventFacade, but if configured with emitFacade=false, an
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * object must be provided. In that case, the object will be removed from the
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * callback parameters.</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * <p>Additional arguments passed during event subscription will be
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * automatically added after those passed to fire().</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @method fire
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @param e {EventFacade|DOMEventFacade|Object|any} (see description)
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @param arg* {any} additional arguments received by all subscriptions
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith // first arg to delegate notifier should be an object with currentTarget
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith if (!e || !e.preventDefault) {
63d012ee193ba8c768b2a2aade99081422759213Luke Smith } else if (delegate && isObject(e) && e.currentTarget) {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith sub.context = thisObj || event.currentTarget || ce.host;
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith sub.context = thisObj; // reset for future firing