base
base copied to clipboard
Include basic placeholder script
This starts precedent for some JS in Base with some bare-bones compadibility fixes, Modernizr style.
For placeholder https://gist.github.com/hagenburger/379601 is a good place to start
I wrote one of these when we were first working on base. Not sure if its still useful, but here it is:
(function($){
$.fn.placeholder = function() {
return this.each(function() {
//variables
var element = $(this);
var placeholder = element.attr("placeholder");
//set default placeholder
element.val(placeholder).addClass("placeholder");
//remove any labels provided for non-js users
if(element.attr("id").length > 0){
$("label[for="+element.attr("id")+"]").remove();
}
//show/hide placeholder on blur/focus
element.focus(function(){
if(element.val()==placeholder)
element.val("").removeClass("placeholder");
}).blur(function(){
if(element.val()=="")
element.val(placeholder).addClass("placeholder");
});
});
};
})(jQuery);