diff --git a/jquery.placeholder.js b/jquery.placeholder.js index 41c3554..284f1ff 100644 --- a/jquery.placeholder.js +++ b/jquery.placeholder.js @@ -1,4 +1,4 @@ -/*! http://mths.be/placeholder v2.0.5 by @mathias */ +/*! http://mths.be/placeholder v2.0.6 by @mathias */ ;(function(window, document, $) { var isInputSupported = 'placeholder' in document.createElement('input'), @@ -99,8 +99,10 @@ function clearPlaceholder(event, value) { var input = this, - $input = $(input); + $input = $(input), + hadFocus; if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) { + hadFocus = input == document.activeElement; if ($input.data('placeholder-password')) { $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id')); // If `clearPlaceholder` was called from `$.valHooks.input.set` @@ -112,6 +114,7 @@ input.value = ''; $input.removeClass('placeholder'); } + hadFocus && input.select(); } } diff --git a/jquery.placeholder.min.js b/jquery.placeholder.min.js index 122277a..db55023 100644 --- a/jquery.placeholder.min.js +++ b/jquery.placeholder.min.js @@ -1,2 +1,2 @@ -/*! http://mths.be/placeholder v2.0.5 by @mathias */ -;(function(f,h,$){var a='placeholder' in h.createElement('input'),d='placeholder' in h.createElement('textarea'),i=$.fn,c=$.valHooks,k,j;if(a&&d){j=i.placeholder=function(){return this};j.input=j.textarea=true}else{j=i.placeholder=function(){var l=this;l.filter((a?'textarea':':input')+'[placeholder]').not('.placeholder').bind({'focus.placeholder':b,'blur.placeholder':e}).data('placeholder-enabled',true).trigger('blur.placeholder');return l};j.input=a;j.textarea=d;k={get:function(m){var l=$(m);return l.data('placeholder-enabled')&&l.hasClass('placeholder')?'':m.value},set:function(m,n){var l=$(m);if(!l.data('placeholder-enabled')){return m.value=n}if(n==''){m.value=n;if(m!=h.activeElement){e.call(m)}}else{if(l.hasClass('placeholder')){b.call(m,true,n)||(m.value=n)}else{m.value=n}}return l}};a||(c.input=k);d||(c.textarea=k);$(function(){$(h).delegate('form','submit.placeholder',function(){var l=$('.placeholder',this).each(b);setTimeout(function(){l.each(e)},10)})});$(f).bind('beforeunload.placeholder',function(){$('.placeholder').each(function(){this.value=''})})}function g(m){var l={},n=/^jQuery\d+$/;$.each(m.attributes,function(p,o){if(o.specified&&!n.test(o.name)){l[o.name]=o.value}});return l}function b(m,n){var l=this,o=$(l);if(l.value==o.attr('placeholder')&&o.hasClass('placeholder')){if(o.data('placeholder-password')){o=o.hide().next().show().attr('id',o.removeAttr('id').data('placeholder-id'));if(m===true){return o[0].value=n}o.focus()}else{l.value='';o.removeClass('placeholder')}}}function e(){var q,l=this,p=$(l),m=p,o=this.id;if(l.value==''){if(l.type=='password'){if(!p.data('placeholder-textinput')){try{q=p.clone().attr({type:'text'})}catch(n){q=$('').attr($.extend(g(this),{type:'text'}))}q.removeAttr('name').data({'placeholder-password':true,'placeholder-id':o}).bind('focus.placeholder',b);p.data({'placeholder-textinput':q,'placeholder-id':o}).before(q)}p=p.removeAttr('id').hide().prev().attr('id',o).show()}p.addClass('placeholder');p[0].value=p.attr('placeholder')}else{p.removeClass('placeholder')}}}(this,document,jQuery)); \ No newline at end of file +/*! http://mths.be/placeholder v2.0.6 by @mathias */ +;(function(g,i,d){var a='placeholder' in i.createElement('input'),e='placeholder' in i.createElement('textarea'),j=d.fn,c=d.valHooks,l,k;if(a&&e){k=j.placeholder=function(){return this};k.input=k.textarea=true}else{k=j.placeholder=function(){var m=this;m.filter((a?'textarea':':input')+'[placeholder]').not('.placeholder').bind({'focus.placeholder':b,'blur.placeholder':f}).data('placeholder-enabled',true).trigger('blur.placeholder');return m};k.input=a;k.textarea=e;l={get:function(n){var m=d(n);return m.data('placeholder-enabled')&&m.hasClass('placeholder')?'':n.value},set:function(n,o){var m=d(n);if(!m.data('placeholder-enabled')){return n.value=o}if(o==''){n.value=o;if(n!=i.activeElement){f.call(n)}}else{if(m.hasClass('placeholder')){b.call(n,true,o)||(n.value=o)}else{n.value=o}}return m}};a||(c.input=l);e||(c.textarea=l);d(function(){d(i).delegate('form','submit.placeholder',function(){var m=d('.placeholder',this).each(b);setTimeout(function(){m.each(f)},10)})});d(g).bind('beforeunload.placeholder',function(){d('.placeholder').each(function(){this.value=''})})}function h(n){var m={},o=/^jQuery\d+$/;d.each(n.attributes,function(q,p){if(p.specified&&!o.test(p.name)){m[p.name]=p.value}});return m}function b(o,p){var n=this,q=d(n),m;if(n.value==q.attr('placeholder')&&q.hasClass('placeholder')){m=n==i.activeElement;if(q.data('placeholder-password')){q=q.hide().next().show().attr('id',q.removeAttr('id').data('placeholder-id'));if(o===true){return q[0].value=p}q.focus()}else{n.value='';q.removeClass('placeholder')}m&&n.select()}}function f(){var r,m=this,q=d(m),n=q,p=this.id;if(m.value==''){if(m.type=='password'){if(!q.data('placeholder-textinput')){try{r=q.clone().attr({type:'text'})}catch(o){r=d('').attr(d.extend(h(this),{type:'text'}))}r.removeAttr('name').data({'placeholder-password':true,'placeholder-id':p}).bind('focus.placeholder',b);q.data({'placeholder-textinput':r,'placeholder-id':p}).before(r)}q=q.removeAttr('id').hide().prev().attr('id',p).show()}q.addClass('placeholder');q[0].value=q.attr('placeholder')}else{q.removeClass('placeholder')}}}(this,document,jQuery)); \ No newline at end of file