Permalink
Browse files

Check for document.activeElement before using it. Closes #9.

  • Loading branch information...
1 parent a3537cb commit 0fddbe8031180febb34221455d09fed777517d36 @mudge committed Dec 20, 2011
Showing with 7 additions and 6 deletions.
  1. +2 −2 README.markdown
  2. +3 −2 jquery.example.js
  3. +2 −2 jquery.example.min.js
View
@@ -1,4 +1,4 @@
-jQuery Form Example Plugin 1.5.1
+jQuery Form Example Plugin 1.5.2
======================================
This is a jQuery plugin to populate form inputs with example text that
@@ -78,7 +78,7 @@ All events are namespaced with `.example` so they can be selectively unbound wit
Downloading
-----------
-[Download jQuery Example 1.5.1](https://github.com/mudge/jquery_example/zipball/v1.5.1).
+[Download jQuery Example 1.5.2](https://github.com/mudge/jquery_example/zipball/v1.5.2).
Testing
-------
View
@@ -1,7 +1,7 @@
/*global window, document, jQuery */
/*
- * jQuery Form Example Plugin 1.5.1
+ * jQuery Form Example Plugin 1.5.2
* Populate form inputs with example text that disappears on focus.
*
* e.g.
@@ -108,7 +108,8 @@
/* Initially place the example text in the field if it is empty
* and doesn't have focus yet.
*/
- if ($this.val() === '' && this !== document.activeElement) {
+ if ($this.val() === '' &&
+ (!document.hasOwnProperty('activeElement') || this !== document.activeElement)) {
/* The text argument can now be a function; if this is the case,
* call it, passing the current element as `this`.
View
@@ -1,5 +1,5 @@
/*
- * jQuery Form Example Plugin 1.5.1
+ * jQuery Form Example Plugin 1.5.2
* Populate form inputs with example text that disappears on focus.
*
* e.g.
@@ -25,4 +25,4 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
-(function(a){"use strict",a.fn.example=function(b,c){var d=a.isFunction(b),e=a.extend({},c,{example:b});return this.each(function(){var b,c,f=a(this);a.metadata?b=a.extend({},a.fn.example.defaults,f.metadata(),e):b=a.extend({},a.fn.example.defaults,e),c=function(){a(this).find("."+b.className).val("")},a.fn.example.boundClassNames[b.className]||(a(window).bind("unload.example",function(){a("."+b.className).val("")}),a.fn.on?a("body").on("submit.example","form",c):a.fn.delegate?a("body").delegate("form","submit.example",c):a.fn.live?a("form").live("submit.example",c):a("form").bind("submit.example",c),a.fn.example.boundClassNames[b.className]=!0),f.val()!==this.defaultValue&&(d||f.val()===b.example)&&f.val(this.defaultValue),f.val()===""&&this!==document.activeElement&&f.addClass(b.className).val(d?b.example.call(this):b.example),f.bind("focus.example",function(){a(this).is("."+b.className)&&a(this).val("").removeClass(b.className)}).bind("change.example",function(){a(this).is("."+b.className)&&a(this).removeClass(b.className)}).bind("blur.example",function(){a(this).val()===""&&a(this).addClass(b.className).val(d?b.example.call(this):b.example)})})},a.fn.example.defaults={className:"example"},a.fn.example.boundClassNames=[]})(jQuery);
+(function(a){"use strict",a.fn.example=function(b,c){var d=a.isFunction(b),e=a.extend({},c,{example:b});return this.each(function(){var b,c,f=a(this);a.metadata?b=a.extend({},a.fn.example.defaults,f.metadata(),e):b=a.extend({},a.fn.example.defaults,e),c=function(){a(this).find("."+b.className).val("")},a.fn.example.boundClassNames[b.className]||(a(window).bind("unload.example",function(){a("."+b.className).val("")}),a.fn.on?a("body").on("submit.example","form",c):a.fn.delegate?a("body").delegate("form","submit.example",c):a.fn.live?a("form").live("submit.example",c):a("form").bind("submit.example",c),a.fn.example.boundClassNames[b.className]=!0),f.val()!==this.defaultValue&&(d||f.val()===b.example)&&f.val(this.defaultValue),f.val()===""&&(!document.hasOwnProperty("activeElement")||this!==document.activeElement)&&f.addClass(b.className).val(d?b.example.call(this):b.example),f.bind("focus.example",function(){a(this).is("."+b.className)&&a(this).val("").removeClass(b.className)}).bind("change.example",function(){a(this).is("."+b.className)&&a(this).removeClass(b.className)}).bind("blur.example",function(){a(this).val()===""&&a(this).addClass(b.className).val(d?b.example.call(this):b.example)})})},a.fn.example.defaults={className:"example"},a.fn.example.boundClassNames=[]})(jQuery);

0 comments on commit 0fddbe8

Please sign in to comment.