!function(e,t){"function"==typeof define&&define.amd?define([],t()):"object"==typeof module&&module.exports?module.exports=t():e.watermark=t()}(this,function(){function a(e){if(1===arguments.length&&"object"==typeof e){var t=e||{};for(key in t)t[key]&&E[key]&&t[key]===E[key]||!t[key]&&0!==t[key]||(E[key]=t[key])}var a=document.getElementById(E.watermark_id);if(a){var r=a.parentNode;r&&r.removeChild(a)}var o=Math.max(document.body.scrollWidth,document.body.clientWidth)-E.watermark_width/2,m=Math.max(document.body.scrollHeight,document.body.clientHeight,document.documentElement.clientHeight)-E.watermark_height/2,n=e||{},w=E.watermark_parent_node,i=0,_=0;n.watermark_parent_width||n.watermark_parent_height?(n.watermark_parent_width?o=n.watermark_parent_width-E.watermark_width/2:E.watermark_parent_node&&(o=w.offsetWidth-E.watermark_width/2),n.watermark_parent_height?m=n.watermark_parent_height-E.watermark_height/2:E.watermark_parent_node&&(m=Math.max(w.offsetHeight,w.scrollHeight)-E.watermark_height/2),w&&(i=w.offsetTop||0,_=w.offsetLeft||0,E.watermark_x=E.watermark_x+_,E.watermark_y=E.watermark_y+i)):w&&(i=w.offsetTop||0,_=w.offsetLeft||0,o=w.offsetWidth-E.watermark_width/2||0,m=Math.max(w.offsetHeight,w.scrollHeight)-E.watermark_height/2||0,E.watermark_x=E.watermark_x+_,E.watermark_y=E.watermark_y+i);var k=document.getElementById(E.watermark_id),d=null;if(k)k.shadowRoot&&(d=k.shadowRoot);else{(k=document.createElement("div")).id=E.watermark_id,k.style.pointerEvents="none",k.style.overflow="hidden",d="function"==typeof k.attachShadow?k.attachShadow({mode:"open"}):k;var l=document.body.children,s=Math.floor(Math.random()*(l.length-1));l[s]?document.body.insertBefore(k,l[s]):document.body.appendChild(k)}var h=E.watermark_x+_+E.watermark_width*E.watermark_cols+E.watermark_x_space*(E.watermark_cols-1);if(0==E.watermark_cols||h+E.watermark_width<o||o<h){E.watermark_cols=parseInt((o-E.watermark_x+_)/(E.watermark_width+E.watermark_x_space/2));var c=parseInt((o-E.watermark_x+_-E.watermark_width*E.watermark_cols)/E.watermark_cols);E.watermark_x_space=c?E.watermark_x_space:c}var y,p,f=E.watermark_y+i+E.watermark_height*E.watermark_rows+E.watermark_y_space*(E.watermark_rows-1);if(0==E.watermark_rows||f+E.watermark_height<m||m<f){E.watermark_rows=parseInt((m-E.watermark_y+i)/(E.watermark_height+E.watermark_y_space/2));var u=parseInt((o-E.watermark_x+_-E.watermark_width*E.watermark_cols)/E.watermark_cols);E.watermark_y_space=u?E.watermark_y_space:u}for(var g=0;g<E.watermark_rows;g++){p=E.watermark_y+(E.watermark_y_space+E.watermark_height)*g;for(var x=0;x<E.watermark_cols;x++){y=E.watermark_x+(E.watermark_width+E.watermark_x_space)*x;var v=document.createElement("div"),b=document.createTextNode(E.watermark_txt);v.appendChild(b),v.id=E.watermark_prefix+g+x,v.className="watermark",v.style.webkitTransform="rotate(-"+E.watermark_angle+"deg)",v.style.MozTransform="rotate(-"+E.watermark_angle+"deg)",v.style.msTransform="rotate(-"+E.watermark_angle+"deg)",v.style.OTransform="rotate(-"+E.watermark_angle+"deg)",v.style.transform="rotate(-"+E.watermark_angle+"deg)",v.style.visibility="",v.style.position="absolute",v.style.left=y+"px",v.style.top=p+"px",v.style.zIndex="9999999",v.style.opacity=E.watermark_alpha,v.style.filter="alpha(opacity="+100*E.watermark_alpha+")",v.style.fontSize=E.watermark_fontsize,v.style.fontFamily=E.watermark_font,v.style.color=E.watermark_color,v.style.textAlign="center",v.style.width=E.watermark_width+"px",v.style.height=E.watermark_height+"px",v.style.display="block",v.style["-ms-user-select"]="none",d.appendChild(v)}}}var e={},E={watermark_id:"wm_div_id",watermark_prefix:"mask_div_id",watermark_txt:"测试水印",watermark_x:20,watermark_y:20,watermark_rows:0,watermark_cols:0,watermark_x_space:50,watermark_y_space:50,watermark_font:"微软雅黑",watermark_color:"black",watermark_fontsize:"18px",watermark_alpha:.15,watermark_width:100,watermark_height:100,watermark_angle:15,watermark_parent_width:0,watermark_parent_height:0,watermark_parent_node:null};return e.init=function(e){Function.prototype.bind||(Function.prototype.bind=function(){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=this,t=arguments[0],a=Array.prototype.slice.call(arguments,1);return function(){e.apply(t,a)}});function t(e,t,a){e.addEventListener?e.addEventListener(t,a,!1):e.attachEvent("on"+t,a.bind(e))}t(window,"load",function(){a(e)}),t(window,"resize",function(){a(e)}),t(window,"DOMContentLoaded",function(){a(e)})},e.load=function(e){a(e)},e.remove=function(){!function(){if(1===arguments.length&&"object"==typeof arguments[0]){var e=arguments[0]||{};for(key in e)e[key]&&E[key]&&e[key]===E[key]||!e[key]&&0!==e[key]||(E[key]=e[key])}var t=document.getElementById(E.watermark_id);t.parentNode.removeChild(t)}()},e});
