Skip to content

Instantly share code, notes, and snippets.

@dmohl
Created January 28, 2012 14:38
Show Gist options
  • Select an option

  • Save dmohl/1694545 to your computer and use it in GitHub Desktop.

Select an option

Save dmohl/1694545 to your computer and use it in GitHub Desktop.
Placeholder jQuery Plugin in CoffeeScript
# Ported from Josh Bush's example at http://digitalbush.com/2011/03/29/testing-jquery-plugins-with-node-js-and-jasmine/
$ = jQuery
$.fn.placeholder = (description) ->
@.each ->
input = $(@)
# Note: We should use "on" instead of "bind" with the latest version of jQuery, but
# we'll leave this just like the original for now.
input.bind("blur.placeholder", -> input.val(input.val() or description))
.bind("focus.placeholder", -> if input.val() is description then input.val(''))
.trigger "blur.placeholder"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment