forked from marioestrada/jQuery-Watermark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.watermark.min.js
12 lines (12 loc) · 2.99 KB
/
jquery.watermark.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
* jQuery Watermark plugin
* Version 1.3.1 (23-MAR-2012)
* @requires jQuery v1.3 or later
*
* Examples at: http://mario.ec/static/jq-watermark/
* Copyright (c) 2010 Mario Estrada
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
(function(a){var b=a.browser.msie&&a.browser.version<8,c=4;a.watermarker=function(){},a.extend(a.watermarker,{defaults:{color:"#999",left:0,top:0,fallback:!1,animDuration:300,minOpacity:.6},setDefaults:function(b){a.extend(a.watermarker.defaults,b)},checkVal:function(b,c,d){return b.length==0?a(c).show():a(c).hide(),b.length>0},html5_support:function(){var a=document.createElement("input");return"placeholder"in a}}),a.fn.watermark=function(d,e){var e,f;return e=a.extend(a.watermarker.defaults,e),f=this.filter("textarea, input:not(:checkbox,:radio,:file,:submit,:reset)"),e.fallback&&a.watermarker.html5_support()?this:(f.each(function(){var f,g,h,i,j,k,l,m,n=0,o,p;f=a(this);if(f.attr("data-jq-watermark")=="processed")return;g=f.attr("placeholder")!=undefined&&f.attr("placeholder")!=""?"placeholder":"title",h=d===undefined||d===""?a(this).attr(g):d,i=a('<span class="watermark_container"></span>'),j=a('<span class="watermark">'+h+"</span>"),g=="placeholder"&&f.removeAttr("placeholder"),i.css({display:"inline-block",position:"relative"}),f.attr("data-percent-width")=="true"&&i.css("width","100%"),f.attr("data-percent-height")=="true"&&i.css("height","100%"),b&&i.css({zoom:1,display:"inline"}),f.wrap(i).attr("data-jq-watermark","processed"),this.nodeName.toLowerCase()=="textarea"?(e_height=f.css("line-height"),e_height=e_height==="normal"?parseInt(f.css("font-size")):e_height,n=f.css("padding-top")!="auto"?parseInt(f.css("padding-top")):0):(e_height=f.outerHeight(),e_height<=0&&(e_height=f.css("padding-top")!="auto"?parseInt(f.css("padding-top")):0,e_height+=f.css("padding-bottom")!="auto"?parseInt(f.css("padding-bottom")):0,e_height+=f.css("height")!="auto"?parseInt(f.css("height")):0)),n+=f.css("margin-top")!="auto"?parseInt(f.css("margin-top")):0,k=f.css("margin-left")!="auto"?parseInt(f.css("margin-left")):0,k+=f.css("padding-left")!="auto"?parseInt(f.css("padding-left")):0,j.css({position:"absolute",display:"block",fontFamily:f.css("font-family"),fontSize:f.css("font-size"),color:e.color,left:c+e.left+k,top:e.top+n,height:e_height,lineHeight:e_height+"px",textAlign:"left",pointerEvents:"none"}).data("jq_watermark_element",f),a.watermarker.checkVal(f.val(),j),j.click(function(){a(a(this).data("jq_watermark_element")).trigger("click").trigger("focus")}),f.before(j).bind("focus.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),j)||j.stop().fadeTo(e.animDuration,e.minOpacity)}).bind("blur.jq_watermark change.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),j)||j.stop().fadeTo(e.animDuration,1)}).bind("keydown.jq_watermark, paste.jq_watermark",function(b){a(j).hide()}).bind("keyup.jq_watermark",function(b){a.watermarker.checkVal(a(this).val(),j)})}),this)},a(function(){a(".jq_watermark").watermark()})})(jQuery)