From 73c318c67ef795a477469dcd4ce35f349b6841c0 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Mon, 27 Sep 2010 14:42:48 +0200 Subject: [PATCH] =?UTF-8?q?Return=20early=20if=20the=20element=20doesn?= =?UTF-8?q?=E2=80=99t=20have=20a=20placeholder=20attribute=20specified.=20?= =?UTF-8?q?Thanks=20for=20the=20tip,=20@gpupo!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jquery.placeholder.js | 6 +++--- jquery.placeholder.min.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jquery.placeholder.js b/jquery.placeholder.js index fd8793c..813e3dc 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -1,5 +1,5 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.3 + * HTML5 Placeholder jQuery Plugin v1.4 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin * @author Mathias Bynens */ @@ -65,8 +65,8 @@ // Yes, .each() — in case .placeholder() is called on several elements, which is very likely, e.g. $('input').placeholder(); return this.each(function() { var $input = $(this); - // Quit if the current element is not an input/textarea at all - if (!$input.is(':input')) { + // Quit if the current element doesn’t have a placeholder attribute, or is not an input/textarea at all + if (!$input.attr('placeholder') || !$input.is(':input')) { return; } setPlaceholder($input); diff --git a/jquery.placeholder.min.js b/jquery.placeholder.min.js index a77d3c0..0f31631 100644 --- a/jquery.placeholder.min.js +++ b/jquery.placeholder.min.js @@ -1,6 +1,6 @@ /*! - * HTML5 Placeholder jQuery Plugin v1.3 + * HTML5 Placeholder jQuery Plugin v1.4 * @link http://github.com/mathiasbynens/Placeholder-jQuery-Plugin * @author Mathias Bynens */ -(function(a){a.fn.placeholder=function(){if(this[0]&&'placeholder' in document.createElement('input')){return this}function b(f){var h=a('
').append(f.clone()).html().replace(/<(\w+)\s+(.*)>/,'$2'),e,g={};while((e=h.match(/\s*([\w-]+)=("[^"]*"|'[^']*'|\w+)/))){g[e[1]]=e[2].replace(/^(["'])(.*?)\1$/,'$2');h=h.replace(e[0],'')}return g}function c(){var e=a(this);if(e.val()===e.attr('placeholder')&&e.hasClass('placeholder')){if(e.data('placeholder-password')){e.next().show().focus().end().remove()}else{e.val('').removeClass('placeholder')}}}function d(f){var h;if(f.val()===''||f.val()===f.attr('placeholder')){if(f.is(':password')){try{h=f.clone().attr({type:'text'})}catch(g){h=a('',a.extend(b(f),{type:'text'}))}h.data('placeholder-password',true).focus(c);f.hide().before(h);f=h}f.addClass('placeholder').val(f.attr('placeholder'))}else{f.removeClass('placeholder')}}a('form:has([placeholder])').submit(function(){a('.placeholder',this).val('')});a(window).unload(function(){a('.placeholder').val('')});return this.each(function(){var e=a(this);if(!e.is(':input')){return}d(e);e.focus(c).blur(function(){d(e)})})}})(jQuery); \ No newline at end of file +(function(a){a.fn.placeholder=function(){if(this[0]&&'placeholder' in document.createElement('input')){return this}function b(f){var h=a('
').append(f.clone()).html().replace(/<(\w+)\s+(.*)>/,'$2'),e,g={};while((e=h.match(/\s*([\w-]+)=("[^"]*"|'[^']*'|\w+)/))){g[e[1]]=e[2].replace(/^(["'])(.*?)\1$/,'$2');h=h.replace(e[0],'')}return g}function c(){var e=a(this);if(e.val()===e.attr('placeholder')&&e.hasClass('placeholder')){if(e.data('placeholder-password')){e.next().show().focus().end().remove()}else{e.val('').removeClass('placeholder')}}}function d(f){var h;if(f.val()===''||f.val()===f.attr('placeholder')){if(f.is(':password')){try{h=f.clone().attr({type:'text'})}catch(g){h=a('',a.extend(b(f),{type:'text'}))}h.data('placeholder-password',true).focus(c);f.hide().before(h);f=h}f.addClass('placeholder').val(f.attr('placeholder'))}else{f.removeClass('placeholder')}}a('form:has([placeholder])').submit(function(){a('.placeholder',this).val('')});a(window).unload(function(){a('.placeholder').val('')});return this.each(function(){var e=a(this);if(!e.attr('placeholder')||!e.is(':input')){return}d(e);e.focus(c).blur(function(){d(e)})})}})(jQuery); \ No newline at end of file