Created
May 4, 2011 04:36
-
-
Save robotdana/954764 to your computer and use it in GitHub Desktop.
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
// watches a text input/area and triggers a change event as soon as it changes. Doesn't wait for blur. | |
// Doesn't loop unless a relevant element is focused | |
(function($){ | |
$.fn.extend({ | |
val_change: function(callback){ | |
var interval; | |
var $this = $(this); | |
$this.focus(function(){ | |
val last_val, current_val; | |
interval = setInterval(function(){ | |
var current_val = $this.val(); | |
if (last_val !== current_val) { | |
$this.triggerHandler('val_change'); | |
last_val = current_val; | |
} | |
}, 16); | |
}).blur(function(){ | |
$this.unbind('val_change'); | |
clearInterval(interval); | |
}).bind('val_change', callback); | |
return $this; | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment