Created
July 28, 2011 13:44
-
-
Save johnnyfreeman/1111579 to your computer and use it in GitHub Desktop.
Placeholder - Just a little js to backup html5's placeholder attribute.
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
(function($){ | |
$.fn.placeHolder = function() { | |
// check for placeholder attribute support in current browser | |
var nativeSupport = "placeholder" in document.createElement("input"); | |
var restorePlaceHolder = function() { | |
if (this.value == "") { | |
$(this).addClass('inactive'); | |
if (!nativeSupport) this.value = this.placeholder; | |
}; | |
}; | |
var clearText = function() { | |
$(this).removeClass('inactive'); | |
if (!nativeSupport && this.value == this.placeholder) this.value = ""; | |
}; | |
return this.focus(clearText).blur(restorePlaceHolder).blur(); | |
}; | |
// attach to elements using the html5 placeholder attribute | |
$('input[placeholder],textarea[placeholder]').placeHolder(); | |
})(jQuery); |
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
(function(a){a.fn.placeHolder=function(){var d=this.placeholder;var e=this.value;var f="placeholder" in document.createElement("input");var c=function(){if(this.value==""){a(this).addClass("inactive");if(!f){e=d}}};var b=function(){a(this).removeClass("inactive");if(!f&&e==d){e=""}};return this.focus(b).blur(c).blur()};a("input[placeholder],textarea[placeholder]").placeHolder()})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment