PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/jquery-watermark/wiki/jquery.watermark-1.0-min.js

http://jquery-watermark.googlecode.com/
JavaScript | 7 lines | 1 code | 0 blank | 6 comment | 0 complexity | 833306ad2a3373d8ebbefe71a17f7a11 MD5 | raw file
1/*
2	Watermark jQuery plugin v1.0
3	Copyright (c) 2009 Todd Northrop
4	http://www.speednet.biz/
5	Licensed under GPL 3, see  <http://www.gnu.org/licenses/>
6*/
7(function($){var f;$.extend($.expr[":"],{"data":function(a,b,c,d){var e,p=/^((?:[^=!^$*]|[!^$*](?!=))+)(?:([!^$*]?=)(.*))?$/.exec(c[3]);if(p){e=$(a).data(p[1]);if(e!==f){if(p[2]){e=""+e;switch(p[2]){case"=":return(e==p[3]);case"!=":return(e!=p[3]);case"^=":return(e.slice(0,p[3].length)==p[3]);case"$=":return(e.slice(-p[3].length)==p[3]);case"*=":return(e.indexOf(p[3])!==-1)}}return true}}return false}});$.watermark={className:"watermark",hide:function(a){$(a).filter(":data(watermark)").each(function(){$.watermark._hide($(this))})},_hide:function(a){if(a.val()==a.data("watermarkText")){a.val("")}a.removeClass(a.data("watermarkClass"))},show:function(a){$(a).filter(":data(watermark)").each(function(){$.watermark._show($(this))})},_show:function(a){var b=a.val(),text=a.data("watermarkText");if(((b.length==0)||(b==text))&&(!a.data("watermarkFocus"))){a.val(text);a.addClass(a.data("watermarkClass"))}else{$.watermark._hide(a)}},hideAll:function(){$.watermark.hide(":text")},showAll:function(){$.watermark.show(":text")}};$.fn.watermark=function(c,d){var e=(typeof(c)==="string"),hasClass=(typeof(d)==="string");return this.filter(":text").each(function(){var a=$(this);if(a.data("watermark")){if(e||hasClass){$.watermark._hide(a);if(e){a.data("watermarkText",c)}if(hasClass){a.data("watermarkClass",d)}}}else{a.data("watermarkText",e?c:"");a.data("watermarkClass",hasClass?d:$.watermark.className);a.data("watermark",1);a.focus(function(){a.data("watermarkFocus",1);$.watermark._hide(a)}).blur(function(){a.data("watermarkFocus",0);$.watermark._show(a)});var b=$(this.form);if(!b.data("watermark")){b.data("watermark",1);b.submit($.watermark.hideAll)}}$.watermark._show(a)}).end()}})(jQuery);