da7cf0982c42a7fff5edfae159358418fe4ed2acLuke Smith/**
da7cf0982c42a7fff5edfae159358418fe4ed2acLuke Smith * Define new DOM events that can be subscribed to from Nodes.
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith *
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @module event
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * @submodule event-synthetic
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith */
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smithvar DOMMap = Y.Env.evt.dom_map,
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith toArray = Y.Array,
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith YLang = Y.Lang,
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith isObject = YLang.isObject,
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith isString = YLang.isString,
0e49d19b4de1c15ca77237aeba82108157749594Luke Smith isArray = YLang.isArray,
6e3e84bf311b9444aa6ca40cc62bfd9be74708e3Luke Smith query = Y.Selector.query,
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith noop = function () {};
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith/**
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * <p>The triggering mechanism used by SyntheticEvents.</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith *
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 *
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 * @private
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * @since 3.2.0
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith */
63d012ee193ba8c768b2a2aade99081422759213Luke Smithfunction Notifier(handle, emitFacade) {
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith this.handle = handle;
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith this.emitFacade = emitFacade;
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith}
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith/**
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 *
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * <p>For notifiers provided to delegate logic, the first argument should be an
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * object with a &quot;currentTarget&quot; 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 *
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * <p>Additional arguments passed during event subscription will be
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith * automatically added after those passed to fire().</p>
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith *
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
cb5c642766e66487e8b32314c4543ee49ced07c8Luke Smith * @private
680f13616a493c7bf3a794982e07d10abd9763b3Luke Smith */
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke SmithNotifier.prototype.fire = function (e) {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith // first arg to delegate notifier should be an object with currentTarget
63d012ee193ba8c768b2a2aade99081422759213Luke Smith var args = toArray(arguments, 0, true),
63d012ee193ba8c768b2a2aade99081422759213Luke Smith handle = this.handle,
63d012ee193ba8c768b2a2aade99081422759213Luke Smith ce = handle.evt,
63d012ee193ba8c768b2a2aade99081422759213Luke Smith sub = handle.sub,
63d012ee193ba8c768b2a2aade99081422759213Luke Smith thisObj = sub.context,
63d012ee193ba8c768b2a2aade99081422759213Luke Smith delegate = sub.filter,
1a728a9dcb11a10b979d625fbda0faae30ce4476Luke Smith event = e || {},
1a728a9dcb11a10b979d625fbda0faae30ce4476Luke Smith ret;
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith if (this.emitFacade) {
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith if (!e || !e.preventDefault) {
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith event = ce._getFacade();
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith if (isObject(e) && !e.preventDefault) {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith Y.mix(event, e, true);
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith args[0] = event;
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith } else {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith args.unshift(event);
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith }
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith }
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith event.type = ce.type;
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith event.details = args.slice();
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
63d012ee193ba8c768b2a2aade99081422759213Luke Smith if (delegate) {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith event.container = ce.host;
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith }
63d012ee193ba8c768b2a2aade99081422759213Luke Smith } else if (delegate && isObject(e) && e.currentTarget) {
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith args.shift();
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith }
fa0dc2eee6aa0bb2be0232d98b593a4432a47c1aLuke Smith
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith sub.context = thisObj || event.currentTarget || ce.host;
1a728a9dcb11a10b979d625fbda0faae30ce4476Luke Smith ret = ce.fire.apply(ce, args);
b83f2c24dbea46614ab539e32fbbbba55776be04Luke Smith sub.context = thisObj; // reset for future firing
1a728a9dcb11a10b979d625fbda0faae30ce4476Luke Smith
1a728a9dcb11a10b979d625fbda0faae30ce4476Luke Smith Error!

 

There was an error!

null

java.lang.NullPointerException