Created
February 23, 2015 19:27
-
-
Save markwatson/1633176d2dd236efdb68 to your computer and use it in GitHub Desktop.
Helper to live check for input box changes in JavaScript.
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.mwOnChange = function(callback, timeout) { | |
return $(this).each(function() { | |
if (timeout === undefined) { | |
timeout = 500; | |
} | |
var eventNames = 'keydown paste input'; | |
var timeoutId = null; | |
$(this).on(eventNames, function(e) { | |
var self = this; | |
if (timeoutId !== null){ | |
clearTimeout(timeoutId); | |
} | |
timeoutId = setTimeout(function() { | |
callback.apply(self, [e]); | |
}, timeout); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment