Created
November 28, 2012 17:08
-
-
Save pygeek/4162579 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
<script> | |
(function($){ | |
//Adding inputFocus to namespace for the placeholder shim | |
$.fn.inputFocus = function(text){ | |
$(this).focusin(function(){ | |
if($(this).val() == text){ | |
$(this).val('') | |
} | |
}) | |
$(this).focusout(function(){ | |
if(!$(this).val().length){ | |
$(this).val(text) | |
} | |
}) | |
} | |
//Placeholder shim | |
elementSupportsAttribute = function(element,attribute){ | |
//Detects Attribute support for outdated browsers | |
var test = document.createElement(element); | |
if (attribute in test){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
if(!elementSupportsAttribute('input','placeholder')){ | |
//Support for outdated browsers | |
$('input').not(':submit').each(function(i,val){ | |
if($(this).val()=="" && $(this).attr("placeholder")!=""){ | |
var $placeholder = $(this).attr('placeholder'); | |
$(this).val($placeholder) | |
$(this).inputFocus($placeholder) | |
} | |
}) | |
var $textarea_placeholder = $('textarea').attr('placeholder'); | |
$('textarea').val($textarea_placeholder) | |
$('textarea').inputFocus($textarea_placeholder) | |
} | |
})(jQuery); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment