forked from marioestrada/jQuery-Watermark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.watermark.min.js
9 lines (9 loc) · 2.89 KB
/
jquery.watermark.min.js
1
2
3
4
5
6
7
8
9
/*
* jquery.watermark
* Version 1.3.3 2013-11-21
* @requires jQuery >= 1.3.2 or later
*
* Homepage: http://labs.mario.ec/jq-watermark/
* Author: Mario Estrada <[email protected]>
* License: MIT
*/!function(a){var b=/MSIE [1-7]\./.test(navigator.userAgent),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){return 0===b.length?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 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;f=a(this),k=f.attr("id"),"processed"!==f.attr("data-jq-watermark")&&(g=void 0!==f.attr("placeholder")&&""!==f.attr("placeholder")?"placeholder":"title",h=void 0===d||""===d?a(this).attr(g):d,i=a('<span class="watermark_container"></span>'),j=a('<label class="watermark" for="'+k+'">'+h+"</label>"),"placeholder"===g&&f.removeAttr("placeholder"),i.css({display:"inline-block",position:"relative"}),"true"===f.attr("data-percent-width")&&i.css("width","100%"),"true"===f.attr("data-percent-height")&&i.css("height","100%"),b&&i.css({zoom:1,display:"inline"}),f.wrap(i).attr("data-jq-watermark","processed"),"textarea"===this.nodeName.toLowerCase()?(m=parseInt(f.css("line-height"),10),m="normal"===m?parseInt(f.css("font-size"),10):m,n="auto"!==f.css("padding-top")?parseInt(f.css("padding-top"),10):0):(m=f.outerHeight(),0>=m&&(m="auto"!==f.css("padding-top")?parseInt(f.css("padding-top"),10):0,m+="auto"!==f.css("padding-bottom")?parseInt(f.css("padding-bottom"),10):0,m+="auto"!==f.css("height")?parseInt(f.css("height"),10):0)),n+="auto"!==f.css("margin-top")?parseInt(f.css("margin-top"),10):0,l="auto"!==f.css("margin-left")?parseInt(f.css("margin-left"),10):0,l+="auto"!==f.css("padding-left")?parseInt(f.css("padding-left"),10):0,j.css({position:"absolute",display:"block",fontFamily:f.css("font-family"),fontSize:f.css("font-size"),color:e.color,left:c+e.left+l,top:e.top+n,height:m,lineHeight:m+"px",textAlign:"left",pointerEvents:"none"}),a.watermarker.checkVal(f.val(),j),k||j.data("jq_watermark_element",f).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(){a(j).hide()}).bind("keyup.jq_watermark",function(){a.watermarker.checkVal(a(this).val(),j)}))}),this)},a(function(){a(".jq_watermark").watermark()})}(jQuery);