Skip to content

Instantly share code, notes, and snippets.

@incik
Last active December 24, 2015 07:19
Show Gist options
  • Save incik/6762764 to your computer and use it in GitHub Desktop.
Save incik/6762764 to your computer and use it in GitHub Desktop.
'onChange' callback delayed until user stops changing value of input
# 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