Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

don't change text if it is already focused

  • Loading branch information...
commit e793a47621f40f323775ef3f7ea8d07934761f6e 1 parent efc109b
Mike Mangino authored

Showing 2 changed files with 6 additions and 11 deletions. Show diff stats Hide diff stats

  1. +4 3 jquery.autofill.js
  2. +2 8 jquery.autofill.min.js
7 jquery.autofill.js
@@ -25,9 +25,10 @@
25 25 p_obj = obj;
26 26 obj = obj.next();
27 27 }
28   -
29   - obj.css({color:options.defaultTextColor})
30   - .val(options.value);
  28 + if(document.activeElement != obj[0]) {
  29 + obj.css({color:options.defaultTextColor})
  30 + .val(options.value);
  31 + }
31 32 obj.each(function() {
32 33 $(this.form).submit(function() {
33 34 if (obj.val() == options.value) {
10 jquery.autofill.min.js
... ... @@ -1,11 +1,5 @@
1   -/*
2   -* Auto-Fill Plugin
3   -* Written by Joe Sak
4   -* Website: http://www.joesak.com/
5   -* Article: http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click/
6   -* GitHub: http://github.com/joemsak/jQuery-AutoFill
7   -*/
8 1
9 2 (function($){$.fn.autofill=function(options){var defaults={value:'First Name',prePopulate:'',defaultTextColor:"#666",activeTextColor:"#333"};var options=$.extend(defaults,options);return this.each(function(){var obj=$(this);var pfield=(obj.attr('type')=='password');var p_obj=false;if(pfield){obj.hide();obj.after('<input type="text" id="'+this.id+'_autofill" class="'+$(this).attr('class')+'" />');p_obj=obj;obj=obj.next();}
10   -obj.css({color:options.defaultTextColor}).val(options.value);obj.focus(function(){if(obj.val()==options.value){if(pfield){obj.hide();p_obj.show().focus()}
  3 +if(document.activeElement!=obj[0]){obj.css({color:options.defaultTextColor}).val(options.value);}
  4 +obj.each(function(){$(this.form).submit(function(){if(obj.val()==options.value){obj.val(options.prePopulate);}});});obj.focus(function(){if(obj.val()==options.value){if(pfield){obj.hide();p_obj.show().focus()}
11 5 obj.val(options.prePopulate).css({color:options.activeTextColor});}}).blur(function(){if(obj.val()==options.prePopulate||obj.val()==''){obj.css({color:options.defaultTextColor}).val(options.value);}});if(p_obj&&p_obj.length>0){p_obj.blur(function(){if(p_obj.val()==""){p_obj.hide();obj.show().css({color:options.defaultTextColor}).val(options.value);}});}});};})(jQuery);

0 comments on commit e793a47

Please sign in to comment.
Something went wrong with that request. Please try again.