Created
May 15, 2012 14:34
-
-
Save cwardzala/2702240 to your computer and use it in GitHub Desktop.
multiple events trigger for jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery eventsTrigger plugin | |
* because jquery supports $(element).on('eventA eventB eventC',func) and $(element).off('eventA eventB eventC') | |
* but does not support $(element).trigger('eventA eventB eventC') | |
* this allows you to pass multiple events to be triggered in order | |
* | |
* @param {String|Array} Space-separated string or array of events in order of execution. | |
*/ | |
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
define(['jquery'], factory); | |
} else { | |
factory(root.jQuery); | |
} | |
})(this, function ($) { | |
$.fn.eventsTrigger = function (events) { | |
events = (typeof events === 'string') ? events.split(' ') : events; | |
if ( typeof events === 'object' && events.length === null ) { return this; }; | |
return this.each(function () { | |
var $element = $(this); | |
$(events).each(function (i, event) { | |
$element.trigger(event); | |
}); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment