Last active
December 24, 2015 07:19
-
-
Save incik/6762764 to your computer and use it in GitHub Desktop.
'onChange' callback delayed until user stops changing value of input
This file contains hidden or 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
# Calls callback function if value of given element stops changing | |
# | |
# elem - element which's value we're watching | |
# callback - anonymous method or callback fuction name | |
# (delay) - delay before callback | |
wait_for_it = (elem, callback, delay = 750) -> | |
old_val = elem.val() | |
setTimeout ( -> | |
if elem.val() == old_val | |
callback() | |
), delay | |
# Usage example: | |
$('input').change -> | |
wait_for_it($(this), -> | |
alert('foo!') | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment