/ Published in: jQuery
/* .labelInside() jQuery plugin per visualizzare la label in grigetto all'interno del campo author: s.caronia */
Expand |
Embed | Plain Text
(function($){ $.fn.labelInside = function(arguments) { var defaults = {}; var options = {}; var title; if (typeof(arguments)!="object") { options=defaults; options.title=arguments; } else { options = $.extend(defaults, arguments); } return this.each(function() { if (options.action=="clean") { if ($(this).val()==$(this).attr('title')) { $(this).val(""); } return this; } if ($(this).attr('title')) { title=$(this).attr('title'); } else { if (options.title) { title = options.title; $(this).attr('title',title); } else { title = ''; } } defaulIfEmpty($(this), title, options.defaultClass); $(this).focus(function(){ if ($(this).val()==$(this).attr('title')) { $(this).val(""); } }); $(this).keypress(function(event){ if ($(this).val()==$(this).attr('title')) { $(this).val(""); } }); $(this).keyup(function(event){ if (event.which!=(9||15)) defaulIfEmpty($(this), $(this).attr('title'), options.defaultClass); }); $(this).blur(function(){ defaulIfEmpty($(this), $(this).attr('title'), options.defaultClass); }); $(this).change(function(){ defaulIfEmpty($(this), $(this).attr('title'), options.defaultClass); }); function defaulIfEmpty(el, ti, dc) { if (el.nodeName=='textarea') { if ((el.html()=="") || (el.html(ti))) { el.html(ti); el.addClass(dc); } else { el.removeClass(dc);} } else { if ((el.val()=="") || (el.val()==ti)) { el.val(ti); el.addClass(dc); } else { el.removeClass(dc);} } el.attr('title',ti); } }); } }) (jQuery);
You need to login to post a comment.
