_.Module.define({path:"common/component/image_water/water_html5",requires:["common/component/image_uploader"],sub:{initial:function(a){this.options=a;this.imageUrl=a.imageUrl;this._percent=0;this._errorCode=null;this._errorMessage=null;this._response=null;this.text=a.text||{};this.font=a.font||{};this.EVENTS=["onProgressListen","onComplete","onError"]},merge:function(){this._start()},_start:function(){this.canvas=document.createElement("canvas");this.context=this.canvas.getContext("2d");var c=this.canvas;var d=this.context;var e=new Image();var b=this.imageUrl;var a=this;e.onload=function(){c.width=e.width;c.height=e.height;d.fillStyle="#ffffff";d.fillRect(0,0,c.width,c.height);d.drawImage(e,0,0,c.width,c.height);a._drawText()};e.onerror=function(){a._errorCode=1;a._errorMessage="\u56fe\u7247\u52a0\u8f7d\u9519\u8bef\uff0c\u8bf7\u68c0\u67e5\u56fe\u7247\u662f\u5426\u5b58\u5728";a._percent=100;a.trigger("onError",a._getData())};e.src=b},_drawText:function(){var j=this.text;var k=this.font;var a=this.context;var m=j.content;var c=k.size||12;var r=k.family||"";var q=j.width;var d=k.lineHeight||15;var l=(d+k.size)/2;var g=j.x;var f=j.y;var t="";var e="";a.fillStyle=(k.color||"");a.font=c+"px/"+d+"px "+r;for(var o=0;o<m.length;o++){var p=m[o];e+=p;if(a.measureText(e).width>q){a.fillText(t,g,f+l);f+=d;e=p}t=e}var n=a.measureText(e).width;var s=a.measureText(" ").width;var b=q-n;var h=parseInt(b/2/s);while(h-->0){e=" "+e}a.fillText(e,g,f+l);this._submit()},_submit:function(){var a=this;var b=this.use("common/component/image_uploader",this.options.uploadUrl);b.bind("success",function(d,e,c){a._percent=100;a._response=c;a.trigger("onComplete",a._getData())});b.bind("progress",function(e,c,d){a._percent=parseInt(c/d*90);a.trigger("onProgressListen",a._getData())});b.bind("error",function(){a._errorCode=300;a._errorMessage="\u4e0a\u4f20\u5931\u8d25";a._percent=100;a.trigger("onError",a._getData())});b.upload(this.canvas,1024*1024*5,"image/png")},_getData:function(){return{percent:this._percent,errorCode:this._errorCode,errorMessage:this._errorMessage,response:this._response}}}});