Skip to content

Instantly share code, notes, and snippets.

@tmilewski
Created March 23, 2012 21:08
Show Gist options
  • Save tmilewski/2175075 to your computer and use it in GitHub Desktop.
Save tmilewski/2175075 to your computer and use it in GitHub Desktop.
(($) ->
$.fn.placeholder = ->
# Check for Placeholder Support
$.support.placeholder = (->
"placeholder" of document.createElement("input")
)()
# Emulate Form Placeholders
unless $.support.placeholder
active = document.activeElement
$(this).find(":text").focus(->
$(this).val("").removeClass "has-placeholder" if $(this).attr("placeholder") isnt "" and $(this).val() is $(this).attr("placeholder")
).blur ->
$(this).val($(this).attr("placeholder")).addClass "has-placeholder" if $(this).attr("placeholder") isnt "" and ($(this).val() is "" or $(this).val() is $(this).attr("placeholder"))
$(this).find(":text").blur()
$(active).focus()
$(this).submit ->
$(this).find(".has-placeholder").each ->
$(this).val ""
) jQuery
$('form').placeholder()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment