Created
November 9, 2011 04:02
-
-
Save carlalexander/1350311 to your computer and use it in GitHub Desktop.
Form label plugin for bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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