Created
April 14, 2014 21:37
-
-
Save maxxcrawford/10684416 to your computer and use it in GitHub Desktop.
Placeholder Shim (Modernizr Test)
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
/* global Modernizr */ | |
(function (app, $, window, document, undefined) { | |
/* SHIM: <input> placeholder shim | |
--------------------------------------------------------------------------- */ | |
if(!Modernizr.input.placeholder){ | |
$(document).on('focus', 'input[placeholder], textarea[placeholder]', function() { | |
var input = $(this); | |
if (input.val() === input.attr('placeholder')) { | |
input.val('').removeClass('placeholder'); | |
} | |
}).on('blur', 'input[placeholder], textarea[placeholder]', function() { | |
var input = $(this); | |
if (input.val() === '' || input.val() === input.attr('placeholder')) { | |
input.addClass('placeholder').val(input.attr('placeholder')); | |
} | |
}).trigger('blur'); | |
// KLUDGE: IE8 doesn't seem to trigger 'blur' event on initial load; 10ms trigger delay | |
setTimeout(function(){ $('input[placeholder], textarea[placeholder]').trigger('blur'); }, 10); | |
$('[placeholder]').closest('form').submit(function() { | |
$(this).find('[placeholder]').each(function() { | |
var input = $(this); | |
if (input.val() === input.attr('placeholder')) { | |
input.val(''); | |
} | |
}); | |
}); | |
} | |
})(window.app = window.app || {}, jQuery, window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment