Created
May 24, 2010 18:58
-
-
Save umbrae/412282 to your computer and use it in GitHub Desktop.
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
| /** | |
| * HTML5 Placeholder Deprecation JS. | |
| * Automatically support the placeholder attribute in browsers that don't support it. | |
| * | |
| * To emulate webkit, placeHolderActive class should probably contain something like: | |
| * .placeholderActive { color: darkGray; } | |
| * | |
| * Chris Dary - [email protected] | |
| * Released under the WTFPL License : http://sam.zoy.org/wtfpl/ | |
| **/ | |
| if (!('placeholder' in document.createElement('input'))) { | |
| var showPlaceholder = function () { | |
| var $this = $(this), | |
| placeholder = $this.attr('placeholder'); | |
| if ($this.val() === '' && placeholder) { | |
| $this.val(placeholder).addClass('placeholderActive'); | |
| } | |
| }; | |
| var hidePlaceholder = function () { | |
| var $this = $(this), | |
| placeholder = $this.attr('placeholder'); | |
| if (placeholder && $this.val() === placeholder) { | |
| $this.val('').removeClass('placeholderActive'); | |
| } | |
| }; | |
| // Look for forms with inputs and/or textareas with a placeholder attribute in them | |
| $('form').submit(function () { | |
| // Clear the placeholder values so they don't get submitted | |
| $('.placeholderActive', this).val(''); | |
| }); | |
| // Clear placeholder values upon page reload | |
| $(window).unload(function () { | |
| $('.placeholderActive').val(''); | |
| }); | |
| $(':input').each(showPlaceholder).blur(showPlaceholder).focus(hidePlaceholder); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment