Created
March 12, 2012 18:27
-
-
Save easierbycode/2023795 to your computer and use it in GitHub Desktop.
IE placeholder polyfill
This file contains hidden or 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
# -= styling =- | |
# li label.over | |
# margin-top: 16px | |
# margin-left: 9px | |
# color: #777 | |
# input[type="text"]:active, input[type="password"]:active | |
# color: black | |
# -= jQuery plugin =- | |
$.fn.textHint = -> | |
@each -> | |
$input = $(this) | |
defaultValue = $input.val() | |
label = $("<label>").text($input.attr("placeholder")) | |
$input.before label | |
if label and $input.val() is "" | |
label.parent().css "position", "relative" | |
label.addClass("over").click -> | |
$input.focus() | |
else | |
label.hide() | |
$input.focus -> | |
if $input.val() is defaultValue | |
$input.val "" | |
label.css textIndent: -10000 | |
$input.blur -> | |
if defaultValue and $input.val() is "" | |
$input.val defaultValue | |
else label.css textIndent: 0 if $input.val() is "" | |
# -= ready.coffee (requires Modernizr) =- | |
$(document).ready -> | |
unless Modernizr.input.placeholder | |
$("[placeholder]").textHint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment