diff --git a/demo.html b/demo.html index 0a0e2a6..7c17df8 100644 --- a/demo.html +++ b/demo.html @@ -16,7 +16,7 @@

HTML5 Placeholder jQuery Plugin

-

Check out the HTML5 Placeholder jQuery Plugin project page on GitHub.

+

Check out the HTML5 Placeholder jQuery Plugin project page on GitHub.

$(function() {
$('input, textarea').placeholder();
});

diff --git a/jquery.placeholder.js b/jquery.placeholder.js index d271882..aca462a 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -1,26 +1,49 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.8.2 - * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin + * HTML5 Placeholder jQuery Plugin v1.8.3 + * @link http://mths.be/placeholder * @author Mathias Bynens */ ;(function($) { var isInputSupported = 'placeholder' in document.createElement('input'), isTextareaSupported = 'placeholder' in document.createElement('textarea'); + if (isInputSupported && isTextareaSupported) { + $.fn.placeholder = function() { return this; }; + $.fn.placeholder.input = $.fn.placeholder.textarea = true; + } else { + $.fn.placeholder = function() { return this.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]') .bind('focus.placeholder', clearPlaceholder) .bind('blur.placeholder', setPlaceholder) - .trigger('blur.placeholder').end(); + .trigger('blur.placeholder').end(); }; + $.fn.placeholder.input = isInputSupported; $.fn.placeholder.textarea = isTextareaSupported; + + $(function() { + // Look for forms + $('form').bind('submit.placeholder', function() { + // Clear the placeholder values so they don’t get submitted + var $inputs = $('.placeholder', this).each(clearPlaceholder); + setTimeout(function() { + $inputs.each(setPlaceholder); + }, 10); + }); + }); + + // Clear placeholder values upon page reload + $(window).bind('unload.placeholder', function() { + $('.placeholder').val(''); + }); + } function args(elem) { @@ -78,20 +101,4 @@ } } - $(function() { - // Look for forms - $('form').bind('submit.placeholder', function() { - // Clear the placeholder values so they don’t get submitted - var $inputs = $('.placeholder', this).each(clearPlaceholder); - setTimeout(function() { - $inputs.each(setPlaceholder); - }, 10); - }); - }); - - // Clear placeholder values upon page reload - $(window).bind('unload.placeholder', function() { - $('.placeholder').val(''); - }); - }(jQuery)); \ No newline at end of file diff --git a/jquery.placeholder.min.js b/jquery.placeholder.min.js index b38b472..b42e45f 100644 --- a/jquery.placeholder.min.js +++ b/jquery.placeholder.min.js @@ -1,6 +1,6 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.8.2 - * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin + * HTML5 Placeholder jQuery Plugin v1.8.3 + * @link http://mths.be/placeholder * @author Mathias Bynens */ -(function(f){var e='placeholder' in document.createElement('input'),a='placeholder' in document.createElement('textarea');if(e&&a){f.fn.placeholder=function(){return this};f.fn.placeholder.input=f.fn.placeholder.textarea=true}else{f.fn.placeholder=function(){return this.filter((e?'textarea':':input')+'[placeholder]').bind('focus.placeholder',b).bind('blur.placeholder',d).trigger('blur.placeholder').end()};f.fn.placeholder.input=e;f.fn.placeholder.textarea=a}function c(h){var g={},i=/^jQuery\d+$/;f.each(h.attributes,function(k,j){if(j.specified&&!i.test(j.name)){g[j.name]=j.value}});return g}function b(){var g=f(this);if(g.val()===g.attr('placeholder')&&g.hasClass('placeholder')){if(g.data('placeholder-password')){g.hide().next().attr('id',g.removeAttr('id').data('placeholder-id')).show().focus()}else{g.val('').removeClass('placeholder')}}}function d(h){var l,k=f(this),g=k,j=this.id;if(k.val()===''){if(k.is(':password')){if(!k.data('placeholder-textinput')){try{l=k.clone().attr({type:'text'})}catch(i){l=f('').attr(f.extend(c(this),{type:'text'}))}l.removeAttr('name').data('placeholder-password',true).data('placeholder-id',j).bind('focus.placeholder',b);k.data('placeholder-textinput',l).data('placeholder-id',j).before(l)}k=k.removeAttr('id').hide().prev().attr('id',j).show()}k.addClass('placeholder').val(k.attr('placeholder'))}else{k.removeClass('placeholder')}}f(function(){f('form').bind('submit.placeholder',function(){var g=f('.placeholder',this).each(b);setTimeout(function(){g.each(d)},10)})});f(window).bind('unload.placeholder',function(){f('.placeholder').val('')})}(jQuery)); \ No newline at end of file +(function(f){var e='placeholder' in document.createElement('input'),a='placeholder' in document.createElement('textarea');if(e&&a){f.fn.placeholder=function(){return this};f.fn.placeholder.input=f.fn.placeholder.textarea=true}else{f.fn.placeholder=function(){return this.filter((e?'textarea':':input')+'[placeholder]').bind('focus.placeholder',b).bind('blur.placeholder',d).trigger('blur.placeholder').end()};f.fn.placeholder.input=e;f.fn.placeholder.textarea=a;f(function(){f('form').bind('submit.placeholder',function(){var g=f('.placeholder',this).each(b);setTimeout(function(){g.each(d)},10)})});f(window).bind('unload.placeholder',function(){f('.placeholder').val('')})}function c(h){var g={},i=/^jQuery\d+$/;f.each(h.attributes,function(k,j){if(j.specified&&!i.test(j.name)){g[j.name]=j.value}});return g}function b(){var g=f(this);if(g.val()===g.attr('placeholder')&&g.hasClass('placeholder')){if(g.data('placeholder-password')){g.hide().next().attr('id',g.removeAttr('id').data('placeholder-id')).show().focus()}else{g.val('').removeClass('placeholder')}}}function d(h){var l,k=f(this),g=k,j=this.id;if(k.val()===''){if(k.is(':password')){if(!k.data('placeholder-textinput')){try{l=k.clone().attr({type:'text'})}catch(i){l=f('').attr(f.extend(c(this),{type:'text'}))}l.removeAttr('name').data('placeholder-password',true).data('placeholder-id',j).bind('focus.placeholder',b);k.data('placeholder-textinput',l).data('placeholder-id',j).before(l)}k=k.removeAttr('id').hide().prev().attr('id',j).show()}k.addClass('placeholder').val(k.attr('placeholder'))}else{k.removeClass('placeholder')}}}(jQuery)); \ No newline at end of file