Skip to content
Browse files

Fixed empty 'for' label attribute in IE7.

  • Loading branch information...
1 parent bf8dc4b commit 73aa4d43911d7ed28e447421837780a5bdf6ec92 @instanceofme committed
Showing with 14 additions and 5 deletions.
  1. +5 −1 README.textile
  2. +4 −0 sample/index.html
  3. +3 −2 src/jquery.infieldlabel.js
  4. +2 −2 src/jquery.infieldlabel.min.js
View
6 README.textile
@@ -1,6 +1,6 @@
h1. In-Field Labels jQuery Plugin
-*Version:* 0.2.0
+*Version:* 0.2.1
*License:* "Same as jQuery (Dual GPL + MIT)":http://docs.jquery.com/License
@@ -113,6 +113,10 @@ If a <code>placeholder</code> attribute is present on the field referenced by th
h2. Changelog
+*Version 0.2.1*
+
+* Fixed a bug with IE7 that caused the <tt>label</tt>'s <tt>for</tt> attribute to be considered empty.
+
*Version 0.2* by "Adrien Lavoillotte":http://instanceof.me/ / "streetpc":http://github.com/streetpc/
* Refactored the plugin into a state machine with unified event handling and transitions.
View
4 sample/index.html
@@ -132,6 +132,10 @@
<p><code>emptyWatch:</code> <strong>Boolean</strong><br />If <code>true</code>, keep watching the field as the user types. This allows the plugin to bring back the label as soon as it is empty, which prevents some overlay errors when the field is still focused. Defaults to <code>true</code></p>
<h2>Changelog</h2>
+ <p><strong>Version 0.2.1</strong></p>
+ <ul>
+ <li>Fixed a bug with IE7 that caused the <tt>label</tt>'s <tt>for</tt> attribute to be considered empty.</li>
+ </ul>
<p><strong>Version 0.2</strong>, by <a href="http://instanceof.me/">Adrien Lavoillotte</a> (<a href="http://github.com/streetpc/">streetpc</a>)</p>
<ul>
<li>Refactored the plugin into a state machine with unified event handling and transitions.</li>
View
5 src/jquery.infieldlabel.js
@@ -7,7 +7,7 @@
* Dual licensed under the MIT and GPL licenses, see:
* http://docs.jquery.com/License
*
- * @version 0.2
+ * @version 0.2.1
*/
(function ($) {
@@ -136,7 +136,8 @@
// Find input or textarea based on for= attribute
// The for attribute on the label must contain the ID
// of the input or textarea element
- var for_attr = this.getAttribute('for'), field, valid = true;
+ var for_attr = this.getAttribute('for') || this.htmlFor,
+ field, valid = true;
if (!for_attr) {
return; // Nothing to attach, since the for field wasn't used
}
View
4 src/jquery.infieldlabel.min.js
@@ -1,5 +1,5 @@
/**
- * In-Field Label jQuery Plugin v0.2
+ * In-Field Label jQuery Plugin v0.2.1
* http://fuelyourcoding.com/scripts/infield.html
* http://github.com/streetpc/jquery-infieldlabels
*
@@ -7,4 +7,4 @@
* Dual licensed under the MIT and GPL licenses, see:
* http://docs.jquery.com/License
*/
-(function(f){var d=0,a=1,b=2,g=/^(?:text|password|search|number|tel|url|email|date(?:time(?:-local)?)?|time|month|week)?$/,c=function(i,h){return(i<<3)|h},e={};e[c(a,d)]=function(h){h.fadeTo(1)};e[c(b,d)]=function(h){h.$label.css({opacity:1}).show();h.emptied(true)};e[c(d,a)]=function(h){h.fadeTo(h.options.fadeOpacity)};e[c(b,a)]=function(h){h.$label.css({opacity:h.options.fadeOpacity}).show();h.emptied(true)};e[c(d,b)]=function(h){h.$label.hide();h.emptied(false)};e[c(a,b)]=e[c(d,b)];f.InFieldLabels=function(i,k,h){var j=this;j.$label=f(i);j.label=i;j.$field=f(k);j.field=k;j.$label.data("InFieldLabels",j);j.state=d;j.init=function(){j.options=f.extend({},f.InFieldLabels.defaultOptions,h);if(j.options.labelClass){j.$label.addClass(j.options.labelClass)}if(j.options.disableAutocomplete){j.$field.attr("autocomplete","off")}j.$field.bind("blur focus change keyup.infield cut",j.updateState).bind("paste",function(l){j.setState(b)});j.updateState()};j.emptied=function(l){if(!j.options.emptyWatch){if(l){j.$field.bind("keyup.infield",j.updateState)}else{j.$field.unbind("keyup.infield",j.updateState)}}};j.fadeTo=function(l){if(!j.options.fadeDuration){j.$label.css({opacity:l})}else{j.$label.stop().animate({opacity:l},j.options.fadeDuration)}};j.updateState=function(o,m){var n=b;if(j.field.value===""){var l=o&&o.type;if(l==="focus"||l==="keyup"){l=true}else{if(l==="blur"||l==="change"){l=false}else{l=j.$field.is(":focus")}}n=l?a:d}j.setState(n,m)};j.setState=function(m,l){if(m===j.state){return}var n=e[c(j.state,m)];if(typeof n==="function"){n(j);j.state=m}else{l||j.updateState(null,true)}};j.init()};f.InFieldLabels.defaultOptions={emptyWatch:true,disableAutocomplete:true,fadeOpacity:0.5,fadeDuration:300,labelClass:"in-field"};f.fn.inFieldLabels=function(h){return this.each(function(){if(this.tagName!=="LABEL"){return}var k=this.getAttribute("for"),j,i=true;if(!k){return}j=document.getElementById(k);if(!j){return}if(j.tagName==="INPUT"){i=g.test(j.type.toLowerCase())}else{if(j.tagName!=="TEXTAREA"){i=false}}i=i&&!j.getAttribute("placeholder");if(!i){return}(new f.InFieldLabels(this,j,h))})}}(jQuery));
+(function(f){var d=0,a=1,b=2,g=/^(?:text|password|search|number|tel|url|email|date(?:time(?:-local)?)?|time|month|week)?$/,c=function(i,h){return(i<<3)|h},e={};e[c(a,d)]=function(h){h.fadeTo(1)};e[c(b,d)]=function(h){h.$label.css({opacity:1}).show();h.emptied(true)};e[c(d,a)]=function(h){h.fadeTo(h.options.fadeOpacity)};e[c(b,a)]=function(h){h.$label.css({opacity:h.options.fadeOpacity}).show();h.emptied(true)};e[c(d,b)]=function(h){h.$label.hide();h.emptied(false)};e[c(a,b)]=e[c(d,b)];f.InFieldLabels=function(i,k,h){var j=this;j.$label=f(i);j.label=i;j.$field=f(k);j.field=k;j.$label.data("InFieldLabels",j);j.state=d;j.init=function(){j.options=f.extend({},f.InFieldLabels.defaultOptions,h);if(j.options.labelClass){j.$label.addClass(j.options.labelClass)}if(j.options.disableAutocomplete){j.$field.attr("autocomplete","off")}j.$field.bind("blur focus change keyup.infield cut",j.updateState).bind("paste",function(l){j.setState(b)});j.updateState()};j.emptied=function(l){if(!j.options.emptyWatch){if(l){j.$field.bind("keyup.infield",j.updateState)}else{j.$field.unbind("keyup.infield",j.updateState)}}};j.fadeTo=function(l){if(!j.options.fadeDuration){j.$label.css({opacity:l})}else{j.$label.stop().animate({opacity:l},j.options.fadeDuration)}};j.updateState=function(o,m){var n=b;if(j.field.value===""){var l=o&&o.type;if(l==="focus"||l==="keyup"){l=true}else{if(l==="blur"||l==="change"){l=false}else{l=j.$field.is(":focus")}}n=l?a:d}j.setState(n,m)};j.setState=function(m,l){if(m===j.state){return}var n=e[c(j.state,m)];if(typeof n==="function"){n(j);j.state=m}else{l||j.updateState(null,true)}};j.init()};f.InFieldLabels.defaultOptions={emptyWatch:true,disableAutocomplete:true,fadeOpacity:0.5,fadeDuration:300,labelClass:"in-field"};f.fn.inFieldLabels=function(h){return this.each(function(){if(this.tagName!=="LABEL"){return}var k=this.getAttribute("for")||this.htmlFor,j,i=true;if(!k){return}j=document.getElementById(k);if(!j){return}if(j.tagName==="INPUT"){i=g.test(j.type.toLowerCase())}else{if(j.tagName!=="TEXTAREA"){i=false}}i=i&&!j.getAttribute("placeholder");if(!i){return}(new f.InFieldLabels(this,j,h))})}}(jQuery));

0 comments on commit 73aa4d4

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