Skip to content
Browse files

don't change text if it is already focused

  • Loading branch information...
1 parent efc109b commit e793a47621f40f323775ef3f7ea8d07934761f6e @mmangino committed May 17, 2010
Showing with 6 additions and 11 deletions.
  1. +4 −3 jquery.autofill.js
  2. +2 −8 jquery.autofill.min.js
View
7 jquery.autofill.js
@@ -25,9 +25,10 @@
p_obj = obj;
obj = obj.next();
}
-
- obj.css({color:options.defaultTextColor})
- .val(options.value);
+ if(document.activeElement != obj[0]) {
+ obj.css({color:options.defaultTextColor})
+ .val(options.value);
+ }
obj.each(function() {
$(this.form).submit(function() {
if (obj.val() == options.value) {
View
10 jquery.autofill.min.js
@@ -1,11 +1,5 @@
-/*
-* Auto-Fill Plugin
-* Written by Joe Sak
-* Website: http://www.joesak.com/
-* Article: http://www.joesak.com/2008/11/19/a-jquery-function-to-auto-fill-input-fields-and-clear-them-on-click/
-* GitHub: http://github.com/joemsak/jQuery-AutoFill
-*/
(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();}
-obj.css({color:options.defaultTextColor}).val(options.value);obj.focus(function(){if(obj.val()==options.value){if(pfield){obj.hide();p_obj.show().focus()}
+if(document.activeElement!=obj[0]){obj.css({color:options.defaultTextColor}).val(options.value);}
+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()}
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.