Skip to content

Instantly share code, notes, and snippets.

@ayumi
Created November 13, 2012 21:21
Show Gist options
  • Save ayumi/4068476 to your computer and use it in GitHub Desktop.
Save ayumi/4068476 to your computer and use it in GitHub Desktop.
[cs] Extend JQuery to bind changes in content, and skip general keypresses.
# Bind changes in content. Skip general keypresses.
$.fn.onValChange = (callback) ->
# IE < 9
usePropertyChange = true
this.on("propertychange.onValChange", (e) =>
callback.call(this) if (e.originalEvent.propertyName == "value")
return
)
# HTML5
this.on("input.onValChange", (e) =>
# This event fires before the above, unbinding it if we're not in IE.
if usePropertyChange
this.off("propertychange.onValChange")
callback.call(this)
return
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment