Created
March 23, 2012 21:08
-
-
Save tmilewski/2175075 to your computer and use it in GitHub Desktop.
This file contains 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
(($) -> | |
$.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