base icon indicating copy to clipboard operation
base copied to clipboard

Include basic placeholder script

Open tommaitland opened this issue 11 years ago • 1 comments

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

tommaitland avatar Feb 02 '14 02:02 tommaitland

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);

scottsanders avatar Feb 03 '14 01:02 scottsanders