Created
March 25, 2010 10:56
-
-
Save 3rd-Eden/343419 to your computer and use it in GitHub Desktop.
Detect if the placeholder attribute is support, if not find all elements and provide support for it through event listeners.
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
(function(){ | |
if( function(){ var input = document.createElement( "input" ); return ( "placeholder" in input )}() ) | |
return; | |
Spry.$$( "input[placeholder]", document.body ).forEach( function( e ){ | |
var current = e.attributes.getNamedItem( "placeholder" ).value; | |
if( !e.value ){ | |
e.value = current; | |
// add special place holder class for styling... | |
Spry.Utils.addClassName( e, "placeholder" ); | |
} | |
Spry.Utils.addEventListener( e, "focus", function(){ this.value = this.value == current ? "" : this.value; return this.value == current ? Spry.Utils.addClassName( e, "placeholder" ) : Spry.Utils.removeClassName( e, "placeholder") }); | |
Spry.Utils.addEventListener( e, "blur", function(){ this.value = this.value == "" ? current : this.value; return this.value == current ? Spry.Utils.addClassName( e, "placeholder" ) : Spry.Utils.removeClassName( e, "placeholder") }); | |
}) | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment