From cdb6e7f3bf98eed46a28fa106af9ba7833448aef Mon Sep 17 00:00:00 2001
From: Nathan Vonnahme
Date: Thu, 9 Feb 2012 09:13:02 -0900
Subject: [PATCH 01/56] I want to see a working demo, not just read about it,
you know? Nice idea and implementation BTW.
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index a30b642..3cc5846 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,10 @@ This method only really works for the following: input[type="text"], input[type=
☨ Uses the easing plugin if available.
+## SHOW ME TEH DEMO
+
+See [my Get In Touch page](http://remy.bach.me.uk/get-in-touch/) for a work-in-progress demo.
+
## Usage
You need to make sure that the element containing both the field and the label has `position:relative;`. Other than that, the plugin should have enough flexibility to handle most of your needs.
From 10b7bce58c69aa0a9ebf19a6aed29bdddd1ef4d9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Thu, 9 Feb 2012 21:35:18 +0000
Subject: [PATCH 02/56] Update the Demo section.
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 3cc5846..dbc094e 100644
--- a/README.md
+++ b/README.md
@@ -8,9 +8,9 @@ This method only really works for the following: input[type="text"], input[type=
☨ Uses the easing plugin if available.
-## SHOW ME TEH DEMO
+## Demo
-See [my Get In Touch page](http://remy.bach.me.uk/get-in-touch/) for a work-in-progress demo.
+If you want to see a kind of demo of how it works, check out the [‘get in touch’](http://remy.bach.me.uk/get-in-touch/) page on my site which uses a version I’m working on that has a tooltip feature rolled in as well.
## Usage
From 3a5874df35ba68cf353541d2d9ec0c419ae9b012 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Sun, 12 Feb 2012 17:56:54 +0000
Subject: [PATCH 03/56] Fix bug where non elements stopped working.
---
jquery.superLabels.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 43715ec..a6d5b9e 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -45,7 +45,7 @@
var _field = $(this);
// Don't even bother going further if this isn't one of the accepted input field types or elements.
- if ($.inArray(_field.attr('type'), acceptedInputTypes) === -1 && $.inArray(_field[0].tagName.toLowerCase(), acceptedElements) !== -1) {
+ if ((_field[0].tagName.toLowerCase() === 'input' && $.inArray(_field.attr('type'), acceptedInputTypes)) === -1 && $.inArray(_field[0].tagName.toLowerCase(), acceptedElements) !== -1) {
_info('Doh! The following '+this.tagName.toLowerCase()+', is not supported.', this);
return true; // Equivalent to continue in a normal for loop.
}
From 6aa249e60f0230ccd809e4929c5af51925ca307b Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Sun, 12 Feb 2012 18:32:37 +0000
Subject: [PATCH 04/56] Link to new Demo (one that _actually_ uses this version
and not the older one I currently use on my site)
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index dbc094e..f49a434 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ This method only really works for the following: input[type="text"], input[type=
## Demo
-If you want to see a kind of demo of how it works, check out the [‘get in touch’](http://remy.bach.me.uk/get-in-touch/) page on my site which uses a version I’m working on that has a tooltip feature rolled in as well.
+Here's a (very) [simple demo](http://remy.bach.me.uk/superlabels_demo/) of Super Labels in action.
## Usage
From ede27af6ebfcd72e30a9325ddcefbb24fa33b5b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 5 Mar 2012 10:28:44 +0000
Subject: [PATCH 05/56] Add a noAnimate option that will just hide/show the
label (identical in function to a normal HTML5 placeholder)
---
jquery.superLabels.js | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index a6d5b9e..7c7fecd 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -17,6 +17,7 @@
fadeDuration:250, // Duration of animation when it's fade only.
labelLeft:0, // The distance from the left for the label.
labelTop:0, // The distance from the top for the label.
+ noAnimate:false, // Whether or not to animate (slide and fade) the label. If true, we'll just hide it.
opacity:0.5, // The opacity to fade the label to.
slide:true, // Whether or not to slide the label across the input field.
wrapSelector:false // The selector for the element you have wrapping each field.
@@ -140,6 +141,11 @@
var _duration = defaults.duration;
var _label = _getLabel(this);
var _to ={ opacity:0 };
+
+ if (defaults.noAnimate) {
+ _label.hide();
+ return false;
+ }
if (defaults.slide) {
_to.left = $(this).width()-_label.width();
@@ -154,7 +160,13 @@
_blur = function() {
if (_noVal(this) ) {
var _duration = defaults.duration;
+ var _label = _getLabel(this);
var _to ={ opacity:1 };
+
+ if (defaults.noAnimate) {
+ _label.show();
+ return false;
+ }
if (defaults.slide) {
_to.left = defaults.labelLeft;
@@ -162,7 +174,7 @@
_duration = defaults.fadeDuration;
}
- _getLabel(this).animate(_to, _duration, defaults.easingOut);
+ _label.animate(_to, _duration, defaults.easingOut);
}
};
_keyup = function() {
@@ -174,11 +186,17 @@
return false;
}
+
// If the field is empty and the label isn't showing, make it show up again.
if (_noVal(this) && !_label.css('opacity') == 0) {
+ if (defaults.noAnimate) {
+ _label.show();
+ return false;
+ }
+
_o = defaults.opacity;
}
-
+
_label.animate({ opacity:_o }, defaults.fadeDuration, defaults.easingOut);
};
From 8d78f1cc599ed0be48385fe0335b07c41be58248 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 5 Mar 2012 10:32:36 +0000
Subject: [PATCH 06/56] Add new noAnimate option!
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index f49a434..371376f 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,8 @@ There are quite a number of options you can pass the plugin additional to the tw
* `easingIn` - The easing in function to use for the slide. _(default: 'easeInOutCubic')_
* `easingOut` - The easing out function to use for the slide. _(default: 'easeInOutCubic')_
* `fadeDuration` - Duration of animation when it's fade only. _(default: 250)_
+* `noAnimate` - Whether or not to animate. If set to true, will function the same as a normal placeholder. _(default:false)_
+ * This is a 'just in case' option that can/should be used when there are performance issues with animating.
* `opacity` - The opacity to fade the label to. _(default: 0.5)_
* `labelLeft` - The distance from the left for the label. _(default: 0)_
* `labelTop` - The distance from the top for the label. _(default: 0)_
From d6f8f611399da1864626f3aa213eeb7b513b9d2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 5 Mar 2012 10:51:32 +0000
Subject: [PATCH 07/56] Don't bother trying to show the label again on keyup if
noAnimate is true.
---
jquery.superLabels.js | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 7c7fecd..6974125 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -178,6 +178,8 @@
}
};
_keyup = function() {
+ if (defaults.noAnimate) return false; // We don't need any keyup checking done if we're not animating (the label would be in the way while trying to type).
+
var _label = _getLabel(this);
var _o = 0;
@@ -189,11 +191,6 @@
// If the field is empty and the label isn't showing, make it show up again.
if (_noVal(this) && !_label.css('opacity') == 0) {
- if (defaults.noAnimate) {
- _label.show();
- return false;
- }
-
_o = defaults.opacity;
}
From 06ba617c97d7d189fb5bbef467f23cd0fbd8bc3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 5 Mar 2012 10:54:53 +0000
Subject: [PATCH 08/56] Pedantic update to the ordering of the options.
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 371376f..e839752 100644
--- a/README.md
+++ b/README.md
@@ -41,11 +41,11 @@ There are quite a number of options you can pass the plugin additional to the tw
* `easingIn` - The easing in function to use for the slide. _(default: 'easeInOutCubic')_
* `easingOut` - The easing out function to use for the slide. _(default: 'easeInOutCubic')_
* `fadeDuration` - Duration of animation when it's fade only. _(default: 250)_
+* `labelLeft` - The distance from the left for the label. _(default: 0)_
+* `labelTop` - The distance from the top for the label. _(default: 0)_
* `noAnimate` - Whether or not to animate. If set to true, will function the same as a normal placeholder. _(default:false)_
* This is a 'just in case' option that can/should be used when there are performance issues with animating.
* `opacity` - The opacity to fade the label to. _(default: 0.5)_
-* `labelLeft` - The distance from the left for the label. _(default: 0)_
-* `labelTop` - The distance from the top for the label. _(default: 0)_
* `slide` - Whether or not to slide the label across the input field. _(default: true)_
* `wrapSelector` - The selector for the element you have wrapping each field. _(default: false)_
* This is used to find the label - use as a last resort. Rather make sure the field and label are next to each other in your markup, or failing that, that your labels use the `for` attribute that point to the field's `name` or `id`.
From fc1091dfe48ccf6acd19f09692164a2ffaef45c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Thu, 15 Mar 2012 13:16:03 +0000
Subject: [PATCH 09/56] Remove any NaNs from the left and top positions (so you
could pass in '5px' for example)
---
jquery.superLabels.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 6974125..e225f59 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -29,6 +29,10 @@
$.fn.superLabels = function(options) {
// If this has been run on an empty set of elements, pop out.
if (this.length === 0) return false;
+
+ // Remove any NaNs from the left and top positions (so you could pass in 5px for example)
+ options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
+ options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
// If options were passed in, merge them with the defaults.
$.extend(defaults, options || {});
From 02710c36bbac672d99b777915a21e0123e98973c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Thu, 15 Mar 2012 13:18:16 +0000
Subject: [PATCH 10/56] Update the labelLeft and labelTop description to
mention ability to pass values with 'px'.
---
README.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/README.md b/README.md
index e839752..c34b253 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,9 @@ There are quite a number of options you can pass the plugin additional to the tw
* `easingOut` - The easing out function to use for the slide. _(default: 'easeInOutCubic')_
* `fadeDuration` - Duration of animation when it's fade only. _(default: 250)_
* `labelLeft` - The distance from the left for the label. _(default: 0)_
+ * You can pass in 'px' if you're the pedantic type. For example: `labelLeft:'5px'`
* `labelTop` - The distance from the top for the label. _(default: 0)_
+ * As above: `labelTop:'5px'`
* `noAnimate` - Whether or not to animate. If set to true, will function the same as a normal placeholder. _(default:false)_
* This is a 'just in case' option that can/should be used when there are performance issues with animating.
* `opacity` - The opacity to fade the label to. _(default: 0.5)_
From 3a49b36424ce9e627d7a9522f98d27186ef2f6c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Thu, 15 Mar 2012 13:32:36 +0000
Subject: [PATCH 11/56] Doh! Actually check whether labelLeft or labelTop are
NOT numbers before trying to pull out the numbers.
---
jquery.superLabels.js | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index e225f59..38848ec 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -30,9 +30,11 @@
// If this has been run on an empty set of elements, pop out.
if (this.length === 0) return false;
- // Remove any NaNs from the left and top positions (so you could pass in 5px for example)
- options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
- options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
+ // Remove any NaNs from the positions (if present)
+ if (isNaN(options.labelLeft))
+ options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
+ if (isNaN(options.labelTop))
+ options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
// If options were passed in, merge them with the defaults.
$.extend(defaults, options || {});
From 3e1eddb09fa5871d28a8a7e4f8e8f626266b4214 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 19 Mar 2012 23:05:21 +0000
Subject: [PATCH 12/56] Bug fix on the new 'passing in px' functionality.
---
jquery.superLabels.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 38848ec..2e6efa6 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -31,9 +31,9 @@
if (this.length === 0) return false;
// Remove any NaNs from the positions (if present)
- if (isNaN(options.labelLeft))
+ if (options && options.labelLeft && isNaN(options.labelLeft))
options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
- if (isNaN(options.labelTop))
+ if (options && options.labelTop && isNaN(options.labelTop))
options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
// If options were passed in, merge them with the defaults.
From 793b840ce856898e193bec9a23890c20462a912e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 28 Mar 2012 12:20:13 +0200
Subject: [PATCH 13/56] Include the 'number' input type.
---
jquery.superLabels.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 2e6efa6..085f646 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -23,7 +23,7 @@
wrapSelector:false // The selector for the element you have wrapping each field.
};
- var acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password'];
+ var acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password', 'number'];
var acceptedElements = ['input', 'textarea', 'select'];
$.fn.superLabels = function(options) {
From 291b972e1d175c1526be60abdfb9039864e5752b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 28 Mar 2012 13:49:44 +0200
Subject: [PATCH 14/56] Add input[type="number"] to the supported input types.
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c34b253..cee1e47 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
This plugin was born out of the need to use the label-over-field method for forms I was working on. There are other plugins out there that do pretty much the same thing, but none of them had the - for lack of a better word - sexiness that I was looking for. This implementation makes the label slide across the field☨ when gaining focus and fade out when a value is entered.
-This method only really works for the following: input[type="text"], input[type="search"], input[type="url"], input[type="tel"], input[type="email"], input[type="password"], textarea, and even on select fields.
+This method only really works for the following: input[type="text"], input[type="search"], input[type="url"], input[type="tel"], input[type="email"], input[type="password"], input[type="number"], textarea, and finally there's select field support thrown in too.
☨ Uses the easing plugin if available.
From 1358b69e102f97d88cdf289fd679469df5d30709 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Mon, 2 Apr 2012 18:19:51 +0200
Subject: [PATCH 15/56] Fix bug where the labels weren't showing up again after
having been pre-filled.
---
jquery.superLabels.js | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 085f646..e9e6a01 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -128,12 +128,10 @@
_label.css('display','none');
} else {
- // If the field already has a value, then hide the label.
- if (!_noVal(_field)) _label.hide();
-
_field.css({ zIndex:defaults.baseZindex+1 }).addClass('sl_field');
_label.css({
- left:defaults.labelLeft,
+ left:_noVal(_field) ? defaults.labelLeft : $(_field).width()-_label.width(),
+ opacity:_noVal(_field) ? 1 : 0,
position:'absolute',
top:defaults.labelTop,
zIndex:defaults.baseZindex+2
@@ -190,13 +188,13 @@
var _o = 0;
// Let's check whether there's even a need to animate anything first.
- if ((_noVal(this) && _label.css('opacity') > 0) || (!_noVal(this) && _label.css('opacity') == 0 )) {
+ if ((_noVal(this) && _label.css('opacity') > 0) || (!_noVal(this) && _label.css('opacity') === 0 )) {
return false;
}
// If the field is empty and the label isn't showing, make it show up again.
- if (_noVal(this) && !_label.css('opacity') == 0) {
+ if (_noVal(this) && _label.css('opacity') !== 0) {
_o = defaults.opacity;
}
From 74d7d12c0a220ddfa08d019cac80c7fc9339f91b Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Wed, 4 Apr 2012 13:26:14 +0100
Subject: [PATCH 16/56] Version bump.
---
jquery.superLabels.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index e9e6a01..7c46949 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.0
+ * Version: 1.0.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
From 7da00469594881cc3561c7f25a4e48f420afd293 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Wed, 4 Apr 2012 13:27:20 +0100
Subject: [PATCH 17/56] Add minified version.
---
README.md | 1 +
jquery.superLabels.min.js | 10 ++++++++++
2 files changed, 11 insertions(+)
create mode 100644 jquery.superLabels.min.js
diff --git a/README.md b/README.md
index cee1e47..7ac44d4 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,7 @@ There are quite a number of options you can pass the plugin additional to the tw
* `baseZindex` - The base z-index which we display on top of. _(default: 0)_
* `debug` - Whether or not to show console messages. _(default: false)_
+ * Note: this is not available in the minified version.
* `duration` - Time of the slide in milliseconds. _(default: 500)_
* `easingIn` - The easing in function to use for the slide. _(default: 'easeInOutCubic')_
* `easingOut` - The easing out function to use for the slide. _(default: 'easeInOutCubic')_
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
new file mode 100644
index 0000000..a316844
--- /dev/null
+++ b/jquery.superLabels.min.js
@@ -0,0 +1,10 @@
+/*
+ * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
+ * Author: Rémy Bach
+ * Version: 1.0.1
+ * License: http://remybach.mit-license.org
+ * Url: http://github.com/remybach/jQuery.superLabels
+ * Description:
+ * This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
+ */
+(function(d){var c={baseZindex:0,duration:500,easingIn:(d.easing.def?'easeInOutCubic':false),easingOut:(d.easing.def?'easeInOutCubic':false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var j=['text','search','url','tel','email','password'];var g=['input','textarea','select'];d.fn.superLabels=function(f){if(this.length===0)return false;if(isNaN(f.labelLeft))f.labelLeft=Number(f.labelLeft.replace(/\D+/,''));if(isNaN(f.labelTop))f.labelTop=Number(f.labelTop.replace(/\D+/,''));d.extend(c,f||{});var h=this;if(this.length===1&&this[0].tagName.match(/form/i)){h=d(g.join(','),this)}return h.each(function(){var a=d(this);if((a[0].tagName.toLowerCase()==='input'&&d.inArray(a.attr('type'),j))===-1&&d.inArray(a[0].tagName.toLowerCase(),g)!==-1){return true}var b=_1(this);var e=a.attr('placeholder');if(e){var i=d(''+e+'');if(b.length===0){b=i;a.prev(b)}else{b.replaceWith(i)}a.removeAttr('placeholder')}if(b.length===0){return true}_2(a,b);if(!this.tagName.match(/select/i)){a.focus(_3);a.blur(_4);a.keyup(_5);b.click(function(){a.focus()})}})};_1=function(a){var b=d(a).siblings('label');if(b.length===0){if(c.wrapSelector){b=d(a).parents(c.wrapSelector).find('label')}else{_6=a.id||a.name;b=d('[for="'+_6+'"]')}}return b};_2=function(a,b){if(a[0].tagName.match(/select/i)){var e=a.find('[selected]').length===0?' selected':'';a.prepend('');b.css('display','none')}else{a.css({zIndex:c.baseZindex+1}).addClass('sl_field');b.css({left:_0(a)?c.labelLeft:d(a).width()-b.width(),opacity:_0(a)?1:0,position:'absolute',top:c.labelTop,zIndex:c.baseZindex+2}).addClass('sl_label')}};_3=function(){if(_0(this)){var a=c.duration;var b=_1(this);var e={opacity:0};if(c.noAnimate){b.hide();return false}if(c.slide){e.left=d(this).width()-b.width();e.opacity=c.opacity}else{a=c.fadeDuration}b.animate(e,a,c.easingOut)}};_4=function(){if(_0(this)){var a=c.duration;var b=_1(this);var e={opacity:1};if(c.noAnimate){b.show();return false}if(c.slide){e.left=c.labelLeft}else{a=c.fadeDuration}b.animate(e,a,c.easingOut)}};_5=function(){var a=_1(this);var b=0;if((_0(this)&&a.css('opacity')>0)||(!_0(this)&&a.css('opacity')===0)){return false}if(_0(this)&&a.css('opacity')!==0){if(c.noAnimate){a.show();return false}b=c.opacity}a.animate({opacity:b},c.fadeDuration,c.easingOut)};_0=function(a){return d(a).val()===''}})(jQuery);
\ No newline at end of file
From ddf4c7d7cbcc535db7604d6e376efa1e7acfd016 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Mon, 16 Apr 2012 10:14:24 +0100
Subject: [PATCH 18/56] Make the field change functionality a bit more
comprehensive.
Includes checking for the 'onpropertychange' event (props to @davatron5000 for that one).
---
jquery.superLabels.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 7c46949..91e52e1 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -89,6 +89,8 @@
_field.focus(_focus);
// What happens when we leave the field.
_field.blur(_blur);
+ _field.change(_blur);
+ _field.bind('propertychange', _blur);
// Check for when the user is typing
_field.keyup(_keyup);
// Make sure the field gets focus when the label is clicked on (for those people who don't use the 'for' attribute and deserve a kick to the face).
From cf47e5c1c4e338897a7b56e348c1ceab31adf899 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Mon, 16 Apr 2012 10:15:08 +0100
Subject: [PATCH 19/56] Updated minified version.
---
jquery.superLabels.min.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index a316844..55ed021 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -7,4 +7,4 @@
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(d){var c={baseZindex:0,duration:500,easingIn:(d.easing.def?'easeInOutCubic':false),easingOut:(d.easing.def?'easeInOutCubic':false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var j=['text','search','url','tel','email','password'];var g=['input','textarea','select'];d.fn.superLabels=function(f){if(this.length===0)return false;if(isNaN(f.labelLeft))f.labelLeft=Number(f.labelLeft.replace(/\D+/,''));if(isNaN(f.labelTop))f.labelTop=Number(f.labelTop.replace(/\D+/,''));d.extend(c,f||{});var h=this;if(this.length===1&&this[0].tagName.match(/form/i)){h=d(g.join(','),this)}return h.each(function(){var a=d(this);if((a[0].tagName.toLowerCase()==='input'&&d.inArray(a.attr('type'),j))===-1&&d.inArray(a[0].tagName.toLowerCase(),g)!==-1){return true}var b=_1(this);var e=a.attr('placeholder');if(e){var i=d(''+e+'');if(b.length===0){b=i;a.prev(b)}else{b.replaceWith(i)}a.removeAttr('placeholder')}if(b.length===0){return true}_2(a,b);if(!this.tagName.match(/select/i)){a.focus(_3);a.blur(_4);a.keyup(_5);b.click(function(){a.focus()})}})};_1=function(a){var b=d(a).siblings('label');if(b.length===0){if(c.wrapSelector){b=d(a).parents(c.wrapSelector).find('label')}else{_6=a.id||a.name;b=d('[for="'+_6+'"]')}}return b};_2=function(a,b){if(a[0].tagName.match(/select/i)){var e=a.find('[selected]').length===0?' selected':'';a.prepend('');b.css('display','none')}else{a.css({zIndex:c.baseZindex+1}).addClass('sl_field');b.css({left:_0(a)?c.labelLeft:d(a).width()-b.width(),opacity:_0(a)?1:0,position:'absolute',top:c.labelTop,zIndex:c.baseZindex+2}).addClass('sl_label')}};_3=function(){if(_0(this)){var a=c.duration;var b=_1(this);var e={opacity:0};if(c.noAnimate){b.hide();return false}if(c.slide){e.left=d(this).width()-b.width();e.opacity=c.opacity}else{a=c.fadeDuration}b.animate(e,a,c.easingOut)}};_4=function(){if(_0(this)){var a=c.duration;var b=_1(this);var e={opacity:1};if(c.noAnimate){b.show();return false}if(c.slide){e.left=c.labelLeft}else{a=c.fadeDuration}b.animate(e,a,c.easingOut)}};_5=function(){var a=_1(this);var b=0;if((_0(this)&&a.css('opacity')>0)||(!_0(this)&&a.css('opacity')===0)){return false}if(_0(this)&&a.css('opacity')!==0){if(c.noAnimate){a.show();return false}b=c.opacity}a.animate({opacity:b},c.fadeDuration,c.easingOut)};_0=function(a){return d(a).val()===''}})(jQuery);
\ No newline at end of file
+(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=a(d.join(","),this)}return f.each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){_info("Doh! The following "+this.tagName.toLowerCase()+", is not supported.",this);return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){var g=a('");if(e.length===0){e=g;b.prev(e)}else{e.replaceWith(g)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
From 13150ce23e7512580138f9ea0ddcb7c5e208b2da Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Fri, 20 Apr 2012 16:37:04 +0100
Subject: [PATCH 20/56] Fix call to undefined _info function.
---
jquery.superLabels.min.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 55ed021..bf11922 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -7,4 +7,4 @@
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=a(d.join(","),this)}return f.each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){_info("Doh! The following "+this.tagName.toLowerCase()+", is not supported.",this);return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){var g=a('");if(e.length===0){e=g;b.prev(e)}else{e.replaceWith(g)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
+(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
From 559a9339a8aebb08075bf6314643adbd6c69b9de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 23 May 2012 21:18:10 +0200
Subject: [PATCH 21/56] Add note about loading superLabels *after* DOM ready.
---
README.md | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7ac44d4..2025583 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,10 @@ You need to make sure that the element containing both the field and the label h
The quickest and easiest way to use this plugin is as follows:
- $('form').superLabels();
+ // Don't forget to do this *after* the DOM has loaded.
+ jQuery(function($) {
+ $('form').superLabels();
+ });
Running the plugin on a form will automatically apply the magic to the accepted fields listed above.
From a5f2841927a4023740facb267d310057b1f5d18e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 23 May 2012 21:19:09 +0200
Subject: [PATCH 22/56] Safety ; (sigh)
---
jquery.superLabels.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 91e52e1..f17f72b 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -7,7 +7,7 @@
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function($) {
+;(function($) {
var defaults = {
baseZindex:0, // The base z-index which we display on top of.
debug:false,
From c46f3b5756eb63e62d29bdf6dc9cd2d29bc105e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 23 May 2012 21:19:27 +0200
Subject: [PATCH 23/56] Safety ; (sigh)
---
jquery.superLabels.min.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index bf11922..8f64a77 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -7,4 +7,4 @@
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
+;(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
From 5735aafdddce91370ed5870fea2743446abfa74c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Sat, 30 Jun 2012 13:59:38 +0200
Subject: [PATCH 24/56] Add links to bug reports regarding the auto fill issue.
(One filed for Chrome and another found for Firefox)
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 2025583..fb8b53d 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ There are quite a number of options you can pass the plugin additional to the tw
Below I'll list any bugs that I'm aware of and will try to get around to fixing as soon as I can.
-* Auto filling of form fields that is performed by some browsers causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value.
+* Auto filling of form fields that is performed by some browsers causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value. I've submitted a bug report for Chrome [here](https://code.google.com/p/chromium/issues/detail?id=135307), and have found a bug report for Firefox [here](https://bugzilla.mozilla.org/show_bug.cgi?id=184761).
#### License
From af1c9140d9d445eced77e672029c5a4e11930c16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Sun, 1 Jul 2012 09:54:07 +0200
Subject: [PATCH 25/56] Fix the autofill bug in chrome + version bump!
(Woooooooooo)
---
jquery.superLabels.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index f17f72b..6db9bac 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.0.1
+ * Version: 1.0.2
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
@@ -90,6 +90,8 @@
// What happens when we leave the field.
_field.blur(_blur);
_field.change(_blur);
+ // Autofil bug fixes
+ _field.bind('input', _keyup); // For the currently selected field.
_field.bind('propertychange', _blur);
// Check for when the user is typing
_field.keyup(_keyup);
@@ -164,7 +166,7 @@
}
};
_blur = function() {
- if (_noVal(this) ) {
+ if (_noVal(this)) {
var _duration = defaults.duration;
var _label = _getLabel(this);
var _to ={ opacity:1 };
@@ -181,6 +183,9 @@
}
_label.animate(_to, _duration, defaults.easingOut);
+ } else {
+ // If there is a value, and the label is visible, fire our _keyup function so as to hide it. (this semi-fixes the autofill bug)
+ _keyup.apply(this);
}
};
_keyup = function() {
From 62fc36e271aa354c38c3f19410c97ff9de857485 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Sun, 1 Jul 2012 09:55:03 +0200
Subject: [PATCH 26/56] Updated minified version with Chrome autofill fix.
---
jquery.superLabels.min.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 8f64a77..dbea4ef 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
/*
- * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
- * Author: Rémy Bach
- * Version: 1.0.1
+ * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
+ * Author: Rémy Bach
+ * Version: 1.0.2
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-;(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
+;(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("input",_keyup);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
From a07920e8266cdcca7e571a551ced6ee6fac0b18b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Sun, 1 Jul 2012 09:56:12 +0200
Subject: [PATCH 27/56] Remove mention of chrome bug report.
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index fb8b53d..e0a67d4 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ There are quite a number of options you can pass the plugin additional to the tw
Below I'll list any bugs that I'm aware of and will try to get around to fixing as soon as I can.
-* Auto filling of form fields that is performed by some browsers causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value. I've submitted a bug report for Chrome [here](https://code.google.com/p/chromium/issues/detail?id=135307), and have found a bug report for Firefox [here](https://bugzilla.mozilla.org/show_bug.cgi?id=184761).
+* Auto filling of form fields that is performed by some browsers (other than Chrome) causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value. I've found a bug report for Firefox [here](https://bugzilla.mozilla.org/show_bug.cgi?id=184761).
#### License
From f696ff90c00858329a8eb3648a5abf7e858dbf4c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Fri, 10 Aug 2012 11:54:35 +0200
Subject: [PATCH 28/56] Add note about ability to select individual fields
---
README.md | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/README.md b/README.md
index e0a67d4..89d8054 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,10 @@ If you find that you need to position the labels slightly differently, pass in `
labelTop:5
});
+Lastly, you can choose to ONLY apply superLabels to specific fields if you wish by selecting them instead of the form as follows:
+
+ $('input.foo, textarea.bar, select.baz').superLabels();
+
#### Advanced
There are quite a number of options you can pass the plugin additional to the two I mentioned above:
From 4f1e48eb0d432376668e4e1731952992b7b8670b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 15 Aug 2012 15:08:16 +0200
Subject: [PATCH 29/56] You can now pass more than one form!
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
`$('.form1, .form2').superLabels();` now works as well as a mixture of forms and labels as follows:
$('.form1, .form2 input').superLabels();
---
jquery.superLabels.js | 47 ++++++++++++++++++++++++++-----------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 6db9bac..28d69ff 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.0.2
+ * Version: 1.1.0
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
@@ -27,6 +27,8 @@
var acceptedElements = ['input', 'textarea', 'select'];
$.fn.superLabels = function(options) {
+ var _fields = [];
+
// If this has been run on an empty set of elements, pop out.
if (this.length === 0) return false;
@@ -35,22 +37,31 @@
options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
if (options && options.labelTop && isNaN(options.labelTop))
options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
-
+
// If options were passed in, merge them with the defaults.
$.extend(defaults, options || {});
if (!$.easing.def) { _info('Easing plugin not found - using standard jQuery animations.'); }
- var _fields = this;
-
- // Check for whether the user has just passed in the form. If so, we need to fetch all the accepted fields, etc..
- if (this.length === 1 && this[0].tagName.match(/form/i)) {
+ // Check for whether the user has just passed in the form. If so, we need to fetch all the accepted fields.
+ if (this.length === 1 && /form/i.test(this[0].tagName)) {
_fields = $(acceptedElements.join(','), this);
+ } else if (this.length > 1) { // we need to extrapolate these fields
+ this.each(function() {
+ if (/form/i.test(this.tagName)) { // if this is a form merge the accepted elements into the _fields array.
+ $.merge(_fields, $(acceptedElements.join(','), this));
+ } else {
+ // This is a normal field, so just dump this one in.
+ _fields.push(this);
+ }
+ });
+ } else { // If all else fails, assume the user passed in the fields individually
+ _fields = this;
}
// Do our magic on each form field.
- return _fields.each(function() {
+ return $(_fields).each(function() {
var _field = $(this);
-
+
// Don't even bother going further if this isn't one of the accepted input field types or elements.
if ((_field[0].tagName.toLowerCase() === 'input' && $.inArray(_field.attr('type'), acceptedInputTypes)) === -1 && $.inArray(_field[0].tagName.toLowerCase(), acceptedElements) !== -1) {
_info('Doh! The following '+this.tagName.toLowerCase()+', is not supported.', this);
@@ -73,7 +84,7 @@
}
_field.removeAttr('placeholder');
}
-
+
// Make sure this form field has a label
if (_label.length === 0) {
_info('Doh! The following '+this.tagName.toLowerCase()+' has no related label.', this);
@@ -82,7 +93,7 @@
// Position the labels above the form fields. Note:We do this here and not in the CSS for the purposes of progressive enhancement.
_prepLabel(_field, _label);
-
+
// Select boxes don't need to have any fancy label stuff done.
if (!this.tagName.match(/select/i)) {
// What happens when we enter the field
@@ -127,7 +138,7 @@
// before the page has loaded), so I'm going to assume that if the form is prefilled or values are remembered
// between page loads, then the [selected attribute will be used.
var _selected = _field.find('[selected]').length === 0 ? ' selected' : '';
-
+
_field.prepend('');
_label.css('display','none');
@@ -154,14 +165,14 @@
_label.hide();
return false;
}
-
+
if (defaults.slide) {
_to.left = $(this).width()-_label.width();
_to.opacity = defaults.opacity;
} else {
_duration = defaults.fadeDuration;
}
-
+
_label.animate(_to, _duration, defaults.easingOut);
}
};
@@ -175,13 +186,13 @@
_label.show();
return false;
}
-
+
if (defaults.slide) {
_to.left = defaults.labelLeft;
} else {
_duration = defaults.fadeDuration;
}
-
+
_label.animate(_to, _duration, defaults.easingOut);
} else {
// If there is a value, and the label is visible, fire our _keyup function so as to hide it. (this semi-fixes the autofill bug)
@@ -190,10 +201,10 @@
};
_keyup = function() {
if (defaults.noAnimate) return false; // We don't need any keyup checking done if we're not animating (the label would be in the way while trying to type).
-
+
var _label = _getLabel(this);
var _o = 0;
-
+
// Let's check whether there's even a need to animate anything first.
if ((_noVal(this) && _label.css('opacity') > 0) || (!_noVal(this) && _label.css('opacity') === 0 )) {
return false;
@@ -211,7 +222,7 @@
/*===== Utility Functions =====*/
// Tell us whether the form field has a value.
_noVal = function(_el) { return $(_el).val() === ''; };
-
+
// Console Functions (We need these to make sure this only displays when the console exists.)
_log = function() { if (defaults.debug && console && console.log) console.log.apply(console, arguments); };
_info = function() { if (defaults.debug && console && console.info) console.info.apply(console, arguments); };
From bea3ae5f2a532dfc30d6e5a1d127b5657f19625a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 15 Aug 2012 15:10:08 +0200
Subject: [PATCH 30/56] You can now pass more than one form!
---
jquery.superLabels.min.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index dbea4ef..06c0502 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
- * Author: Rémy Bach
- * Version: 1.0.2
+ * Author: Rémy Bach
+ * Version: 1.1.0
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-;(function(c){var d={baseZindex:0,duration:500,easingIn:(c.easing.def?"easeInOutCubic":false),easingOut:(c.easing.def?"easeInOutCubic":false),fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:0.5,slide:true,wrapSelector:false};var a=["text","search","url","tel","email","password","number"];var b=["input","textarea","select"];c.fn.superLabels=function(e){if(this.length===0){return false}if(e&&e.labelLeft&&isNaN(e.labelLeft)){e.labelLeft=Number(e.labelLeft.replace(/\D+/,""))}if(e&&e.labelTop&&isNaN(e.labelTop)){e.labelTop=Number(e.labelTop.replace(/\D+/,""))}c.extend(d,e||{});var f=this;if(this.length===1&&this[0].tagName.match(/form/i)){f=c(b.join(","),this)}return f.each(function(){var i=c(this);if((i[0].tagName.toLowerCase()==="input"&&c.inArray(i.attr("type"),a))===-1&&c.inArray(i[0].tagName.toLowerCase(),b)!==-1){return true}var j=_getLabel(this);var h=i.attr("placeholder");if(h){var g=c('");if(j.length===0){j=g;i.prev(j)}else{j.replaceWith(g)}i.removeAttr("placeholder")}if(j.length===0){return true}_prepLabel(i,j);if(!this.tagName.match(/select/i)){i.focus(_focus);i.blur(_blur);i.change(_blur);i.bind("input",_keyup);i.bind("propertychange",_blur);i.keyup(_keyup);j.click(function(){i.focus()})}})};_getLabel=function(e){var f=c(e).siblings("label");if(f.length===0){if(d.wrapSelector){f=c(e).parents(d.wrapSelector).find("label")}else{_for=e.id||e.name;f=c('[for="'+_for+'"]')}}return f};_prepLabel=function(e,g){if(e[0].tagName.match(/select/i)){var f=e.find("[selected]").length===0?" selected":"";e.prepend('");g.css("display","none")}else{e.css({zIndex:d.baseZindex+1}).addClass("sl_field");g.css({left:_noVal(e)?d.labelLeft:c(e).width()-g.width(),opacity:_noVal(e)?1:0,position:"absolute",top:d.labelTop,zIndex:d.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:0};if(d.noAnimate){f.hide();return false}if(d.slide){e.left=c(this).width()-f.width();e.opacity=d.opacity}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}};_blur=function(){if(_noVal(this)){var g=d.duration;var f=_getLabel(this);var e={opacity:1};if(d.noAnimate){f.show();return false}if(d.slide){e.left=d.labelLeft}else{g=d.fadeDuration}f.animate(e,g,d.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(d.noAnimate){return false}var f=_getLabel(this);var e=0;if((_noVal(this)&&f.css("opacity")>0)||(!_noVal(this)&&f.css("opacity")===0)){return false}if(_noVal(this)&&f.css("opacity")!==0){e=d.opacity}f.animate({opacity:e},d.fadeDuration,d.easingOut)};_noVal=function(e){return c(e).val()===""}})(jQuery);
\ No newline at end of file
+(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){var f=[];if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});if(this.length===1&&/form/i.test(this[0].tagName)){f=a(d.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){a.merge(f,a(d.join(","),this))}else{f.push(this)}})}else{f=this}return a(f).each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){var g=a('");if(e.length===0){e=g;b.prev(e)}else{e.replaceWith(g)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("input",_keyup);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
From 48d8b5954e01cca82d2775dfa14bba6a5844eb9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 15 Aug 2012 15:49:08 +0200
Subject: [PATCH 31/56] Fix the way placeholder works.
If there is a placeholder but NO label, the placeholder becomes the label.
If there is a placeholder AND a label, the placeholder becomes the title of the label (and thus shows up when you hover on the label).
---
jquery.superLabels.js | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 28d69ff..c91c65e 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.1.0
+ * Version: 1.1.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
@@ -71,16 +71,20 @@
var _label = _getLabel(this);
var _placeholder = _field.attr('placeholder');
- // Check for the placeholder attribute first.
+ // If there's a placeholder
if (_placeholder) {
- var _placeholderLabel = $('');
-
- // If there isn't a label for this field, create one, otherwise replace the existing one with the placeholder one.
+ // but NO label, make a label using the placeholder
if (_label.length === 0) {
+ var _placeholderLabel = '';
+ _placeholderLabel+= '';
+ _placeholderLabel = $(_placeholderLabel);
+
+ // If there isn't a label for this field, create one, otherwise replace the existing one with the placeholder one.
_label = _placeholderLabel;
- _field.prev(_label);
+ _field.before(_label);
} else {
- _label.replaceWith(_placeholderLabel);
+ // Otherwise, just give the label a title with the placeholder
+ _label.attr('title', _placeholder);
}
_field.removeAttr('placeholder');
}
From 842de28d1adaa75a8a87a41c79de1539d55e879e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 15 Aug 2012 15:50:23 +0200
Subject: [PATCH 32/56] Fix the way placeholder works.
---
jquery.superLabels.min.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 06c0502..5991a77 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.1.0
+ * Version: 1.1.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){var f=[];if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});if(this.length===1&&/form/i.test(this[0].tagName)){f=a(d.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){a.merge(f,a(d.join(","),this))}else{f.push(this)}})}else{f=this}return a(f).each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){var g=a('");if(e.length===0){e=g;b.prev(e)}else{e.replaceWith(g)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("input",_keyup);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
+(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){var f=[];if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});if(this.length===1&&/form/i.test(this[0].tagName)){f=a(d.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){a.merge(f,a(d.join(","),this))}else{f.push(this)}})}else{f=this}return a(f).each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){if(e.length===0){var g='";g+="";g=a(g);e=g;b.before(e)}else{e.attr("title",f)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("input",_keyup);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
From 92cfac76df442f18ba0a96bec3d69d36b152fe01 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Wed, 15 Aug 2012 16:00:46 +0200
Subject: [PATCH 33/56] Update with info about placeholders.
---
README.md | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 89d8054..65ec207 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ You need to make sure that the element containing both the field and the label h
The quickest and easiest way to use this plugin is as follows:
- // Don't forget to do this *after* the DOM has loaded.
+ // Don't forget to do this *after* the DOM has loaded.
jQuery(function($) {
$('form').superLabels();
});
@@ -60,7 +60,16 @@ There are quite a number of options you can pass the plugin additional to the tw
* `wrapSelector` - The selector for the element you have wrapping each field. _(default: false)_
* This is used to find the label - use as a last resort. Rather make sure the field and label are next to each other in your markup, or failing that, that your labels use the `for` attribute that point to the field's `name` or `id`.
-#### Known Bugs
+## Concerning placeholders
+
+According to [the spec](http://www.w3.org/wiki/HTML/Elements/input/text) placeholders are meant to be used to represent "a short hint (a word or short phrase) intended to aid the user with data entry." *NOT* as a replacement for labels.
+
+The way superLabels uses placeholders (as of version 1.1.1) is as follows:
+
+* If there is a label AND a placeholder for the field, the placeholder becomes the label's title so that it shows up when you hover over the label.
+* If there is JUST the placeholder, it becomes the label for the field.
+
+##Known Bugs
Below I'll list any bugs that I'm aware of and will try to get around to fixing as soon as I can.
@@ -68,4 +77,4 @@ Below I'll list any bugs that I'm aware of and will try to get around to fixing
#### License
-MIT License - [http://remybach.mit-license.org/](http://remybach.mit-license.org/ 'Link through to read my License.')
+MIT License - [http://remybach.mit-license.org/](http://remybach.mit-license.org/ 'Link through to read my License.')
\ No newline at end of file
From 428287a58bce4036a6599ed9e173844e0a45ea8b Mon Sep 17 00:00:00 2001
From: Francisc Romano
Date: Sat, 29 Sep 2012 02:11:31 +0300
Subject: [PATCH 34/56] Fixed label animation from queuing up.
---
jquery.superLabels.js | 6 +++---
jquery.superLabels.min.js | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index c91c65e..0d1b3b3 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -177,7 +177,7 @@
_duration = defaults.fadeDuration;
}
- _label.animate(_to, _duration, defaults.easingOut);
+ _label.stop(true,false).animate(_to, _duration, defaults.easingOut);
}
};
_blur = function() {
@@ -197,7 +197,7 @@
_duration = defaults.fadeDuration;
}
- _label.animate(_to, _duration, defaults.easingOut);
+ _label.stop(true,false).animate(_to, _duration, defaults.easingOut);
} else {
// If there is a value, and the label is visible, fire our _keyup function so as to hide it. (this semi-fixes the autofill bug)
_keyup.apply(this);
@@ -220,7 +220,7 @@
_o = defaults.opacity;
}
- _label.animate({ opacity:_o }, defaults.fadeDuration, defaults.easingOut);
+ _label.stop(true,false).animate({ opacity:_o }, defaults.fadeDuration, defaults.easingOut);
};
/*===== Utility Functions =====*/
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 5991a77..dbcd3cb 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -7,4 +7,4 @@
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){var f=[];if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});if(this.length===1&&/form/i.test(this[0].tagName)){f=a(d.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){a.merge(f,a(d.join(","),this))}else{f.push(this)}})}else{f=this}return a(f).each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){if(e.length===0){var g='";g+="";g=a(g);e=g;b.before(e)}else{e.attr("title",f)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("input",_keyup);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
+(function(a){var b={baseZindex:0,duration:500,easingIn:a.easing.def?"easeInOutCubic":false,easingOut:a.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var c=["text","search","url","tel","email","password","number"];var d=["input","textarea","select"];a.fn.superLabels=function(e){var f=[];if(this.length===0)return false;if(e&&e.labelLeft&&isNaN(e.labelLeft))e.labelLeft=Number(e.labelLeft.replace(/\D+/,""));if(e&&e.labelTop&&isNaN(e.labelTop))e.labelTop=Number(e.labelTop.replace(/\D+/,""));a.extend(b,e||{});if(this.length===1&&/form/i.test(this[0].tagName)){f=a(d.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){a.merge(f,a(d.join(","),this))}else{f.push(this)}})}else{f=this}return a(f).each(function(){var b=a(this);if((b[0].tagName.toLowerCase()==="input"&&a.inArray(b.attr("type"),c))===-1&&a.inArray(b[0].tagName.toLowerCase(),d)!==-1){return true}var e=_getLabel(this);var f=b.attr("placeholder");if(f){if(e.length===0){var g='";g+="";g=a(g);e=g;b.before(e)}else{e.attr("title",f)}b.removeAttr("placeholder")}if(e.length===0){return true}_prepLabel(b,e);if(!this.tagName.match(/select/i)){b.focus(_focus);b.blur(_blur);b.change(_blur);b.bind("input",_keyup);b.bind("propertychange",_blur);b.keyup(_keyup);e.click(function(){b.focus()})}})};_getLabel=function(c){var d=a(c).siblings("label");if(d.length===0){if(b.wrapSelector){d=a(c).parents(b.wrapSelector).find("label")}else{_for=c.id||c.name;d=a('[for="'+_for+'"]')}}return d};_prepLabel=function(c,d){if(c[0].tagName.match(/select/i)){var e=c.find("[selected]").length===0?" selected":"";c.prepend('");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.stop(true,false).animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.stop(true,false).animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.stop(true,false).animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
From 891eb3fea2d00d451a1a98d06440b74b427d0b2c Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Tue, 6 Nov 2012 00:24:09 +0000
Subject: [PATCH 35/56] Add in a character count option to only fade label
*after* a given number of characters
---
README.md | 7 +++++++
jquery.superLabels.js | 34 +++++++++++++++++++++++++++++-----
jquery.superLabels.min.js | 6 +++---
3 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 65ec207..5370085 100644
--- a/README.md
+++ b/README.md
@@ -60,6 +60,13 @@ There are quite a number of options you can pass the plugin additional to the tw
* `wrapSelector` - The selector for the element you have wrapping each field. _(default: false)_
* This is used to find the label - use as a last resort. Rather make sure the field and label are next to each other in your markup, or failing that, that your labels use the `for` attribute that point to the field's `name` or `id`.
+Last, but not least, you can choose to only fade out the label *after* a certain number of characters have been typed (as of version 1.1.2). You can make use of this by adding a `data-sl-char-limit` with the number of characters you wish for any given field (simply leave it out if you don't want to use this)
+
+For example, to make the label fade out only *after* 20 characters have been typed in the field:
+
+
+
+
## Concerning placeholders
According to [the spec](http://www.w3.org/wiki/HTML/Elements/input/text) placeholders are meant to be used to represent "a short hint (a word or short phrase) intended to aid the user with data entry." *NOT* as a replacement for labels.
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 0d1b3b3..69f4063 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.1.1
+ * Version: 1.1.2
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
@@ -136,6 +136,8 @@
// Position the label.
_prepLabel = function(_field, _label) {
+ var opacity = 0;
+
// Handle drop down list labels differently
if (_field[0].tagName.match(/select/i)) {
// Checking whether the field has a value doesn't work (the browser just seems to select the first ");d.css("display","none")}else{c.css({zIndex:b.baseZindex+1}).addClass("sl_field");d.css({left:_noVal(c)?b.labelLeft:a(c).width()-d.width(),opacity:_noVal(c)?1:0,position:"absolute",top:b.labelTop,zIndex:b.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var c=b.duration;var d=_getLabel(this);var e={opacity:0};if(b.noAnimate){d.hide();return false}if(b.slide){e.left=a(this).width()-d.width();e.opacity=b.opacity}else{c=b.fadeDuration}d.stop(true,false).animate(e,c,b.easingOut)}};_blur=function(){if(_noVal(this)){var a=b.duration;var c=_getLabel(this);var d={opacity:1};if(b.noAnimate){c.show();return false}if(b.slide){d.left=b.labelLeft}else{a=b.fadeDuration}c.stop(true,false).animate(d,a,b.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(b.noAnimate)return false;var a=_getLabel(this);var c=0;if(_noVal(this)&&a.css("opacity")>0||!_noVal(this)&&a.css("opacity")===0){return false}if(_noVal(this)&&a.css("opacity")!==0){c=b.opacity}a.stop(true,false).animate({opacity:c},b.fadeDuration,b.easingOut)};_noVal=function(b){return a(b).val()===""}})(jQuery)
\ No newline at end of file
+(function(e){var t={baseZindex:0,duration:500,easingIn:e.easing.def?"easeInOutCubic":false,easingOut:e.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var n=["text","search","url","tel","email","password","number"];var r=["input","textarea","select"];e.fn.superLabels=function(i){var s=[];if(this.length===0)return false;if(i&&i.labelLeft&&isNaN(i.labelLeft))i.labelLeft=Number(i.labelLeft.replace(/\D+/,""));if(i&&i.labelTop&&isNaN(i.labelTop))i.labelTop=Number(i.labelTop.replace(/\D+/,""));e.extend(t,i||{});if(this.length===1&&/form/i.test(this[0].tagName)){s=e(r.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){e.merge(s,e(r.join(","),this))}else{s.push(this)}})}else{s=this}return e(s).each(function(){var t=e(this);if((t[0].tagName.toLowerCase()==="input"&&e.inArray(t.attr("type"),n))===-1&&e.inArray(t[0].tagName.toLowerCase(),r)!==-1){return true}var i=_getLabel(this);var s=t.attr("placeholder");if(s){if(i.length===0){var o='";o+="";o=e(o);i=o;t.before(i)}else{i.attr("title",s)}t.removeAttr("placeholder")}if(i.length===0){return true}_prepLabel(t,i);if(!this.tagName.match(/select/i)){t.focus(_focus);t.blur(_blur);t.change(_blur);t.bind("input",_keyup);t.bind("propertychange",_blur);t.keyup(_keyup);i.click(function(){t.focus()})}})};_getLabel=function(n){var r=e(n).siblings("label");if(r.length===0){if(t.wrapSelector){r=e(n).parents(t.wrapSelector).find("label")}else{_for=n.id||n.name;r=e('[for="'+_for+'"]')}}return r};_prepLabel=function(n,r){var i=0;if(n[0].tagName.match(/select/i)){var s=n.find("[selected]").length===0?" selected":"";n.prepend('");r.css("display","none")}else{if(_noVal(n)){i=1}else if(_withinCharCount(n)){i=t.opacity}n.css({zIndex:t.baseZindex+1}).addClass("sl_field");r.css({left:_noVal(n)?t.labelLeft:e(n).width()-r.width(),opacity:i,position:"absolute",top:t.labelTop,zIndex:t.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var n=t.duration;var r=_getLabel(this);var i={opacity:0};if(t.noAnimate){r.hide();return false}if(t.slide){i.left=e(this).width()-r.width();i.opacity=t.opacity}else{n=t.fadeDuration}r.stop(true,false).animate(i,n,t.easingOut)}};_blur=function(){if(_noVal(this)){var e=t.duration;var n=_getLabel(this);var r={opacity:1};if(t.noAnimate){n.show();return false}if(t.slide){r.left=t.labelLeft}else{e=t.fadeDuration}n.stop(true,false).animate(r,e,t.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(t.noAnimate)return false;var e=_getLabel(this);var n=0;if(_noVal(this)&&e.css("opacity")>0||!_noVal(this)&&e.css("opacity")===0){return false}if(_noVal(this)&&e.css("opacity")!==0||_withinCharCount(this)){n=t.opacity}e.stop(true,false).animate({opacity:n},t.fadeDuration,t.easingOut)};_noVal=function(t){return e(t).val()===""};_withinCharCount=function(t){var n=e(t).data("slCharLimit");if(!n||typeof n!=="number"){return false}t=t.length?t[0]:t;return n&&t.value&&t.value.length<=n}})(jQuery)
\ No newline at end of file
From c7087bde205b7e7d1f4361b968e67855717d74e8 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Wed, 7 Nov 2012 00:13:29 +0000
Subject: [PATCH 36/56] Add in auto character limit approximation option.
---
README.md | 15 ++++++--
jquery.superLabels.js | 74 ++++++++++++++++++++++++++++-----------
jquery.superLabels.min.js | 4 +--
3 files changed, 67 insertions(+), 26 deletions(-)
diff --git a/README.md b/README.md
index 5370085..7bdceb9 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Here's a (very) [simple demo](http://remy.bach.me.uk/superlabels_demo/) of Super
You need to make sure that the element containing both the field and the label has `position:relative;`. Other than that, the plugin should have enough flexibility to handle most of your needs.
-#### Basic
+### Basic
The quickest and easiest way to use this plugin is as follows:
@@ -38,10 +38,11 @@ Lastly, you can choose to ONLY apply superLabels to specific fields if you wish
$('input.foo, textarea.bar, select.baz').superLabels();
-#### Advanced
+### Advanced
There are quite a number of options you can pass the plugin additional to the two I mentioned above:
+* `autoCharLimit` - Whether to automatically attempt to determine the number of characters after which to fade the label out or not (see below for more on this). _(default: false)_
* `baseZindex` - The base z-index which we display on top of. _(default: 0)_
* `debug` - Whether or not to show console messages. _(default: false)_
* Note: this is not available in the minified version.
@@ -60,13 +61,21 @@ There are quite a number of options you can pass the plugin additional to the tw
* `wrapSelector` - The selector for the element you have wrapping each field. _(default: false)_
* This is used to find the label - use as a last resort. Rather make sure the field and label are next to each other in your markup, or failing that, that your labels use the `for` attribute that point to the field's `name` or `id`.
-Last, but not least, you can choose to only fade out the label *after* a certain number of characters have been typed (as of version 1.1.2). You can make use of this by adding a `data-sl-char-limit` with the number of characters you wish for any given field (simply leave it out if you don't want to use this)
+#### "Character Limit"
+
+Last, but not least, you can choose to only fade out the label *after* a certain number of characters have been typed. You can make use of this by adding a `data-sl-char-limit` (as of version 1.1.2) with the number of characters you wish for any given field (simply leave it out if you don't want to use this).
For example, to make the label fade out only *after* 20 characters have been typed in the field:
+As of version 1.1.3, you can now choose to let superLabels do the heavy lifting for you and let it automatically try to guess the character length☨. You can do this by using the above `autoCharLimit` option, _or_ by setting the `data-sl-char-limit` to `auto` for a given field.
+
+The `autoCharLimit` option will be overridden by whatever is specified in the `data-sl-char-limit` attribute for that given element.
+
+☨ Note that this is only an approximation. Unless a mono-spaced font is used, there isn't a method of figuring out _exactly_ what length the characters are that _isn't_ expensive in terms of performance.
+
## Concerning placeholders
According to [the spec](http://www.w3.org/wiki/HTML/Elements/input/text) placeholders are meant to be used to represent "a short hint (a word or short phrase) intended to aid the user with data entry." *NOT* as a replacement for labels.
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 69f4063..647b7c8 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.1.2
+ * Version: 1.1.3
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
@@ -9,6 +9,7 @@
*/
;(function($) {
var defaults = {
+ autoCharLimit:false, // Whether to automatically attempt to determine the number of characters after which to fade the label out or not.
baseZindex:0, // The base z-index which we display on top of.
debug:false,
duration:500, // Time of the slide in milliseconds.
@@ -40,8 +41,7 @@
// If options were passed in, merge them with the defaults.
$.extend(defaults, options || {});
- if (!$.easing.def) { _info('Easing plugin not found - using standard jQuery animations.'); }
-
+
// Check for whether the user has just passed in the form. If so, we need to fetch all the accepted fields.
if (this.length === 1 && /form/i.test(this[0].tagName)) {
_fields = $(acceptedElements.join(','), this);
@@ -64,7 +64,6 @@
// Don't even bother going further if this isn't one of the accepted input field types or elements.
if ((_field[0].tagName.toLowerCase() === 'input' && $.inArray(_field.attr('type'), acceptedInputTypes)) === -1 && $.inArray(_field[0].tagName.toLowerCase(), acceptedElements) !== -1) {
- _info('Doh! The following '+this.tagName.toLowerCase()+', is not supported.', this);
return true; // Equivalent to continue in a normal for loop.
}
@@ -91,7 +90,6 @@
// Make sure this form field has a label
if (_label.length === 0) {
- _info('Doh! The following '+this.tagName.toLowerCase()+' has no related label.', this);
return true;
}
@@ -136,7 +134,9 @@
// Position the label.
_prepLabel = function(_field, _label) {
- var opacity = 0;
+ var _charLimit,
+ _charLimitAttr = _field.data('slCharLimit'),
+ _opacity = 0;
// Handle drop down list labels differently
if (_field[0].tagName.match(/select/i)) {
@@ -149,18 +149,24 @@
_label.css('display','none');
} else {
+ // If we need to figure out the length automatically (and this field isn't specifically excluded),
+ // or if this field is specifically requesting this functionality.
+ if (_charLimitAttr === 'auto' || (defaults.autoCharLimit && isNaN(_charLimitAttr))) {
+ _approximateChars(_field, _label);
+ }
+
// If the field is empty, make the label fully opaque.
if (_noVal(_field)) {
- opacity = 1;
- // Otherwise, if the field is not empty, but below the character count (if any), use the passed in option.
- } else if (_withinCharCount(_field)) {
- opacity = defaults.opacity;
+ _opacity = 1;
+ // Otherwise, if the field is not empty, but below the character limit (if any), use the passed in option.
+ } else if (_withinCharLimit(_field)) {
+ _opacity = defaults._opacity;
}
_field.css({ zIndex:defaults.baseZindex+1 }).addClass('sl_field');
_label.css({
left:_noVal(_field) ? defaults.labelLeft : $(_field).width()-_label.width(),
- opacity:opacity,
+ opacity:_opacity,
position:'absolute',
top:defaults.labelTop,
zIndex:defaults.baseZindex+2
@@ -225,7 +231,7 @@
}
// If the field is empty and the label isn't showing, make it show up again.
- if ( (_noVal(this) && _label.css('opacity') !== 0) || _withinCharCount(this) ) {
+ if ( (_noVal(this) && _label.css('opacity') !== 0) || _withinCharLimit(this) ) {
_o = defaults.opacity;
}
@@ -235,12 +241,12 @@
/*===== Utility Functions =====*/
// Tell us whether the form field has a value.
_noVal = function(_el) { return $(_el).val() === ''; };
- // Tell us whether the form field meets a given character count (if necessary)
- _withinCharCount = function(_el) {
- var count = $(_el).data('slCharLimit');
+ // Tell us whether the form field meets a given character limit (if necessary)
+ _withinCharLimit = function(_el) {
+ var _limit = $(_el).data('slCharLimit');
// Stop here if there's no need to check for number of characters.
- if (!count || typeof count !== 'number') {
+ if (!_limit || typeof _limit !== 'number') {
return false;
}
@@ -248,11 +254,37 @@
// jQuery object-like Array, thus: grab the DOM element from it.
_el = _el.length ? _el[0] : _el;
- return count && _el.value && _el.value.length <= count;
+ return _limit && _el.value && _el.value.length <= _limit;
};
+ // Attempt to automatically set up the character limit and attach it to the field.
+ _approximateChars = function(_field, _label) {
+ var _available,
+ _charLen,
+ _chars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ _properties = ["font-family", "font-size", "font-weight", "letter-spacing", "line-height", "text-shadow", "text-transform"],
+ _tmp = $('
'+_chars+'
');
+
+ // Loop through each of the defined properties so that we can get the font looking the same size.
+ // I know this isn't too great for performance, but for now I don't know of a better way to do this.
+ // If you do know of a better way, please hit me with a pull request.
+ $.each(_properties, function(i, _prop) {
+ _tmp.css(_prop, _field.css(_prop));
+ });
- // Console Functions (We need these to make sure this only displays when the console exists.)
- _log = function() { if (defaults.debug && console && console.log) console.log.apply(console, arguments); };
- _info = function() { if (defaults.debug && console && console.info) console.info.apply(console, arguments); };
- _error = function() { if (defaults.debug && console && console.error) console.error.apply(console, arguments); };
+ _tmp.css({
+ 'position':'absolute', // so it's out of the document flow.
+ 'visibility':'hidden' // so that it's not visible, but still takes up space in the DOM so we can grab the width
+ });
+
+ $('body').append(_tmp);
+ // Get the average length *per character*
+ _charLen = Math.round(_tmp.width() / _chars.length);
+ // Remove our temporary div from the DOM.
+ _tmp.remove();
+
+ _available = _field.width() - _label.width();
+
+ // Set the data-sl-char-limit attribute for this field to our approximated value.
+ _field.data('slCharLimit', Math.floor(_available / _charLen));
+ };
})(jQuery);
\ No newline at end of file
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index f4c0042..a15b3ff 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.1.2
+ * Version: 1.1.3
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(e){var t={baseZindex:0,duration:500,easingIn:e.easing.def?"easeInOutCubic":false,easingOut:e.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var n=["text","search","url","tel","email","password","number"];var r=["input","textarea","select"];e.fn.superLabels=function(i){var s=[];if(this.length===0)return false;if(i&&i.labelLeft&&isNaN(i.labelLeft))i.labelLeft=Number(i.labelLeft.replace(/\D+/,""));if(i&&i.labelTop&&isNaN(i.labelTop))i.labelTop=Number(i.labelTop.replace(/\D+/,""));e.extend(t,i||{});if(this.length===1&&/form/i.test(this[0].tagName)){s=e(r.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){e.merge(s,e(r.join(","),this))}else{s.push(this)}})}else{s=this}return e(s).each(function(){var t=e(this);if((t[0].tagName.toLowerCase()==="input"&&e.inArray(t.attr("type"),n))===-1&&e.inArray(t[0].tagName.toLowerCase(),r)!==-1){return true}var i=_getLabel(this);var s=t.attr("placeholder");if(s){if(i.length===0){var o='";o+="";o=e(o);i=o;t.before(i)}else{i.attr("title",s)}t.removeAttr("placeholder")}if(i.length===0){return true}_prepLabel(t,i);if(!this.tagName.match(/select/i)){t.focus(_focus);t.blur(_blur);t.change(_blur);t.bind("input",_keyup);t.bind("propertychange",_blur);t.keyup(_keyup);i.click(function(){t.focus()})}})};_getLabel=function(n){var r=e(n).siblings("label");if(r.length===0){if(t.wrapSelector){r=e(n).parents(t.wrapSelector).find("label")}else{_for=n.id||n.name;r=e('[for="'+_for+'"]')}}return r};_prepLabel=function(n,r){var i=0;if(n[0].tagName.match(/select/i)){var s=n.find("[selected]").length===0?" selected":"";n.prepend('");r.css("display","none")}else{if(_noVal(n)){i=1}else if(_withinCharCount(n)){i=t.opacity}n.css({zIndex:t.baseZindex+1}).addClass("sl_field");r.css({left:_noVal(n)?t.labelLeft:e(n).width()-r.width(),opacity:i,position:"absolute",top:t.labelTop,zIndex:t.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var n=t.duration;var r=_getLabel(this);var i={opacity:0};if(t.noAnimate){r.hide();return false}if(t.slide){i.left=e(this).width()-r.width();i.opacity=t.opacity}else{n=t.fadeDuration}r.stop(true,false).animate(i,n,t.easingOut)}};_blur=function(){if(_noVal(this)){var e=t.duration;var n=_getLabel(this);var r={opacity:1};if(t.noAnimate){n.show();return false}if(t.slide){r.left=t.labelLeft}else{e=t.fadeDuration}n.stop(true,false).animate(r,e,t.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(t.noAnimate)return false;var e=_getLabel(this);var n=0;if(_noVal(this)&&e.css("opacity")>0||!_noVal(this)&&e.css("opacity")===0){return false}if(_noVal(this)&&e.css("opacity")!==0||_withinCharCount(this)){n=t.opacity}e.stop(true,false).animate({opacity:n},t.fadeDuration,t.easingOut)};_noVal=function(t){return e(t).val()===""};_withinCharCount=function(t){var n=e(t).data("slCharLimit");if(!n||typeof n!=="number"){return false}t=t.length?t[0]:t;return n&&t.value&&t.value.length<=n}})(jQuery)
\ No newline at end of file
+(function(e){var t={autoCharLimit:false,baseZindex:0,debug:false,duration:500,easingIn:e.easing.def?"easeInOutCubic":false,easingOut:e.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false};var n=["text","search","url","tel","email","password","number"];var r=["input","textarea","select"];e.fn.superLabels=function(i){var s=[];if(this.length===0)return false;if(i&&i.labelLeft&&isNaN(i.labelLeft))i.labelLeft=Number(i.labelLeft.replace(/\D+/,""));if(i&&i.labelTop&&isNaN(i.labelTop))i.labelTop=Number(i.labelTop.replace(/\D+/,""));e.extend(t,i||{});if(this.length===1&&/form/i.test(this[0].tagName)){s=e(r.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){e.merge(s,e(r.join(","),this))}else{s.push(this)}})}else{s=this}return e(s).each(function(){var t=e(this);if((t[0].tagName.toLowerCase()==="input"&&e.inArray(t.attr("type"),n))===-1&&e.inArray(t[0].tagName.toLowerCase(),r)!==-1){return true}var i=_getLabel(this);var s=t.attr("placeholder");if(s){if(i.length===0){var o='";o+="";o=e(o);i=o;t.before(i)}else{i.attr("title",s)}t.removeAttr("placeholder")}if(i.length===0){return true}_prepLabel(t,i);if(!this.tagName.match(/select/i)){t.focus(_focus);t.blur(_blur);t.change(_blur);t.bind("input",_keyup);t.bind("propertychange",_blur);t.keyup(_keyup);i.click(function(){t.focus()})}})};_getLabel=function(n){var r=e(n).siblings("label");if(r.length===0){if(t.wrapSelector){r=e(n).parents(t.wrapSelector).find("label")}else{_for=n.id||n.name;r=e('[for="'+_for+'"]')}}return r};_prepLabel=function(n,r){var i,s=n.data("slCharLimit"),o=0;if(n[0].tagName.match(/select/i)){var u=n.find("[selected]").length===0?" selected":"";n.prepend('");r.css("display","none")}else{if(s==="auto"||t.autoCharLimit&&isNaN(s)){_approximateChars(n,r)}if(_noVal(n)){o=1}else if(_withinCharLimit(n)){o=t._opacity}n.css({zIndex:t.baseZindex+1}).addClass("sl_field");r.css({left:_noVal(n)?t.labelLeft:e(n).width()-r.width(),opacity:o,position:"absolute",top:t.labelTop,zIndex:t.baseZindex+2}).addClass("sl_label")}};_focus=function(){if(_noVal(this)){var n=t.duration;var r=_getLabel(this);var i={opacity:0};if(t.noAnimate){r.hide();return false}if(t.slide){i.left=e(this).width()-r.width();i.opacity=t.opacity}else{n=t.fadeDuration}r.stop(true,false).animate(i,n,t.easingOut)}};_blur=function(){if(_noVal(this)){var e=t.duration;var n=_getLabel(this);var r={opacity:1};if(t.noAnimate){n.show();return false}if(t.slide){r.left=t.labelLeft}else{e=t.fadeDuration}n.stop(true,false).animate(r,e,t.easingOut)}else{_keyup.apply(this)}};_keyup=function(){if(t.noAnimate)return false;var e=_getLabel(this);var n=0;if(_noVal(this)&&e.css("opacity")>0||!_noVal(this)&&e.css("opacity")===0){return false}if(_noVal(this)&&e.css("opacity")!==0||_withinCharLimit(this)){n=t.opacity}e.stop(true,false).animate({opacity:n},t.fadeDuration,t.easingOut)};_noVal=function(t){return e(t).val()===""};_withinCharLimit=function(t){var n=e(t).data("slCharLimit");if(!n||typeof n!=="number"){return false}t=t.length?t[0]:t;return n&&t.value&&t.value.length<=n};_approximateChars=function(t,n){var r,i,s="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";_properties=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],_tmp=e("
+
+
+
+
+
+
+
+
+
+
+
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26356246-2']);
diff --git a/demo/scripts/demo.js b/demo/scripts/demo.js
new file mode 100644
index 0000000..5fdb125
--- /dev/null
+++ b/demo/scripts/demo.js
@@ -0,0 +1,44 @@
+jQuery(function($) {
+ var tweakableConf = {
+ duration:500,
+ easingIn:'easeInOutCubic',
+ easingOut:'easeInOutCubic',
+ fadeDuration:250,
+ labelLeft:5,
+ labelTop:5,
+ opacity:0.5
+ };
+
+ $('.basic form, .placeholder form').superLabels({
+ labelLeft:5,
+ labelTop:5
+ });
+
+ $('.tweakable form').superLabels(tweakableConf);
+ $('.tweakable-container input, .tweakable-container select').focus(function() {
+ $(this).css('zIndex', 2);
+ }).blur(function() {
+ $(this).css('zIndex', 0);
+ }).change(function() {
+ var identifier = $(this).data('token'),
+ num = $(this).data('tokenNum'),
+ token = $('.tweakable-container .token.'+identifier).get(num),
+ val = this.value;
+
+ if (isNaN(val)) {
+ token.innerHTML = val;
+ tweakableConf[this.className] = val;
+ } else {
+ token.innerHTML = Number(val);
+ tweakableConf[this.className] = Number(val);
+ }
+
+ $('.tweakable form').superLabels(tweakableConf);
+ });
+
+ $('.charLimit form').superLabels({
+ autoCharLimit:true,
+ labelLeft:5,
+ labelTop:5
+ });
+});
\ No newline at end of file
From e40823120d1b98cd36397c9e0c5aa5b3f22538f8 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 8 Nov 2012 20:42:12 +0000
Subject: [PATCH 43/56] Increase the width of the demo to display the forms a
little better.
---
demo/css/style.css | 2 +-
demo/index.html | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/demo/css/style.css b/demo/css/style.css
index 6f0e346..c52766a 100755
--- a/demo/css/style.css
+++ b/demo/css/style.css
@@ -25,7 +25,7 @@ form { margin-bottom:0; }
/* Reset this from what's set by bootstrap */
label { display:inline; }
-section > .span6:not(.intro) {
+section > .span8:not(.intro) {
border-top:1px dashed #777;
margin-top:20px;
padding-top:20px;
diff --git a/demo/index.html b/demo/index.html
index c0796a3..3d2e314 100755
--- a/demo/index.html
+++ b/demo/index.html
@@ -17,7 +17,7 @@
-
+
jQuery Super Labels Demo
All of the below use the following form unless otherwise specified.
@@ -47,7 +47,7 @@
jQuery Super Labels Demo
-
+
Basic Example
@@ -83,7 +83,7 @@
Basic Example
-
+
Tweakable Example
Simply click on the values below for the items you want to edit, change the values and click out of the field again.
@@ -197,7 +197,7 @@
Tweakable Example
-
+
Character Limit Example
@@ -239,7 +239,7 @@
Character Limit Example
-
+
Placeholder Example
This example uses a form with only the "Name" fields to show the placeholder functionality.
From 7dbb819386487d911eb19a3d716ff8e93bb330b1 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 8 Nov 2012 21:52:00 +0000
Subject: [PATCH 44/56] Upgrade the version number to 2.0 now that we have a
decent demo, new features, and bug fixes.
---
jquery.superLabels.js | 2 +-
jquery.superLabels.min.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index dd5da70..5c9ddea 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.2.2
+ * Version: 2.0
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index f52b44a..7b1f847 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 1.2.2
+ * Version: 2.0
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
From eb3eac5d56eea69b7c717878ff48685c5d754908 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 8 Nov 2012 22:16:08 +0000
Subject: [PATCH 45/56] Add a seen-on.md file to track places where super
labels is used.
---
README.md | 4 ++++
seen-on.md | 0
2 files changed, 4 insertions(+)
create mode 100644 seen-on.md
diff --git a/README.md b/README.md
index ecd2b1d..0c29f0a 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,10 @@ This method only really works for the following: input[type="text"], input[type=
☨ Uses the easing plugin if available.
+## Who's using it?
+
+[Here](https://github.com/remybach/jQuery.superLabels/blob/master/seen-on.md) is a list of sites that use Super Labels. If you've used this plugin and would like to add your site to the list either fork the project, update the file, and submit a pull request or [let me know](http://remy.bach.me.uk/get-in-touch) through my website.
+
## Demo
A demo of some of the functionality can be found on my site [here](http://remy.bach.me.uk/superlabels_demo/), but is also included in the repository in the `demo` folder.
diff --git a/seen-on.md b/seen-on.md
new file mode 100644
index 0000000..e69de29
From 7c73b0b54a64c2444b7059c3957ad595a777e7ff Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 8 Nov 2012 23:53:20 +0000
Subject: [PATCH 46/56] Initial sites for the seen-on.md file
---
seen-on.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/seen-on.md b/seen-on.md
index e69de29..fbc5249 100644
--- a/seen-on.md
+++ b/seen-on.md
@@ -0,0 +1,2 @@
+* [http://www.biscuiteers.com](http://www.biscuiteers.com)
+* [http://www.yeovalley.co.uk](http://www.yeovalley.co.uk)
\ No newline at end of file
From eabbeeb0bb15cfb15df839a23e8004c5160b0aff Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Wed, 14 Nov 2012 10:38:55 +0000
Subject: [PATCH 47/56] Update the prism theme (more accurate twilight
colouring)
---
demo/css/prism.css | 56 ++++++++++++++++++++++++----------------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/demo/css/prism.css b/demo/css/prism.css
index 9566a5a..9128617 100644
--- a/demo/css/prism.css
+++ b/demo/css/prism.css
@@ -25,23 +25,29 @@ pre[class*="language-"] {
pre[class*="language-"],
:not(pre) > code[class*="language-"] {
- background:hsl(0,0%,22%);
+ background:hsl(0, 0%, 8%); /* #141414 */
}
/* Code blocks */
pre[class*="language-"] {
border-radius: .5em;
- border: .3em solid hsl(0,0%,33%);
+ border: .3em solid hsl(0,0%,33%); /* #282A2B */
box-shadow: 1px 1px .5em black inset;
margin: .5em 0;
overflow: auto;
padding: 1em;
}
+pre[class*="language-"]::selection { /* Safari */
+ background:hsl(200, 4%, 16%); /* #282A2B */
+}
+pre[class*="language-"]::selection { /* Firefox */
+ background:hsl(200, 4%, 16%); /* #282A2B */
+}
/* Inline code */
:not(pre) > code[class*="language-"] {
border-radius: .3em;
- border: .13em solid hsl(0,0%,33%);
+ border: .13em solid hsl(0,0%,33%); /* #545454 */
box-shadow: 1px 1px .3em -.1em black inset;
padding: .15em .2em .05em;
}
@@ -50,7 +56,7 @@ pre[class*="language-"] {
.token.prolog,
.token.doctype,
.token.cdata {
- color: hsl(0,0%,47%);
+ color: hsl(0, 0%, 47%); /* #777777 */
}
.token.punctuation {
@@ -64,33 +70,32 @@ pre[class*="language-"] {
.token.tag,
.token.boolean,
.token.number {
- color: hsl(15, 60%, 61%);
+ color: hsl(14, 58%, 55%); /* #CF6A4C */
}
.token.keyword,
.token.property,
.token.selector {
- color:hsl(53, 89%, 79%);
+ color:hsl(53, 89%, 79%); /* #F9EE98 */
}
.token.attr-name,
+.token.attr-value,
.token.string,
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
- color:hsl(76, 21%, 52%);
+ color:hsl(76, 21%, 52%); /* #8F9D6A */
}
-.token.atrule,
-.token.attr-value {
- color: hsl(32, 33%, 50%);
+.token.atrule {
+ color:hsl(218, 22%, 55%); /* #7587A6 */
}
-
.token.regex,
.token.important {
- color: hsl(42, 75%, 65%);
+ color: hsl(42, 75%, 65%); /* #E9C062 */
}
.token.important {
@@ -109,18 +114,15 @@ pre[data-line] {
.language-markup .token.tag,
.language-markup .token.attr-name,
.language-markup .token.punctuation {
- color: hsl(38, 50%, 61%);
-}
-.language-markup .token.attr-value {
- color: hsl(76, 21%, 52%);
+ color: hsl(33, 33%, 52%); /* #AC885B */
}
/* Text Selection colour */
::selection {
- background: hsla(0,0%,93%,0.15);
+ background: hsla(0,0%,93%,0.15); /* #EDEDED */
}
::-moz-selection {
- background: hsla(0,0%,93%,0.15);
+ background: hsla(0,0%,93%,0.15); /* #EDEDED */
}
/* Make the tokens sit above the line highlight so the colours don't look faded. */
@@ -129,13 +131,13 @@ pre[data-line] {
z-index:1;
}
.line-highlight {
- background: -moz-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0));
- background: -o-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0));
- background: -webkit-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0));
- background: hsla(0, 0%, 33%, 0.25);
- background: linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0));
- border-bottom:1px dashed hsl(0, 0%, 33%);
- border-top:1px dashed hsl(0, 0%, 33%);
+ background: -moz-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0)); /* #545454 */
+ background: -o-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0)); /* #545454 */
+ background: -webkit-linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0)); /* #545454 */
+ background: hsla(0, 0%, 33%, 0.25); /* #545454 */
+ background: linear-gradient(left, hsl(0, 0%, 33%,.1) 70%, hsl(0, 0%, 33%,0)); /* #545454 */
+ border-bottom:1px dashed hsl(0, 0%, 33%); /* #545454 */
+ border-top:1px dashed hsl(0, 0%, 33%); /* #545454 */
left: 0;
line-height: inherit;
margin-top: 0.75em; /* Same as .prism’s padding-top */
@@ -148,10 +150,10 @@ pre[data-line] {
}
.line-highlight:before,
.line-highlight[data-end]:after {
- background-color: hsl(215, 15%, 59%);
+ background-color: hsl(215, 15%, 59%); /* #8794A6 */
border-radius: 999px;
box-shadow: 0 1px white;
- color: hsl(24, 20%, 95%);
+ color: hsl(24, 20%, 95%); /* #F5F2F0 */
content: attr(data-start);
font: bold 65%/1.5 sans-serif;
left: .6em;
From 1992721e1bb9682210850374881685fcf16f5b7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Fri, 4 Jan 2013 13:42:46 +0000
Subject: [PATCH 48/56] Add note about opacity bug on bold labels in IE.
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 0c29f0a..10d7447 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,8 @@ The way superLabels uses placeholders (as of version 1.1.1) is as follows:
Below I'll list any bugs that I'm aware of and will try to get around to fixing as soon as I can.
* Auto filling of form fields that is performed by some browsers (other than Chrome) causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value. I've found a bug report for Firefox [here](https://bugzilla.mozilla.org/show_bug.cgi?id=184761).
+* Opacity bug with bold label text in IE. This was pointed out by [alensa](https://github.com/alensa) in [this bug](https://github.com/remybach/jQuery.superLabels/issues/11#issuecomment-11860664). The proposed fix is to add a background colour to the label in your CSS.
#### License
-MIT License - [http://remybach.mit-license.org/](http://remybach.mit-license.org/ 'Link through to read my License.')
\ No newline at end of file
+MIT License - [http://remybach.mit-license.org/](http://remybach.mit-license.org/ 'Link through to read my License.')
From d18149137e669199704c6affa971ac77843579dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9my=20Bach?=
Date: Fri, 4 Jan 2013 13:43:37 +0000
Subject: [PATCH 49/56] Remove direct link to comment on issue 11.
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 10d7447..8c6aee6 100644
--- a/README.md
+++ b/README.md
@@ -94,7 +94,7 @@ The way superLabels uses placeholders (as of version 1.1.1) is as follows:
Below I'll list any bugs that I'm aware of and will try to get around to fixing as soon as I can.
* Auto filling of form fields that is performed by some browsers (other than Chrome) causes a visual bug. Currently the label stays visible and positioned on top of the field while the field has a value. I've found a bug report for Firefox [here](https://bugzilla.mozilla.org/show_bug.cgi?id=184761).
-* Opacity bug with bold label text in IE. This was pointed out by [alensa](https://github.com/alensa) in [this bug](https://github.com/remybach/jQuery.superLabels/issues/11#issuecomment-11860664). The proposed fix is to add a background colour to the label in your CSS.
+* Opacity bug with bold label text in IE. This was pointed out by [alensa](https://github.com/alensa) in [this bug](https://github.com/remybach/jQuery.superLabels/issues/11). The proposed fix is to add a background colour to the label in your CSS.
#### License
From 1c2b5be474ba9d5ca496a2e0dd41c5a9c85e25bc Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 17 Jan 2013 07:59:49 +0200
Subject: [PATCH 50/56] Minor version bump and added the jQuery plugin repo
manifest file.
---
jquery.superLabels.js | 2 +-
jquery.superLabels.min.js | 2 +-
superLabels.jquery.json | 28 ++++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
create mode 100644 superLabels.jquery.json
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 5c9ddea..4ee70ed 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0
+ * Version: 2.0.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 7b1f847..b9f64c6 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0
+ * Version: 2.0.1
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
diff --git a/superLabels.jquery.json b/superLabels.jquery.json
new file mode 100644
index 0000000..878e8af
--- /dev/null
+++ b/superLabels.jquery.json
@@ -0,0 +1,28 @@
+{
+ "name": "superLabels",
+ "version": "2.0.1",
+ "title": "jQuery Super Labels",
+ "author": {
+ "name": "Rémy Bach",
+ "url": "http://remy.bach.me.uk"
+ },
+ "licenses": [{
+ "type": "MIT",
+ "url": "http://remybach.mit-license.org/"
+ }],
+ "dependencies": {
+ "jquery": "*"
+ },
+ "description": "Give your forms a helping of awesome!",
+ "keywords": [
+ "form",
+ "forms",
+ "label",
+ "labels",
+ "usability"
+ ],
+ "homepage": "https://github.com/remybach/jQuery.superLabels",
+ "docs": "https://github.com/remybach/jQuery.superLabels",
+ "demo": "http://remy.bach.me.uk/superlabels_demo/",
+ "bugs": "https://github.com/remybach/jQuery.superLabels/issues"
+}
\ No newline at end of file
From 7348e769f071ee9b516316907acd2acec084e9d1 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Thu, 17 Jan 2013 08:23:02 +0200
Subject: [PATCH 51/56] Fix the dependency version in the jQuery plugin repo
file.
---
jquery.superLabels.js | 2 +-
jquery.superLabels.min.js | 2 +-
superLabels.jquery.json | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 4ee70ed..5cfe342 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0.1
+ * Version: 2.0.2
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index b9f64c6..0c8a852 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,7 +1,7 @@
/*
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0.1
+ * Version: 2.0.2
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
diff --git a/superLabels.jquery.json b/superLabels.jquery.json
index 878e8af..8daa0cd 100644
--- a/superLabels.jquery.json
+++ b/superLabels.jquery.json
@@ -1,6 +1,6 @@
{
"name": "superLabels",
- "version": "2.0.1",
+ "version": "2.0.2",
"title": "jQuery Super Labels",
"author": {
"name": "Rémy Bach",
@@ -11,7 +11,7 @@
"url": "http://remybach.mit-license.org/"
}],
"dependencies": {
- "jquery": "*"
+ "jquery": ">=1.5"
},
"description": "Give your forms a helping of awesome!",
"keywords": [
From c5aec2cc42ed122432ec33f011d94500b8a4d0d2 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Tue, 5 Mar 2013 17:29:27 +0000
Subject: [PATCH 52/56] Add Grunt.
Can now do the following: Run JS Hint, check that the version in the jquery.json file matches what's in packages.json file, update the banner in the jquery.superLabels.js file, and automatically minify.
---
.gitignore | 1 +
Gruntfile.js | 81 ++++++++++++++++++++++++++++++++++++++++
package.json | 25 +++++++++++++
tasks/checkBanner.js | 32 ++++++++++++++++
tasks/checkjQueryJSON.js | 29 ++++++++++++++
tasks/minify.js | 37 ++++++++++++++++++
6 files changed, 205 insertions(+)
create mode 100644 .gitignore
create mode 100644 Gruntfile.js
create mode 100644 package.json
create mode 100644 tasks/checkBanner.js
create mode 100644 tasks/checkjQueryJSON.js
create mode 100644 tasks/minify.js
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..40b878d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules/
\ No newline at end of file
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..510ab97
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,81 @@
+/*global module:false*/
+
+module.exports = function(grunt) {
+
+ // Project configuration.
+ grunt.initConfig({
+ pkg: grunt.file.readJSON('package.json'),
+ meta: {
+ version: '<%= pkg.version %>',
+ banner: '/*!\n' +
+ ' * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!\n' +
+ ' * Author: Rémy Bach\n' +
+ ' * Version: <%= pkg.version %>\n' +
+ ' * License: http://remybach.mit-license.org\n' +
+ ' * Url: http://github.com/remybach/jQuery.superLabels\n' +
+ ' * Description:\n' +
+ ' * This plugin allows you to display your form labels on top of your form fields, saving you space on your page.\n' +
+ ' */\n'+
+ ';'
+ },
+ jshint: {
+ files: ['jquery.superLabels.js'],
+ options: {
+ // Enforcing
+ curly: true,
+ immed: true,
+ indent: 4,
+ latedef: true,
+ newcap: true,
+ noarg: true,
+ noempty: true,
+ strict: true,
+ sub: true,
+ trailing: true,
+ undef: true,
+ unused: true,
+
+ // Relaxing
+ boss: true,
+ eqnull: true,
+ globalstrict: true,
+ iterator: true,
+ loopfunc: true,
+ smarttabs: true,
+
+ // Environments
+ browser: true,
+ jquery: true,
+ nonstandard: true,
+ white: false
+ }
+ },
+ checkBanner: {
+ filename: 'jquery.superLabels.js'
+ },
+ checkjQueryJSON: {
+ filename: 'superLabels.jquery.json'
+ },
+ minify: {
+ dest: 'jquery.superLabels.min.js',
+ filename: 'jquery.superLabels.js'
+ },
+ uglify: {
+ options: {
+ banner: '<%= meta.banner %>'
+ },
+ dist: {
+ files: {
+ 'jquery.superLabels.min.js': ['', 'jquery.superLabels.min.js']
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+ grunt.loadTasks('tasks');
+
+ // Default task - Run JS Hint, check the version in the jquery.json file matches what's in packages.json, update the banner in the superlabels file, and minify.
+ grunt.registerTask('default', ["jshint", "checkjQueryJSON", "checkBanner", "minify"]);
+};
\ No newline at end of file
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..8fc8108
--- /dev/null
+++ b/package.json
@@ -0,0 +1,25 @@
+{
+ "name": "jQuery.superLabels",
+ "version": "2.0.3",
+ "description": "Give your forms a helping of awesome!",
+ "homepage": "http://remy.bach.me.uk/superlabels_demo/",
+ "bugs": {
+ "url": "https://github.com/remybach/jQuery.superLabels/issues"
+ },
+ "contributors": [
+ {
+ "name": "Rémy Bach",
+ "url": "http://remy.bach.me.uk"
+ }
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/remybach/jQuery.superLabels"
+ },
+ "private": true,
+ "devDependencies": {
+ "grunt": "0.4.0rc7",
+ "grunt-contrib-jshint": "0.1.1",
+ "grunt-contrib-uglify": "0.1.1"
+ }
+}
\ No newline at end of file
diff --git a/tasks/checkBanner.js b/tasks/checkBanner.js
new file mode 100644
index 0000000..10224d1
--- /dev/null
+++ b/tasks/checkBanner.js
@@ -0,0 +1,32 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('checkBanner', 'Update the banner of the given file.', function() {
+ var banner, filename;
+
+ grunt.config.requires('minify.filename');
+
+ banner = grunt.config('meta.banner');
+ filename = grunt.config('minify.filename');
+
+ var src;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Updating Banner for: '+filename);
+
+ src = grunt.file.read(filename);
+
+ // Strip out the existing banner
+ src = src.replace(/\/\*![\r\n] \*\sTitle(.|[\r\n])*?\*\/[\r\n];/gm, banner);
+
+ grunt.file.write(filename, src);
+
+ grunt.log.writeln('Done updating banner in: '+filename);
+
+ });
+};
\ No newline at end of file
diff --git a/tasks/checkjQueryJSON.js b/tasks/checkjQueryJSON.js
new file mode 100644
index 0000000..d3aacc0
--- /dev/null
+++ b/tasks/checkjQueryJSON.js
@@ -0,0 +1,29 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('checkjQueryJSON', 'Update the version number in the jquery.json file.', function() {
+ var filename;
+
+ grunt.config.requires('checkjQueryJSON.filename');
+
+ filename = grunt.config('checkjQueryJSON.filename');
+
+ var json;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Updating Banner for: '+filename);
+
+ json = grunt.file.readJSON(filename);
+
+ json.version = grunt.config('meta.version');
+
+ grunt.file.write(filename, JSON.stringify(json));
+
+ grunt.log.writeln('Done updating version in: '+filename);
+ });
+};
\ No newline at end of file
diff --git a/tasks/minify.js b/tasks/minify.js
new file mode 100644
index 0000000..6c841d4
--- /dev/null
+++ b/tasks/minify.js
@@ -0,0 +1,37 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('minify', 'Strip out some of the guff and uglify.', function() {
+ var dest,
+ filename;
+
+ // Fail task if we don't know which file/s to minify or where to put them
+ grunt.config.requires('minify.dest');
+ grunt.config.requires('minify.filename');
+
+ dest = grunt.config('minify.dest');
+ filename = grunt.config('minify.filename');
+
+ var src;
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Minifying: '+filename);
+
+ src = grunt.file.read(filename);
+
+ // Strip out anything we don't want in the minified version.
+ src = src.replace(/\/\* nominify \*\/(.|[\r\n])*?\/\* \/nominify \*\//gm, '');
+
+ grunt.file.write(dest, src);
+
+ grunt.task.run('uglify');
+
+ grunt.log.writeln('Done minifying, stripped and uglified file is at: '+dest);
+
+ });
+};
\ No newline at end of file
From 489c6a564a06e964aa7be56c88025f100536d421 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Tue, 5 Mar 2013 17:31:25 +0000
Subject: [PATCH 53/56] Run everything through grunt.
Added strict mode, cleaned up a few things according to JS Hint and updated the version number.
---
jquery.superLabels.js | 50 ++++++++++++++++++++++++++++++---------
jquery.superLabels.min.js | 6 ++---
superLabels.jquery.json | 29 +----------------------
3 files changed, 43 insertions(+), 42 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index 5cfe342..f9a7ff0 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -1,17 +1,22 @@
-/*
+/*global console */
+/*!
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0.2
+ * Version: 2.0.3
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
;(function($) {
+ 'use strict';
+
var defaults = {
autoCharLimit:false, // Whether to automatically attempt to determine the number of characters after which to fade the label out or not.
baseZindex:0, // The base z-index which we display on top of.
+ /* nominify */
debug:false,
+ /* /nominify */
duration:500, // Time of the slide in milliseconds.
easingIn:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing in function to use for the slide.
easingOut:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing out function to use for the slide.
@@ -24,7 +29,10 @@
wrapSelector:false // The selector for the element you have wrapping each field.
},
acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password', 'number'],
- acceptedElements = ['input', 'textarea', 'select'];
+ acceptedElements = ['input', 'textarea', 'select'],
+
+ // Function declarations
+ _getLabel, _prepLabel, _focus, _blur, _keyup, _noVal, _withinCharLimit, _approximateChars/* nominify */,_log, _info, _error/* /nominify */;
$.fn.superLabels = function(options) {
var _fields = [],
@@ -48,7 +56,9 @@
// to superLabels.
$(this).data('slDefaults', $.extend(_newDefaults, options || {})).addClass('sl-defaults');
+ /* nominify */
if (!$.easing.def) { _info('Easing plugin not found - using standard jQuery animations.'); }
+ /* /nominify */
// Check for whether the user has just passed in the form. If so, we need to fetch all the accepted fields.
if (this.length === 1 && /form/i.test(this[0].tagName)) {
@@ -75,7 +85,9 @@
// Don't even bother going further if this isn't one of the accepted input field types or elements.
if ((_field[0].tagName.toLowerCase() === 'input' && $.inArray(_field.attr('type'), acceptedInputTypes)) === -1 && $.inArray(_field[0].tagName.toLowerCase(), acceptedElements) !== -1) {
+ /* nominify */
_info('Doh! The following '+this.tagName.toLowerCase()+', is not supported.', this);
+ /* /nominify */
return true; // Equivalent to continue in a normal for loop.
}
@@ -102,7 +114,9 @@
// Make sure this form field has a label
if (_label.length === 0) {
+ /* nominify */
_info('Doh! The following '+this.tagName.toLowerCase()+' has no related label.', this);
+ /* /nominify */
return true;
}
@@ -131,7 +145,8 @@
// Get the label for a given field.
_getLabel = function(_field) {
var _defaults = $(_field).closest('.sl-defaults').data('slDefaults'),
- _label = $(_field).siblings('label');
+ _label = $(_field).siblings('label'),
+ _for;
if (_label.length === 0) {
// If a selector is present for the wrapping element, use that, otherwise, proceed to use more traditional methods.
@@ -148,8 +163,7 @@
// Position the label.
_prepLabel = function(_field, _label) {
- var _charLimit,
- _charLimitAttr = _field.data('slCharLimit'),
+ var _charLimitAttr = _field.data('slCharLimit'),
_defaults = $(_field).closest('.sl-defaults').data('slDefaults'),
_opacity = 0,
_selected;
@@ -198,7 +212,7 @@
_to = { opacity:0 };
if (_noVal(this)) {
- _label = _getLabel(this);
+ _label = _getLabel(this);
if (_defaults.noAnimate) {
_label.hide();
@@ -288,7 +302,7 @@
_approximateChars = function(_field, _label) {
var _available,
_charLen,
- _chars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ _chars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
_properties = ["font-family", "font-size", "font-weight", "letter-spacing", "line-height", "text-shadow", "text-transform"],
_tmp = $('
'+_chars+'
');
@@ -318,8 +332,22 @@
_field.data('slCharLimit', Math.floor(_available / _charLen));
};
+ /* nominify */
// Console Functions (We need these to make sure this only displays when the console exists.)
- _log = function() { if (defaults.debug && console && console.log) console.log.apply(console, arguments); };
- _info = function() { if (defaults.debug && console && console.info) console.info.apply(console, arguments); };
- _error = function() { if (defaults.debug && console && console.error) console.error.apply(console, arguments); };
+ _log = function() {
+ if (defaults.debug && console && console.log) {
+ console.log.apply(console, arguments);
+ }
+ };
+ _info = function() {
+ if (defaults.debug && console && console.info) {
+ console.info.apply(console, arguments);
+ }
+ };
+ _error = function() {
+ if (defaults.debug && console && console.error) {
+ console.error.apply(console, arguments);
+ }
+ };
+ /* /nominify */
})(jQuery);
\ No newline at end of file
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index 0c8a852..dbc6d7a 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
-/*
+/*!
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0.2
+ * Version: 2.0.3
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-(function(e){var t={autoCharLimit:false,baseZindex:0,duration:500,easingIn:e.easing&&e.easing.def?"easeInOutCubic":false,easingOut:e.easing&&e.easing.def?"easeInOutCubic":false,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:false,opacity:.5,slide:true,wrapSelector:false},n=["text","search","url","tel","email","password","number"],r=["input","textarea","select"];e.fn.superLabels=function(i){var s=[],o;if(this.length===0){return false}if(i&&i.labelLeft&&isNaN(i.labelLeft)){i.labelLeft=Number(i.labelLeft.replace(/\D+/,""))}if(i&&i.labelTop&&isNaN(i.labelTop)){i.labelTop=Number(i.labelTop.replace(/\D+/,""))}o=e.extend({},t);e(this).data("slDefaults",e.extend(o,i||{})).addClass("sl-defaults");if(this.length===1&&/form/i.test(this[0].tagName)){s=e(r.join(","),this)}else if(this.length>1){this.each(function(){if(/form/i.test(this.tagName)){e.merge(s,e(r.join(","),this))}else{s.push(this)}})}else{s=this}return e(s).each(function(){var t=e(this),i,s=t.attr("placeholder"),o;if((t[0].tagName.toLowerCase()==="input"&&e.inArray(t.attr("type"),n))===-1&&e.inArray(t[0].tagName.toLowerCase(),r)!==-1){return true}i=_getLabel(this);if(s){if(i.length===0){o='";o+="";o=e(o);i=o;t.before(i)}else{i.attr("title",s)}t.removeAttr("placeholder")}if(i.length===0){return true}_prepLabel(t,i);if(!this.tagName.match(/select/i)){t.focus(_focus);t.blur(_blur);t.change(_blur);t.bind("input",_keyup);t.bind("propertychange",_blur);t.keyup(_keyup);i.click(function(){t.focus()})}})};_getLabel=function(t){var n=e(t).closest(".sl-defaults").data("slDefaults"),r=e(t).siblings("label");if(r.length===0){if(n.wrapSelector){r=e(t).parents(n.wrapSelector).find("label")}else{_for=t.id||t.name;r=e('[for="'+_for+'"]')}}return r};_prepLabel=function(t,n){var r,i=t.data("slCharLimit"),s=e(t).closest(".sl-defaults").data("slDefaults"),o=0,u;if(t[0].tagName.match(/select/i)){u=t.find("[selected]").length===0?" selected":"";t.prepend('");n.css("display","none")}else{if(i==="auto"||s.autoCharLimit&&isNaN(i)){_approximateChars(t,n)}if(_noVal(t)){o=1}else if(_withinCharLimit(t)){o=s._opacity}t.css({zIndex:s.baseZindex+1}).addClass("sl_field");n.css({left:_noVal(t)?s.labelLeft:e(t).width()-n.width(),opacity:o,position:"absolute",top:s.labelTop,zIndex:s.baseZindex+2}).addClass("sl_label")}};_focus=function(){var t=e(this).closest(".sl-defaults").data("slDefaults"),n=t.duration,r,i={opacity:0};if(_noVal(this)){r=_getLabel(this);if(t.noAnimate){r.hide();return false}if(t.slide){i.left=e(this).width()-r.width();i.opacity=t.opacity}else{n=t.fadeDuration}r.stop(true,false).animate(i,n,t.easingOut)}};_blur=function(){var t=e(this).closest(".sl-defaults").data("slDefaults"),n=t.duration,r,i={opacity:1};if(_noVal(this)){r=_getLabel(this);if(t.noAnimate){r.show();return false}if(t.slide){i.left=t.labelLeft}else{n=t.fadeDuration}r.stop(true,false).animate(i,n,t.easingOut)}else{_keyup.apply(this)}};_keyup=function(){var t=e(this).closest(".sl-defaults").data("slDefaults"),n,r=0;if(t.noAnimate){return false}n=_getLabel(this);if(_noVal(this)&&n.css("opacity")>0||!_noVal(this)&&n.css("opacity")===0){return false}if(_noVal(this)&&n.css("opacity")!==0||_withinCharLimit(this)){r=t.opacity}n.stop(true,false).animate({opacity:r},t.fadeDuration,t.easingOut)};_noVal=function(t){return e(t).val()===""};_withinCharLimit=function(t){var n=e(t).data("slCharLimit");if(!n||typeof n!=="number"){return false}t=t.length?t[0]:t;return n&&t.value&&t.value.length<=n};_approximateChars=function(t,n){var r,i,s="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";_properties=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],_tmp=e("
"+s+"
");e.each(_properties,function(e,n){_tmp.css(n,t.css(n))});_tmp.css({position:"absolute",visibility:"hidden"});t.parent().append(_tmp);i=Math.round(_tmp.width()/s.length);_tmp.remove();r=t.width()-n.width();t.data("slCharLimit",Math.floor(r/i))}})(jQuery)
\ No newline at end of file
+;(function(t){"use strict";var e,a,i,s,l,n,o,r,u={autoCharLimit:!1,baseZindex:0,duration:500,easingIn:t.easing&&t.easing.def?"easeInOutCubic":!1,easingOut:t.easing&&t.easing.def?"easeInOutCubic":!1,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:!1,opacity:.5,slide:!0,wrapSelector:!1},d=["text","search","url","tel","email","password","number"],h=["input","textarea","select"];t.fn.superLabels=function(n){var o,r=[];return 0===this.length?!1:(n&&n.labelLeft&&isNaN(n.labelLeft)&&(n.labelLeft=Number(n.labelLeft.replace(/\D+/,""))),n&&n.labelTop&&isNaN(n.labelTop)&&(n.labelTop=Number(n.labelTop.replace(/\D+/,""))),o=t.extend({},u),t(this).data("slDefaults",t.extend(o,n||{})).addClass("sl-defaults"),1===this.length&&/form/i.test(this[0].tagName)?r=t(h.join(","),this):this.length>1?this.each(function(){/form/i.test(this.tagName)?t.merge(r,t(h.join(","),this)):r.push(this)}):r=this,t(r).each(function(){var n,o,r=t(this),u=r.attr("placeholder");return-1===("input"===r[0].tagName.toLowerCase()&&t.inArray(r.attr("type"),d))&&-1!==t.inArray(r[0].tagName.toLowerCase(),h)?!0:(n=e(this),u&&(0===n.length?(o='",o+="",o=t(o),n=o,r.before(n)):n.attr("title",u),r.removeAttr("placeholder")),0===n.length?!0:(a(r,n),this.tagName.match(/select/i)||(r.focus(i),r.blur(s),r.change(s),r.bind("input",l),r.bind("propertychange",s),r.keyup(l),n.click(function(){r.focus()})),void 0))}))},e=function(e){var a,i=t(e).closest(".sl-defaults").data("slDefaults"),s=t(e).siblings("label");return 0===s.length&&(i.wrapSelector?s=t(e).parents(i.wrapSelector).find("label"):(a=e.id||e.name,s=t('[for="'+a+'"]'))),s},a=function(e,a){var i,s=e.data("slCharLimit"),l=t(e).closest(".sl-defaults").data("slDefaults"),u=0;e[0].tagName.match(/select/i)?(i=0===e.find("[selected]").length?" selected":"",e.prepend('"),a.css("display","none")):(("auto"===s||l.autoCharLimit&&isNaN(s))&&r(e,a),n(e)?u=1:o(e)&&(u=l._opacity),e.css({zIndex:l.baseZindex+1}).addClass("sl_field"),a.css({left:n(e)?l.labelLeft:t(e).width()-a.width(),opacity:u,position:"absolute",top:l.labelTop,zIndex:l.baseZindex+2}).addClass("sl_label"))},i=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,l={opacity:0};if(n(this)){if(a=e(this),i.noAnimate)return a.hide(),!1;i.slide?(l.left=t(this).width()-a.width(),l.opacity=i.opacity):s=i.fadeDuration,a.stop(!0,!1).animate(l,s,i.easingOut)}},s=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,o={opacity:1};if(n(this)){if(a=e(this),i.noAnimate)return a.show(),!1;i.slide?o.left=i.labelLeft:s=i.fadeDuration,a.stop(!0,!1).animate(o,s,i.easingOut)}else l.apply(this)},l=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=0;return i.noAnimate?!1:(a=e(this),n(this)&&a.css("opacity")>0||!n(this)&&0===a.css("opacity")?!1:((n(this)&&0!==a.css("opacity")||o(this))&&(s=i.opacity),a.stop(!0,!1).animate({opacity:s},i.fadeDuration,i.easingOut),void 0))},n=function(e){return""===t(e).val()},o=function(e){var a=t(e).data("slCharLimit");return a&&"number"==typeof a?(e=e.length?e[0]:e,a&&e.value&&a>=e.value.length):!1},r=function(e,a){var i,s,l="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",n=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],o=t("
"+l+"
");t.each(n,function(t,a){o.css(a,e.css(a))}),o.css({position:"absolute",visibility:"hidden"}),e.parent().append(o),s=Math.round(o.width()/l.length),o.remove(),i=e.width()-a.width(),e.data("slCharLimit",Math.floor(i/s))}})(jQuery);
\ No newline at end of file
diff --git a/superLabels.jquery.json b/superLabels.jquery.json
index 8daa0cd..1120080 100644
--- a/superLabels.jquery.json
+++ b/superLabels.jquery.json
@@ -1,28 +1 @@
-{
- "name": "superLabels",
- "version": "2.0.2",
- "title": "jQuery Super Labels",
- "author": {
- "name": "Rémy Bach",
- "url": "http://remy.bach.me.uk"
- },
- "licenses": [{
- "type": "MIT",
- "url": "http://remybach.mit-license.org/"
- }],
- "dependencies": {
- "jquery": ">=1.5"
- },
- "description": "Give your forms a helping of awesome!",
- "keywords": [
- "form",
- "forms",
- "label",
- "labels",
- "usability"
- ],
- "homepage": "https://github.com/remybach/jQuery.superLabels",
- "docs": "https://github.com/remybach/jQuery.superLabels",
- "demo": "http://remy.bach.me.uk/superlabels_demo/",
- "bugs": "https://github.com/remybach/jQuery.superLabels/issues"
-}
\ No newline at end of file
+{"name":"superLabels","version":"2.0.3","title":"jQuery Super Labels","author":{"name":"Rémy Bach","url":"http://remy.bach.me.uk"},"licenses":[{"type":"MIT","url":"http://remybach.mit-license.org/"}],"dependencies":{"jquery":">=1.5"},"description":"Give your forms a helping of awesome!","keywords":["form","forms","label","labels","usability"],"homepage":"https://github.com/remybach/jQuery.superLabels","docs":"https://github.com/remybach/jQuery.superLabels","demo":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues"}
\ No newline at end of file
From 4b417f1faba5c7f6e4dc69f85aa877e40ac28cd6 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Sun, 14 Apr 2013 14:29:38 +0100
Subject: [PATCH 54/56] Remove NaN check so that any united value can be used
(like em for example)
---
jquery.superLabels.js | 8 --------
jquery.superLabels.min.js | 4 ++--
package.json | 2 +-
superLabels.jquery.json | 2 +-
4 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/jquery.superLabels.js b/jquery.superLabels.js
index f9a7ff0..a464328 100644
--- a/jquery.superLabels.js
+++ b/jquery.superLabels.js
@@ -41,14 +41,6 @@
// If this has been run on an empty set of elements, pop out.
if (this.length === 0) { return false; }
- // Remove any NaNs from the positions (if present)
- if (options && options.labelLeft && isNaN(options.labelLeft)) {
- options.labelLeft = Number(options.labelLeft.replace(/\D+/, ''));
- }
- if (options && options.labelTop && isNaN(options.labelTop)) {
- options.labelTop = Number(options.labelTop.replace(/\D+/, ''));
- }
-
// Make a copy of the defaults.
_newDefaults = $.extend({}, defaults);
// If options were passed in, merge them with the defaults.
diff --git a/jquery.superLabels.min.js b/jquery.superLabels.min.js
index dbc6d7a..c2699c7 100644
--- a/jquery.superLabels.min.js
+++ b/jquery.superLabels.min.js
@@ -1,10 +1,10 @@
/*!
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach
- * Version: 2.0.3
+ * Version: 2.0.4
* License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels
* Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/
-;(function(t){"use strict";var e,a,i,s,l,n,o,r,u={autoCharLimit:!1,baseZindex:0,duration:500,easingIn:t.easing&&t.easing.def?"easeInOutCubic":!1,easingOut:t.easing&&t.easing.def?"easeInOutCubic":!1,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:!1,opacity:.5,slide:!0,wrapSelector:!1},d=["text","search","url","tel","email","password","number"],h=["input","textarea","select"];t.fn.superLabels=function(n){var o,r=[];return 0===this.length?!1:(n&&n.labelLeft&&isNaN(n.labelLeft)&&(n.labelLeft=Number(n.labelLeft.replace(/\D+/,""))),n&&n.labelTop&&isNaN(n.labelTop)&&(n.labelTop=Number(n.labelTop.replace(/\D+/,""))),o=t.extend({},u),t(this).data("slDefaults",t.extend(o,n||{})).addClass("sl-defaults"),1===this.length&&/form/i.test(this[0].tagName)?r=t(h.join(","),this):this.length>1?this.each(function(){/form/i.test(this.tagName)?t.merge(r,t(h.join(","),this)):r.push(this)}):r=this,t(r).each(function(){var n,o,r=t(this),u=r.attr("placeholder");return-1===("input"===r[0].tagName.toLowerCase()&&t.inArray(r.attr("type"),d))&&-1!==t.inArray(r[0].tagName.toLowerCase(),h)?!0:(n=e(this),u&&(0===n.length?(o='",o+="",o=t(o),n=o,r.before(n)):n.attr("title",u),r.removeAttr("placeholder")),0===n.length?!0:(a(r,n),this.tagName.match(/select/i)||(r.focus(i),r.blur(s),r.change(s),r.bind("input",l),r.bind("propertychange",s),r.keyup(l),n.click(function(){r.focus()})),void 0))}))},e=function(e){var a,i=t(e).closest(".sl-defaults").data("slDefaults"),s=t(e).siblings("label");return 0===s.length&&(i.wrapSelector?s=t(e).parents(i.wrapSelector).find("label"):(a=e.id||e.name,s=t('[for="'+a+'"]'))),s},a=function(e,a){var i,s=e.data("slCharLimit"),l=t(e).closest(".sl-defaults").data("slDefaults"),u=0;e[0].tagName.match(/select/i)?(i=0===e.find("[selected]").length?" selected":"",e.prepend('"),a.css("display","none")):(("auto"===s||l.autoCharLimit&&isNaN(s))&&r(e,a),n(e)?u=1:o(e)&&(u=l._opacity),e.css({zIndex:l.baseZindex+1}).addClass("sl_field"),a.css({left:n(e)?l.labelLeft:t(e).width()-a.width(),opacity:u,position:"absolute",top:l.labelTop,zIndex:l.baseZindex+2}).addClass("sl_label"))},i=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,l={opacity:0};if(n(this)){if(a=e(this),i.noAnimate)return a.hide(),!1;i.slide?(l.left=t(this).width()-a.width(),l.opacity=i.opacity):s=i.fadeDuration,a.stop(!0,!1).animate(l,s,i.easingOut)}},s=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,o={opacity:1};if(n(this)){if(a=e(this),i.noAnimate)return a.show(),!1;i.slide?o.left=i.labelLeft:s=i.fadeDuration,a.stop(!0,!1).animate(o,s,i.easingOut)}else l.apply(this)},l=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=0;return i.noAnimate?!1:(a=e(this),n(this)&&a.css("opacity")>0||!n(this)&&0===a.css("opacity")?!1:((n(this)&&0!==a.css("opacity")||o(this))&&(s=i.opacity),a.stop(!0,!1).animate({opacity:s},i.fadeDuration,i.easingOut),void 0))},n=function(e){return""===t(e).val()},o=function(e){var a=t(e).data("slCharLimit");return a&&"number"==typeof a?(e=e.length?e[0]:e,a&&e.value&&a>=e.value.length):!1},r=function(e,a){var i,s,l="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",n=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],o=t("
"+l+"
");t.each(n,function(t,a){o.css(a,e.css(a))}),o.css({position:"absolute",visibility:"hidden"}),e.parent().append(o),s=Math.round(o.width()/l.length),o.remove(),i=e.width()-a.width(),e.data("slCharLimit",Math.floor(i/s))}})(jQuery);
\ No newline at end of file
+;(function(t){"use strict";var e,a,i,s,n,l,o,r,d={autoCharLimit:!1,baseZindex:0,duration:500,easingIn:t.easing&&t.easing.def?"easeInOutCubic":!1,easingOut:t.easing&&t.easing.def?"easeInOutCubic":!1,fadeDuration:250,labelLeft:0,labelTop:0,noAnimate:!1,opacity:.5,slide:!0,wrapSelector:!1},u=["text","search","url","tel","email","password","number"],h=["input","textarea","select"];t.fn.superLabels=function(l){var o,r=[];return 0===this.length?!1:(o=t.extend({},d),t(this).data("slDefaults",t.extend(o,l||{})).addClass("sl-defaults"),1===this.length&&/form/i.test(this[0].tagName)?r=t(h.join(","),this):this.length>1?this.each(function(){/form/i.test(this.tagName)?t.merge(r,t(h.join(","),this)):r.push(this)}):r=this,t(r).each(function(){var l,o,r=t(this),d=r.attr("placeholder");return-1===("input"===r[0].tagName.toLowerCase()&&t.inArray(r.attr("type"),u))&&-1!==t.inArray(r[0].tagName.toLowerCase(),h)?!0:(l=e(this),d&&(0===l.length?(o='",o+="",o=t(o),l=o,r.before(l)):l.attr("title",d),r.removeAttr("placeholder")),0===l.length?!0:(a(r,l),this.tagName.match(/select/i)||(r.focus(i),r.blur(s),r.change(s),r.bind("input",n),r.bind("propertychange",s),r.keyup(n),l.click(function(){r.focus()})),void 0))}))},e=function(e){var a,i=t(e).closest(".sl-defaults").data("slDefaults"),s=t(e).siblings("label");return 0===s.length&&(i.wrapSelector?s=t(e).parents(i.wrapSelector).find("label"):(a=e.id||e.name,s=t('[for="'+a+'"]'))),s},a=function(e,a){var i,s=e.data("slCharLimit"),n=t(e).closest(".sl-defaults").data("slDefaults"),d=0;e[0].tagName.match(/select/i)?(i=0===e.find("[selected]").length?" selected":"",e.prepend('"),a.css("display","none")):(("auto"===s||n.autoCharLimit&&isNaN(s))&&r(e,a),l(e)?d=1:o(e)&&(d=n._opacity),e.css({zIndex:n.baseZindex+1}).addClass("sl_field"),a.css({left:l(e)?n.labelLeft:t(e).width()-a.width(),opacity:d,position:"absolute",top:n.labelTop,zIndex:n.baseZindex+2}).addClass("sl_label"))},i=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,n={opacity:0};if(l(this)){if(a=e(this),i.noAnimate)return a.hide(),!1;i.slide?(n.left=t(this).width()-a.width(),n.opacity=i.opacity):s=i.fadeDuration,a.stop(!0,!1).animate(n,s,i.easingOut)}},s=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=i.duration,o={opacity:1};if(l(this)){if(a=e(this),i.noAnimate)return a.show(),!1;i.slide?o.left=i.labelLeft:s=i.fadeDuration,a.stop(!0,!1).animate(o,s,i.easingOut)}else n.apply(this)},n=function(){var a,i=t(this).closest(".sl-defaults").data("slDefaults"),s=0;return i.noAnimate?!1:(a=e(this),l(this)&&a.css("opacity")>0||!l(this)&&0===a.css("opacity")?!1:((l(this)&&0!==a.css("opacity")||o(this))&&(s=i.opacity),a.stop(!0,!1).animate({opacity:s},i.fadeDuration,i.easingOut),void 0))},l=function(e){return""===t(e).val()},o=function(e){var a=t(e).data("slCharLimit");return a&&"number"==typeof a?(e=e.length?e[0]:e,a&&e.value&&a>=e.value.length):!1},r=function(e,a){var i,s,n="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",l=["font-family","font-size","font-weight","letter-spacing","line-height","text-shadow","text-transform"],o=t("
"+n+"
");t.each(l,function(t,a){o.css(a,e.css(a))}),o.css({position:"absolute",visibility:"hidden"}),e.parent().append(o),s=Math.round(o.width()/n.length),o.remove(),i=e.width()-a.width(),e.data("slCharLimit",Math.floor(i/s))}})(jQuery);
\ No newline at end of file
diff --git a/package.json b/package.json
index 8fc8108..6d3ba62 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "jQuery.superLabels",
- "version": "2.0.3",
+ "version": "2.0.4",
"description": "Give your forms a helping of awesome!",
"homepage": "http://remy.bach.me.uk/superlabels_demo/",
"bugs": {
diff --git a/superLabels.jquery.json b/superLabels.jquery.json
index 1120080..2e5c0e1 100644
--- a/superLabels.jquery.json
+++ b/superLabels.jquery.json
@@ -1 +1 @@
-{"name":"superLabels","version":"2.0.3","title":"jQuery Super Labels","author":{"name":"Rémy Bach","url":"http://remy.bach.me.uk"},"licenses":[{"type":"MIT","url":"http://remybach.mit-license.org/"}],"dependencies":{"jquery":">=1.5"},"description":"Give your forms a helping of awesome!","keywords":["form","forms","label","labels","usability"],"homepage":"https://github.com/remybach/jQuery.superLabels","docs":"https://github.com/remybach/jQuery.superLabels","demo":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues"}
\ No newline at end of file
+{"name":"superLabels","version":"2.0.4","title":"jQuery Super Labels","author":{"name":"Rémy Bach","url":"http://remy.bach.me.uk"},"licenses":[{"type":"MIT","url":"http://remybach.mit-license.org/"}],"dependencies":{"jquery":">=1.5"},"description":"Give your forms a helping of awesome!","keywords":["form","forms","label","labels","usability"],"homepage":"https://github.com/remybach/jQuery.superLabels","docs":"https://github.com/remybach/jQuery.superLabels","demo":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues"}
\ No newline at end of file
From 051befb933777df4609a4ba9c39b1ce8431d5b4d Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Tue, 28 May 2013 10:06:22 +0100
Subject: [PATCH 55/56] Add bower.json and update Grunt tasks to update version
number in all *.json files.
---
Gruntfile.js | 6 +++---
bower.json | 1 +
tasks/checkjQueryJSON.js | 29 -----------------------------
tasks/updateVersion.js | 33 +++++++++++++++++++++++++++++++++
4 files changed, 37 insertions(+), 32 deletions(-)
create mode 100644 bower.json
delete mode 100644 tasks/checkjQueryJSON.js
create mode 100644 tasks/updateVersion.js
diff --git a/Gruntfile.js b/Gruntfile.js
index 510ab97..6e8f59e 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -53,8 +53,8 @@ module.exports = function(grunt) {
checkBanner: {
filename: 'jquery.superLabels.js'
},
- checkjQueryJSON: {
- filename: 'superLabels.jquery.json'
+ updateVersion: {
+ files: [ 'superLabels.jquery.json', 'bower.json' ]
},
minify: {
dest: 'jquery.superLabels.min.js',
@@ -77,5 +77,5 @@ module.exports = function(grunt) {
grunt.loadTasks('tasks');
// Default task - Run JS Hint, check the version in the jquery.json file matches what's in packages.json, update the banner in the superlabels file, and minify.
- grunt.registerTask('default', ["jshint", "checkjQueryJSON", "checkBanner", "minify"]);
+ grunt.registerTask('default', ["jshint", "updateVersion", "checkBanner", "minify"]);
};
\ No newline at end of file
diff --git a/bower.json b/bower.json
new file mode 100644
index 0000000..3f962be
--- /dev/null
+++ b/bower.json
@@ -0,0 +1 @@
+{"name":"jQuery.superLabels","version":"2.0.4","description":"Give your forms a helping of awesome!","homepage":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues","repository":{"type":"git","url":"https://github.com/remybach/jQuery.superLabels"},"main":"jquery.superLabels.min.js","licenses":[{"type":"MIT"}]}
\ No newline at end of file
diff --git a/tasks/checkjQueryJSON.js b/tasks/checkjQueryJSON.js
deleted file mode 100644
index d3aacc0..0000000
--- a/tasks/checkjQueryJSON.js
+++ /dev/null
@@ -1,29 +0,0 @@
-module.exports = function(grunt) {
- 'use strict';
-
- grunt.registerTask('checkjQueryJSON', 'Update the version number in the jquery.json file.', function() {
- var filename;
-
- grunt.config.requires('checkjQueryJSON.filename');
-
- filename = grunt.config('checkjQueryJSON.filename');
-
- var json;
-
- // Warn on and remove invalid source files (if nonull was set).
- if (!grunt.file.exists(filename)) {
- grunt.log.warn('Source file not found at "' + filename + '"');
- return false;
- }
-
- grunt.log.writeln('Updating Banner for: '+filename);
-
- json = grunt.file.readJSON(filename);
-
- json.version = grunt.config('meta.version');
-
- grunt.file.write(filename, JSON.stringify(json));
-
- grunt.log.writeln('Done updating version in: '+filename);
- });
-};
\ No newline at end of file
diff --git a/tasks/updateVersion.js b/tasks/updateVersion.js
new file mode 100644
index 0000000..d31ce05
--- /dev/null
+++ b/tasks/updateVersion.js
@@ -0,0 +1,33 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ grunt.registerTask('updateVersion', 'Update the version number in all relevant *.json files.', function() {
+ var filename,
+ files,
+ json;
+
+ grunt.config.requires('updateVersion.files');
+
+ files = grunt.config('updateVersion.files');
+
+ for (var i = files.length - 1; i >= 0; i--) {
+ filename = files[i];
+
+ // Warn on and remove invalid source files (if nonull was set).
+ if (!grunt.file.exists(filename)) {
+ grunt.log.warn('Source file not found at "' + filename + '"');
+ return false;
+ }
+
+ grunt.log.writeln('Updating Banner for: '+filename);
+
+ json = grunt.file.readJSON(filename);
+
+ json.version = grunt.config('meta.version');
+
+ grunt.file.write(filename, JSON.stringify(json));
+
+ grunt.log.writeln('Done updating version in: '+filename);
+ }
+ });
+};
\ No newline at end of file
From ad069690554739056c084ee3b62750e6c2fb3e74 Mon Sep 17 00:00:00 2001
From: Remy Bach
Date: Tue, 28 May 2013 10:11:35 +0100
Subject: [PATCH 56/56] Make the updateVersion grunt task pretty print the
JSON.
---
bower.json | 18 +++++++++++++++++-
superLabels.jquery.json | 31 ++++++++++++++++++++++++++++++-
tasks/updateVersion.js | 2 +-
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/bower.json b/bower.json
index 3f962be..4d0cb64 100644
--- a/bower.json
+++ b/bower.json
@@ -1 +1,17 @@
-{"name":"jQuery.superLabels","version":"2.0.4","description":"Give your forms a helping of awesome!","homepage":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues","repository":{"type":"git","url":"https://github.com/remybach/jQuery.superLabels"},"main":"jquery.superLabels.min.js","licenses":[{"type":"MIT"}]}
\ No newline at end of file
+{
+ "name": "jQuery.superLabels",
+ "version": "2.0.4",
+ "description": "Give your forms a helping of awesome!",
+ "homepage": "http://remy.bach.me.uk/superlabels_demo/",
+ "bugs": "https://github.com/remybach/jQuery.superLabels/issues",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/remybach/jQuery.superLabels"
+ },
+ "main": "jquery.superLabels.min.js",
+ "licenses": [
+ {
+ "type": "MIT"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/superLabels.jquery.json b/superLabels.jquery.json
index 2e5c0e1..572f14a 100644
--- a/superLabels.jquery.json
+++ b/superLabels.jquery.json
@@ -1 +1,30 @@
-{"name":"superLabels","version":"2.0.4","title":"jQuery Super Labels","author":{"name":"Rémy Bach","url":"http://remy.bach.me.uk"},"licenses":[{"type":"MIT","url":"http://remybach.mit-license.org/"}],"dependencies":{"jquery":">=1.5"},"description":"Give your forms a helping of awesome!","keywords":["form","forms","label","labels","usability"],"homepage":"https://github.com/remybach/jQuery.superLabels","docs":"https://github.com/remybach/jQuery.superLabels","demo":"http://remy.bach.me.uk/superlabels_demo/","bugs":"https://github.com/remybach/jQuery.superLabels/issues"}
\ No newline at end of file
+{
+ "name": "superLabels",
+ "version": "2.0.4",
+ "title": "jQuery Super Labels",
+ "author": {
+ "name": "Rémy Bach",
+ "url": "http://remy.bach.me.uk"
+ },
+ "licenses": [
+ {
+ "type": "MIT",
+ "url": "http://remybach.mit-license.org/"
+ }
+ ],
+ "dependencies": {
+ "jquery": ">=1.5"
+ },
+ "description": "Give your forms a helping of awesome!",
+ "keywords": [
+ "form",
+ "forms",
+ "label",
+ "labels",
+ "usability"
+ ],
+ "homepage": "https://github.com/remybach/jQuery.superLabels",
+ "docs": "https://github.com/remybach/jQuery.superLabels",
+ "demo": "http://remy.bach.me.uk/superlabels_demo/",
+ "bugs": "https://github.com/remybach/jQuery.superLabels/issues"
+}
\ No newline at end of file
diff --git a/tasks/updateVersion.js b/tasks/updateVersion.js
index d31ce05..49e28bf 100644
--- a/tasks/updateVersion.js
+++ b/tasks/updateVersion.js
@@ -25,7 +25,7 @@ module.exports = function(grunt) {
json.version = grunt.config('meta.version');
- grunt.file.write(filename, JSON.stringify(json));
+ grunt.file.write(filename, JSON.stringify(json, null, 4));
grunt.log.writeln('Done updating version in: '+filename);
}