Skip to content

Commit

Permalink
Fix white space and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ten1seven committed Apr 11, 2016
1 parent be4b4fe commit bb1dde5
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 86 deletions.
180 changes: 96 additions & 84 deletions jquery.infieldLabel.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,98 @@
/*! jquery.infieldLabel.js v 1.0.1 | Author: Jeremy Fields [[email protected]], 2014 | License: MIT */

(function($){

$.infieldLabel = function(el, options){

// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;

// Access to jQuery and DOM versions of element
base.$el = $(el);

// internal variables
base.$input = null;

base.init = function() {
base.options = $.extend({}, $.infieldLabel.defaultOptions, options);

base.setup();
};


// setup
// ==========================================================================

// first time input setup
base.setup = function() {
base.$input = base.$el.find('input');
base.$label = base.$el.find('label');

// hide label if there's already a value
base.blur();

// bind events
base.bind();
};

// binds the focus, blur and change events
base.bind = function() {
base.$input
.on('focus.infield', function() {
base.$el
.removeClass(base.options.hideClass)
.addClass(base.options.focusClass);

}).on('blur.infield change.infield', function() {
base.blur();
});

base.$label.on('click.infield', function() {
base.$el
.removeClass(base.options.hideClass)
.addClass(base.options.focusClass);
base.$input.focus()
});
};

base.blur = function() {
if (base.$input.val() !== '') {
base.$el
.removeClass(base.options.focusClass)
.addClass(base.options.hideClass);

} else {
base.$el.removeClass(base.options.focusClass + ' ' + base.options.hideClass);
}
};

// run initializer
// ==========================================================================
base.init();
};

$.infieldLabel.defaultOptions = {
focusClass: 'placeholder-focus',
hideClass: 'placeholder-hide'
};

$.fn.infieldLabel = function(options) {
this.each(function(){
(new $.infieldLabel(this, options));
});
};
(function($) {

$.infieldLabel = function(el, options) {

// To avoid scope issues, use 'base' instead of 'this'
// to reference this class from internal events and functions.
var base = this;

// Access to jQuery and DOM versions of element
base.$el = $(el);

// internal variables
base.$input = null;

base.init = function() {
base.options = $.extend({}, $.infieldLabel.defaultOptions, options);
base.setup();
};


/*
--------------------
Set up
--------------------
*/

// first time input setup
base.setup = function() {
base.$input = base.$el.find('input');
base.$label = base.$el.find('label');

// hide label if there's already a value
base.blur();

// bind events
base.bind();
};

// binds the focus, blur and change events
base.bind = function() {
base.$input
.on('focus.infield', function() {
base.$el
.removeClass(base.options.hideClass)
.addClass(base.options.focusClass);

}).on('blur.infield change.infield', function() {
base.blur();
});

base.$label.on('click.infield', function() {
base.$el
.removeClass(base.options.hideClass)
.addClass(base.options.focusClass);

base.$input.focus();
});
};

base.blur = function() {
if (base.$input.val() !== '') {
base.$el
.removeClass(base.options.focusClass)
.addClass(base.options.hideClass);

} else {
base.$el
.removeClass(base.options.focusClass + ' ' + base.options.hideClass);
}
};

/*
--------------------
Initialize
--------------------
*/
base.init();
};


/*
--------------------
Options
--------------------
*/

$.infieldLabel.defaultOptions = {
focusClass: 'placeholder-focus',
hideClass: 'placeholder-hide'
};

$.fn.infieldLabel = function(options) {
this.each(function() {
new $.infieldLabel(this, options);
});
};

})(jQuery);
9 changes: 7 additions & 2 deletions jquery.infieldLabel.min.js

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

0 comments on commit bb1dde5

Please sign in to comment.