Skip to content

Instantly share code, notes, and snippets.

@lsmith
Last active December 19, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsmith/5986637 to your computer and use it in GitHub Desktop.
Save lsmith/5986637 to your computer and use it in GitHub Desktop.
Notifier.prototype.fire = function () {
// first arg to delegate notifier should be an object with currentTarget
var args = toArray(arguments, 0, true),
handle = this.handle,
ce = handle.evt,
sub = handle.sub,
thisObj = sub.context,
delegate = sub.filter,
event = e || {},
ret;
if (this.emitFacade) {
if (!e || !e.preventDefault) {
event = ce._getFacade();
if (isObject(e) && !e.preventDefault) {
Y.mix(event, e, true);
args[0] = event;
} else {
args.unshift(event);
}
}
event.type = ce.type;
event.details = args.slice();
if (delegate) {
event.container = ce.host;
}
} else if (delegate && isObject(e) && e.currentTarget) {
args.shift();
}
sub.context = thisObj || event.currentTarget || ce.host;
ret = ce.fire.apply(ce, args);
// have to handle preventedFn and stoppedFn manually because
// Notifier CustomEvents are forced to emitFacade=false
if (e.prevented && ce.preventedFn) {
ce.preventedFn.apply(ce, args);
}
if (e.stopped && ce.stoppedFn) {
ce.stoppedFn.apply(ce, args);
}
sub.context = thisObj; // reset for future firing
// to capture callbacks that return false to stopPropagation.
// Useful for delegate implementations
return ret;
};
Y.Event.define('tap', {
publishConfig: {
preventedFn: function (e) {
// This should be moved to a prototype
e.target.once('click', function (click) {
click.preventDefault();
});
}
},
...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment