jQuery event trigger - cancelable event
- by Dismissile
I have created a jquery plugin which is triggering an event:
$.fn.myplugin = function(options) {
this.on("foo.myplugin", options.foo);
this.on("bar.myplugin", options.bar);
};
I want to check if foo has been canceled by a user and prevent bar from being triggered:
// trigger foo
this.trigger("foo.myplugin");
// how do I check if foo was canceled
if( !fooCanceled ) {
this.trigger("bar.myplugin");
}
How can I check if foo was canceled to prevent bar from being triggered?
jQuery UI does something similar to this, but it did not work when I tried:
if (this._trigger("search", event) === false) {
return;
}
I tried something similar to this:
if( this.trigger("foo.myplugin") === false ) {
return;
}
this.trigger("bar.myplugin");
But bar was still being triggered.