Last active
April 5, 2017 07:49
-
-
Save infostreams/6540654 to your computer and use it in GitHub Desktop.
ensures a handler is run before any other registered handlers, independent of the order in which they were bound. Requires jQuery > 1.7
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
$.fn.bindFirst = function(which, handler) { | |
// ensures a handler is run before any other registered handlers, | |
// independent of the order in which they were bound | |
var $el = $(this); | |
$el.unbind(which, handler); | |
$el.bind(which, handler); | |
var events = $._data($el[0]).events; | |
var registered = events[which]; | |
registered.unshift(registered.pop()); | |
events[which] = registered; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment