Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Run everything through grunt.
Browse files Browse the repository at this point in the history
Added strict mode, cleaned up a few things according to JS Hint and updated the version number.
  • Loading branch information
remybach committed Mar 5, 2013
1 parent c5aec2c commit 489c6a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
50 changes: 39 additions & 11 deletions jquery.superLabels.js
@@ -1,17 +1,22 @@
/* /*global console */
/*!
* Title: jQuery Super Labels Plugin - Give your forms a helping of awesome! * Title: jQuery Super Labels Plugin - Give your forms a helping of awesome!
* Author: Rémy Bach * Author: Rémy Bach
* Version: 2.0.2 * Version: 2.0.3
* License: http://remybach.mit-license.org * License: http://remybach.mit-license.org
* Url: http://github.com/remybach/jQuery.superLabels * Url: http://github.com/remybach/jQuery.superLabels
* Description: * Description:
* This plugin allows you to display your form labels on top of your form fields, saving you space on your page. * This plugin allows you to display your form labels on top of your form fields, saving you space on your page.
*/ */
;(function($) { ;(function($) {
'use strict';

var defaults = { var defaults = {
autoCharLimit:false, // Whether to automatically attempt to determine the number of characters after which to fade the label out or not. 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. baseZindex:0, // The base z-index which we display on top of.
/* nominify */
debug:false, debug:false,
/* /nominify */
duration:500, // Time of the slide in milliseconds. duration:500, // Time of the slide in milliseconds.
easingIn:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing in function to use for the slide. 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. easingOut:($.easing && $.easing.def ? 'easeInOutCubic' : false), // The easing out function to use for the slide.
Expand All @@ -24,7 +29,10 @@
wrapSelector:false // The selector for the element you have wrapping each field. wrapSelector:false // The selector for the element you have wrapping each field.
}, },
acceptedInputTypes = ['text', 'search', 'url', 'tel', 'email', 'password', 'number'], 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) { $.fn.superLabels = function(options) {
var _fields = [], var _fields = [],
Expand All @@ -48,7 +56,9 @@
// to superLabels. // to superLabels.
$(this).data('slDefaults', $.extend(_newDefaults, options || {})).addClass('sl-defaults'); $(this).data('slDefaults', $.extend(_newDefaults, options || {})).addClass('sl-defaults');


/* nominify */
if (!$.easing.def) { _info('Easing plugin not found - using standard jQuery animations.'); } 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. // 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)) { if (this.length === 1 && /form/i.test(this[0].tagName)) {
Expand All @@ -75,7 +85,9 @@


// Don't even bother going further if this isn't one of the accepted input field types or elements. // 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) { 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); _info('Doh! The following '+this.tagName.toLowerCase()+', is not supported.', this);
/* /nominify */
return true; // Equivalent to continue in a normal for loop. return true; // Equivalent to continue in a normal for loop.
} }


Expand All @@ -102,7 +114,9 @@


// Make sure this form field has a label // Make sure this form field has a label
if (_label.length === 0) { if (_label.length === 0) {
/* nominify */
_info('Doh! The following '+this.tagName.toLowerCase()+' has no related label.', this); _info('Doh! The following '+this.tagName.toLowerCase()+' has no related label.', this);
/* /nominify */
return true; return true;
} }


Expand Down Expand Up @@ -131,7 +145,8 @@
// Get the label for a given field. // Get the label for a given field.
_getLabel = function(_field) { _getLabel = function(_field) {
var _defaults = $(_field).closest('.sl-defaults').data('slDefaults'), var _defaults = $(_field).closest('.sl-defaults').data('slDefaults'),
_label = $(_field).siblings('label'); _label = $(_field).siblings('label'),
_for;


if (_label.length === 0) { if (_label.length === 0) {
// If a selector is present for the wrapping element, use that, otherwise, proceed to use more traditional methods. // If a selector is present for the wrapping element, use that, otherwise, proceed to use more traditional methods.
Expand All @@ -148,8 +163,7 @@


// Position the label. // Position the label.
_prepLabel = function(_field, _label) { _prepLabel = function(_field, _label) {
var _charLimit, var _charLimitAttr = _field.data('slCharLimit'),
_charLimitAttr = _field.data('slCharLimit'),
_defaults = $(_field).closest('.sl-defaults').data('slDefaults'), _defaults = $(_field).closest('.sl-defaults').data('slDefaults'),
_opacity = 0, _opacity = 0,
_selected; _selected;
Expand Down Expand Up @@ -198,7 +212,7 @@
_to = { opacity:0 }; _to = { opacity:0 };


if (_noVal(this)) { if (_noVal(this)) {
_label = _getLabel(this); _label = _getLabel(this);


if (_defaults.noAnimate) { if (_defaults.noAnimate) {
_label.hide(); _label.hide();
Expand Down Expand Up @@ -288,7 +302,7 @@
_approximateChars = function(_field, _label) { _approximateChars = function(_field, _label) {
var _available, var _available,
_charLen, _charLen,
_chars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' _chars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
_properties = ["font-family", "font-size", "font-weight", "letter-spacing", "line-height", "text-shadow", "text-transform"], _properties = ["font-family", "font-size", "font-weight", "letter-spacing", "line-height", "text-shadow", "text-transform"],
_tmp = $('<div>'+_chars+'</div>'); _tmp = $('<div>'+_chars+'</div>');


Expand Down Expand Up @@ -318,8 +332,22 @@
_field.data('slCharLimit', Math.floor(_available / _charLen)); _field.data('slCharLimit', Math.floor(_available / _charLen));
}; };


/* nominify */
// Console Functions (We need these to make sure this only displays when the console exists.) // 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); }; _log = function() {
_info = function() { if (defaults.debug && console && console.info) console.info.apply(console, arguments); }; if (defaults.debug && console && console.log) {
_error = function() { if (defaults.debug && console && console.error) console.error.apply(console, arguments); }; 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); })(jQuery);
6 changes: 3 additions & 3 deletions jquery.superLabels.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 1 addition & 28 deletions superLabels.jquery.json
@@ -1,28 +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"}
"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"
}

0 comments on commit 489c6a5

Please sign in to comment.