Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Run everything through grunt.

Added strict mode, cleaned up a few things according to JS Hint and updated the version number.
  • Loading branch information...
commit 489c6a564a06e964aa7be56c88025f100536d421 1 parent c5aec2c
@remybach authored
View
50 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 = $('<div>'+_chars+'</div>');
@@ -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);
View
6 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='<label for="'+(t.attr("id")||t.attr("name"))+'">'+s+"</label>";o+="</label>";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('<option value="" disabled'+u+' rel="label">'+n.html()+"</option>");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("<div>"+s+"</div>");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)
+;(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='<label for="'+(r.attr("id")||r.attr("name"))+'">'+u+"</label>",o+="</label>",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('<option value="" disabled'+i+' rel="label">'+a.html()+"</option>"),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("<div>"+l+"</div>");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);
View
29 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"
-}
+{"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"}
Please sign in to comment.
Something went wrong with that request. Please try again.