Skip to content

Instantly share code, notes, and snippets.

@carlalexander
Created November 9, 2011 04:02
Show Gist options
  • Save carlalexander/1350311 to your computer and use it in GitHub Desktop.
Save carlalexander/1350311 to your computer and use it in GitHub Desktop.
Form label plugin for bootstrap
!function( $ ){
/* FORM LABEL PLUGIN DEFINITION
* ============================ */
$.fn.formLabel = function ( options ) {
var options = $.extend({}, $.fn.formLabel.defaults, options);
return this.each(function () {
var $holding = $(this),
$input = $holding.find(':input'),
input = $input[0],
$holder = $holding.find(options.selector);
function show() {
$holding.removeClass('hassome');
};
function hide() {
$holding.addClass('hassome');
};
function focus() {
if (input.value.length) hide();
else show();
};
$holder.click(function() {
$input.focus();
focus();
});
$input.focusin(function() {
$holder.addClass('dimmed');
});
$input.focusout(function() {
$holder.removeClass('dimmed');
});
$input.bind('focus blur change cut paste input keyup', function(e){
focus();
});
})
}
$.fn.formLabel.defaults = {
selector: '.holder'
}
}( window.jQuery || window.ender );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment