From 0fefabfdc1d6f7bc524cc278a5751e2c649dd1ad Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Sat, 16 Oct 2010 11:15:32 +0200 Subject: [PATCH] =?UTF-8?q?We=20don=E2=80=99t=20want=20to=20stop=20the=20p?= =?UTF-8?q?lugin=20after=20event.preventDefault()=20in=20a=20submit=20hand?= =?UTF-8?q?ler.=20Fixes=20#5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jquery.placeholder.js | 13 ++++++++----- jquery.placeholder.min.js | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 03b04d1..7795f3b 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -1,5 +1,5 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.5 + * HTML5 Placeholder jQuery Plugin v1.6 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin * @author Mathias Bynens */ @@ -24,7 +24,7 @@ return newAttrs; } - function onFocus() { + function clearPlaceholder() { var $input = $(this); if ($input.val() === $input.attr('placeholder') && $input.hasClass('placeholder')) { if ($input.data('placeholder-password')) { @@ -49,7 +49,7 @@ $replacement .removeAttr('name') .data('placeholder-password', true) - .bind('focus.placeholder', onFocus); + .bind('focus.placeholder', clearPlaceholder); $input .data('placeholder-textinput', $replacement) .before($replacement); @@ -66,7 +66,10 @@ // Look for forms $('form').bind('submit.placeholder', function() { // Clear the placeholder values so they don’t get submitted - $('.placeholder', this).val(''); + var $inputs = $('.placeholder', this).each(clearPlaceholder); + setTimeout(function() { + $inputs.each(setPlaceholder); + }, 10); }); }); @@ -77,7 +80,7 @@ $.fn.placeholder = function() { return this.filter(':input[placeholder]') - .bind('focus.placeholder', onFocus) + .bind('focus.placeholder', clearPlaceholder) .bind('blur.placeholder' , setPlaceholder) .trigger('blur.placeholder').end(); }; diff --git a/jquery.placeholder.min.js b/jquery.placeholder.min.js index 1a3d6ad..cd02364 100644 --- a/jquery.placeholder.min.js +++ b/jquery.placeholder.min.js @@ -1,6 +1,6 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.5 + * HTML5 Placeholder jQuery Plugin v1.6 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin * @author Mathias Bynens */ -(function(d){if('placeholder' in document.createElement('input')){d.fn.placeholder=function(){return this};return}function a(f){var e={},g=/^jQuery\d+$/;d.each(f.attributes,function(j,h){if(!g.test(h.name)){e[h.name]=h.value}});return e}function b(){var e=d(this);if(e.val()===e.attr('placeholder')&&e.hasClass('placeholder')){if(e.data('placeholder-password')){e.hide().next().show().focus()}else{e.val('').removeClass('placeholder')}}}function c(f){var i,h=d(this);if(h.val()===''||h.val()===h.attr('placeholder')){if(h.is(':password')){if(!h.data('placeholder-textinput')){try{i=h.clone().attr({type:'text'})}catch(g){i=d('').attr(d.extend(a(h[0]),{type:'text'}))}i.removeAttr('name').data('placeholder-password',true).bind('focus.placeholder',b);h.data('placeholder-textinput',i).before(i)}h=h.hide().prev().show()}h.addClass('placeholder').val(h.attr('placeholder'))}else{h.removeClass('placeholder')}}d(function(){d('form').bind('submit.placeholder',function(){d('.placeholder',this).val('')})});d(window).bind('unload.placeholder',function(){d('.placeholder').val('')});d.fn.placeholder=function(){return this.filter(':input[placeholder]').bind('focus.placeholder',b).bind('blur.placeholder',c).trigger('blur.placeholder').end()}})(jQuery); \ No newline at end of file +(function(d){if('placeholder' in document.createElement('input')){d.fn.placeholder=function(){return this};return}function b(f){var e={},g=/^jQuery\d+$/;d.each(f.attributes,function(j,h){if(!g.test(h.name)){e[h.name]=h.value}});return e}function a(){var e=d(this);if(e.val()===e.attr('placeholder')&&e.hasClass('placeholder')){if(e.data('placeholder-password')){e.hide().next().show().focus()}else{e.val('').removeClass('placeholder')}}}function c(f){var i,h=d(this);if(h.val()===''||h.val()===h.attr('placeholder')){if(h.is(':password')){if(!h.data('placeholder-textinput')){try{i=h.clone().attr({type:'text'})}catch(g){i=d('').attr(d.extend(b(h[0]),{type:'text'}))}i.removeAttr('name').data('placeholder-password',true).bind('focus.placeholder',a);h.data('placeholder-textinput',i).before(i)}h=h.hide().prev().show()}h.addClass('placeholder').val(h.attr('placeholder'))}else{h.removeClass('placeholder')}}d(function(){d('form').bind('submit.placeholder',function(){var e=d('.placeholder',this).each(a);setTimeout(function(){e.each(c)},10)})});d(window).bind('unload.placeholder',function(){d('.placeholder').val('')});d.fn.placeholder=function(){return this.filter(':input[placeholder]').bind('focus.placeholder',a).bind('blur.placeholder',c).trigger('blur.placeholder').end()}})(jQuery); \ No newline at end of file