var scrawl=function(e){e&&this.initOptions(e)},ScaleBoy=((()=>{var g=$G("J_brushBoard"),m=g.getContext("2d"),a=[],f=0;scrawl.prototype={isScrawl:!1,brushWidth:-1,brushColor:"",initOptions:function(e){var t=this;t.originalState(e),t._buildToolbarColor(e.colorList),t._addBoardListener(e.saveNum),t._addOPerateListener(e.saveNum),t._addColorBarListener(),t._addBrushBarListener(),t._addEraserBarListener(),t._addAddImgListener(),t._addRemoveImgListenter(),t._addScalePicListenter(),t._addClearSelectionListenter(),t._originalColorSelect(e.drawBrushColor),t._originalBrushSelect(e.drawBrushSize),t._clearSelection()},originalState:function(e){var t=this;t.brushWidth=e.drawBrushSize,t.brushColor=e.drawBrushColor,m.lineWidth=t.brushWidth,m.strokeStyle=t.brushColor,m.fillStyle="transparent",m.lineCap="round",m.fill()},_buildToolbarColor:function(e){var t=[];t.push("<table id='J_colorList'>");for(var a,i=0;a=e[i++];)(i-1)%5==0&&(1!=i&&t.push("</tr>"),t.push("<tr>")),t.push("<td><a title='"+(a="#"+a)+"' href='javascript:void(0)' style='background-color:"+a+"'></a></td>");t.push("</tr></table>"),$G("J_colorBar").innerHTML=t.join("")},_addBoardListener:function(i){var s,r=this,o=-1,l=-1,n=!1,c=!1,d=!1,h=0,u="",p=parseInt(domUtils.getComputedStyle($G("J_wrap"),"margin-left"));a.push(m.getImageData(0,0,m.canvas.width,m.canvas.height)),f+=1,domUtils.on(g,["mousedown","mousemove","mouseup","mouseout"],function(e){switch(s=browser.webkit?e.which:h,e.type){case"mousedown":u=h=1,c=d=!(n=!0),r.isScrawl=!0,o=e.clientX-p,l=e.clientY-p,m.beginPath();break;case"mousemove":var t,a;!u&&0==s||(!u&&s&&(o=e.clientX-p,l=e.clientY-p,m.beginPath(),u=1),d)||!n||(t=e.clientX-p,a=e.clientY-p,m.moveTo(o,l),m.lineTo(t,a),m.stroke(),o=t,l=a,c=!0);break;case"mouseup":h=0,n&&(c||(m.arc(o,l,m.lineWidth,0,2*Math.PI,!1),m.fillStyle=m.strokeStyle,m.fill()),m.closePath(),r._saveOPerate(i),d=!(c=n=!1),l=o=-1);break;case"mouseout":u="",h=0,1!=s&&m.closePath()}})},_addOPerateListener:function(e){var t=this;domUtils.on($G("J_previousStep"),"click",function(){1<f&&(--f,m.clearRect(0,0,m.canvas.width,m.canvas.height),m.putImageData(a[f-1],0,0),t.btn2Highlight("J_nextStep"),1==f)&&t.btn2disable("J_previousStep")}),domUtils.on($G("J_nextStep"),"click",function(){0<f&&f<a.length&&(m.clearRect(0,0,m.canvas.width,m.canvas.height),m.putImageData(a[f],0,0),f+=1,t.btn2Highlight("J_previousStep"),f==a.length)&&t.btn2disable("J_nextStep")}),domUtils.on($G("J_clearBoard"),"click",function(){m.clearRect(0,0,m.canvas.width,m.canvas.height),a=[],t._saveOPerate(e),f=1,t.isScrawl=!1,t.btn2disable("J_previousStep"),t.btn2disable("J_nextStep"),t.btn2disable("J_clearBoard")})},_addColorBarListener:function(){var a=this;domUtils.on($G("J_colorBar"),"click",function(e){var e=a.getTarget(e),t=e.title;t&&(a._addColorSelect(e),a.brushColor=t,m.globalCompositeOperation="source-over",m.lineWidth=a.brushWidth,m.strokeStyle=t)})},_addBrushBarListener:function(){var a=this;domUtils.on($G("J_brushBar"),"click",function(e){var e=a.getTarget(e),t=browser.ie?e.innerText:e.text;t&&(a._addBESelect(e),m.globalCompositeOperation="source-over",m.lineWidth=parseInt(t),m.strokeStyle=a.brushColor,a.brushWidth=m.lineWidth)})},_addEraserBarListener:function(){var a=this;domUtils.on($G("J_eraserBar"),"click",function(e){var e=a.getTarget(e),t=browser.ie?e.innerText:e.text;t&&(a._addBESelect(e),m.lineWidth=parseInt(t),m.globalCompositeOperation="destination-out",m.strokeStyle="#FFF")})},_addAddImgListener:function(){var i=$G("J_imgTxt");window.FileReader||($G("J_addImg").style.display="none",$G("J_removeImg").style.display="none",$G("J_sacleBoard").style.display="none"),domUtils.on(i,"change",function(e){var t=i.parentNode,e=(addMaskLayer(lang.backgroundUploading),e.target||e.srcElement),a=new FileReader;a.onload=function(e){ue_callback((e.target||e.srcElement).result,"SUCCESS")},a.readAsDataURL(e.files[0]),t.reset()})},_addRemoveImgListenter:function(){var e=this;domUtils.on($G("J_removeImg"),"click",function(){$G("J_picBoard").innerHTML="",e.btn2disable("J_removeImg"),e.btn2disable("J_sacleBoard")})},_addScalePicListenter:function(){domUtils.on($G("J_sacleBoard"),"click",function(){var e=$G("J_picBoard"),t=$G("J_scaleCon"),a=e.children[0];a&&(t?"visible"==t.style.visibility?(t.style.visibility="hidden",e.style.position="",e.style.zIndex=""):(t.style.visibility="visible",e.style.cssText+="position:relative;z-index:999"):(e.style.cssText="position:relative;z-index:999;"+e.style.cssText,a.style.cssText="position: absolute;top:"+(g.height-a.height)/2+"px;left:"+(g.width-a.width)/2+"px;",t=new ScaleBoy,e.appendChild(t.init()),t.startScale(a)))})},_addClearSelectionListenter:function(){var t=document;domUtils.on(t,"mousemove",function(e){browser.ie&&browser.version<11?t.selection.clear():window.getSelection().removeAllRanges()})},_clearSelection:function(){for(var e,t=["J_operateBar","J_colorBar","J_brushBar","J_eraserBar","J_picBoard"],a=0;e=t[a++];)domUtils.unSelectable($G(e))},_saveOPerate:function(e){f=(a.length<=e?f<a.length&&(this.btn2disable("J_nextStep"),a.splice(f)):a.shift(),a.push(m.getImageData(0,0,m.canvas.width,m.canvas.height)),a.length),this.btn2Highlight("J_previousStep"),this.btn2Highlight("J_clearBoard")},_originalColorSelect:function(e){for(var t,a=$G("J_colorList").getElementsByTagName("td"),i=0;t=a[i++];)t.children[0].title.toLowerCase()==e&&(t.children[0].style.opacity=1)},_originalBrushSelect:function(e){for(var t,a=$G("J_brushBar").children,i=0;t=a[i++];)"a"==t.tagName.toLowerCase()&&(browser.ie?t.innerText:t.text).toLowerCase()==e&&(t.style.opacity=1)},_addColorSelect:function(e){for(var t,a=$G("J_colorList").getElementsByTagName("td"),i=$G("J_eraserBar").children,s=$G("J_brushBar").children,r=0;t=a[r++];)t.children[0].style.opacity=.3;for(var o,l=0;o=s[l++];)"a"==o.tagName.toLowerCase()&&(o.style.opacity=.3,(browser.ie?o.innerText:o.text).toLowerCase()==this.brushWidth)&&(o.style.opacity=1);for(var n,c=0;n=i[c++];)"a"==n.tagName.toLowerCase()&&(n.style.opacity=.3);e.style.opacity=1,e.blur()},_addBESelect:function(e){for(var t,a=$G("J_brushBar").children,i=$G("J_eraserBar").children,s=0;t=a[s++];)"a"==t.tagName.toLowerCase()&&(t.style.opacity=.3);for(var r,o=0;r=i[o++];)"a"==r.tagName.toLowerCase()&&(r.style.opacity=.3);e.style.opacity=1,e.blur()},getCanvasData:function(){var e,t=$G("J_picBoard"),a=t.children[0];a?(t="absolute"==a.style.position?(e=parseInt(a.style.left),parseInt(a.style.top)):(e=(t.offsetWidth-a.width)/2,(t.offsetHeight-a.height)/2),m.globalCompositeOperation="destination-over",m.drawImage(a,e,t,a.width,a.height)):(m.globalCompositeOperation="destination-atop",m.fillStyle="#fff",m.fillRect(0,0,g.width,g.height));try{return g.toDataURL("image/png").substring(22)}catch(e){return""}},btn2Highlight:function(e){e=$G(e);-1==e.className.indexOf("H")&&(e.className+="H")},btn2disable:function(e){e=$G(e);-1!=e.className.indexOf("H")&&(e.className=e.className.replace("H",""))},getTarget:function(e){return e.target||e.srcElement}}})(),function(){this.dom=null,this.scalingElement=null});function ue_callback(e,t){var a=document,o=$G("J_picBoard"),l=a.createElement("img");removeMaskLayer(),"SUCCESS"==t?(o.innerHTML="",l.onload=function(){t=300,a=(e=this).width||a,i=e.height||i,(t<a||t<i)&&(i<=a?(r=a-t)&&(s=(r/a).toFixed(2),e.height=i-i*s,e.width=t):(r=i-t)&&(s=(r/i).toFixed(2),e.width=a-a*s,e.height=t)),o.appendChild(l);var e,t,a,i,s,r=new scrawl;r.btn2Highlight("J_removeImg"),r.btn2Highlight("J_sacleBoard")},l.src=e):alert(t)}function removeMaskLayer(){var e=$G("J_maskLayer");e.className="maskLayerNull",e.innerHTML="",dialog.buttons[0].setDisabled(!1)}function addMaskLayer(e){var t=$G("J_maskLayer");dialog.buttons[0].setDisabled(!0),t.className="maskLayer",t.innerHTML=e}function exec(scrawlObj){var base64,successHandler,file,options,actionUrl,params,url;scrawlObj.isScrawl?(addMaskLayer(lang.scrawlUpLoading),base64=scrawlObj.getCanvasData(),base64&&(successHandler=function(e){var t={},a=editor.options.scrawlUrlPrefix+e.url;t.src=a,t._src=a,t.alt=e.original||"",editor.execCommand("insertImage",t),dialog.close(),editor.fireEvent("uploadsuccess",{res:e,type:"scrawl"})},editor.getOpt("uploadServiceEnable")?(file=utils.base64toBlob(base64,"image/png"),editor.getOpt("uploadServiceUpload")("image",file,{success:function(e){scrawlObj.isCancelScrawl||successHandler(e)},error:function(e){alert(lang.imageError+" : "+e),dialog.close()},progress:function(e){}},{from:"scrawl"})):(options={timeout:1e5,headers:editor.options.serverHeaders||{},onsuccess:function(xhr){var responseObj,responseObj;scrawlObj.isCancelScrawl||(responseObj=eval("("+xhr.responseText+")"),"SUCCESS"===responseObj.state?successHandler(responseObj):alert(responseObj.state))},onerror:function(){alert(lang.imageError),dialog.close()}},options[editor.getOpt("scrawlFieldName")]=base64,actionUrl=editor.getActionUrl(editor.getOpt("scrawlActionName")),params=utils.serializeParam(editor.queryCommandValue("serverparam"))||"",url=utils.formatUrl(actionUrl+(-1==actionUrl.indexOf("?")?"?":"&")+params),ajax.request(url,options)))):addMaskLayer(lang.noScarwl+" <input type='button' value='"+lang.continueBtn+"' onclick='removeMaskLayer()'/>")}(()=>{var r=[[1,1,-1,-1],[0,1,0,-1],[0,1,1,-1],[1,0,-1,0],[0,0,1,0],[1,0,-1,1],[0,0,0,1],[0,0,1,1]];ScaleBoy.prototype={init:function(){var e=document,t=e.getElementsByTagName("head")[0],a=e.createElement("style"),i=".scale{visibility:hidden;cursor:move;position:absolute;left:0;top:0;width:100px;height:50px;background-color:#fff;font-size:0;line-height:0;opacity:.4;filter:Alpha(opacity=40);}.scale span{position:absolute;left:0;top:0;width:6px;height:6px;background-color:#006DAE;}.scale .hand0, .scale .hand7{cursor:nw-resize;}.scale .hand1, .scale .hand6{left:50%;margin-left:-3px;cursor:n-resize;}.scale .hand2, .scale .hand4, .scale .hand7{left:100%;margin-left:-6px;}.scale .hand3, .scale .hand4{top:50%;margin-top:-3px;cursor:w-resize;}.scale .hand5, .scale .hand6, .scale .hand7{margin-top:-6px;top:100%;}.scale .hand2, .scale .hand5{cursor:ne-resize;}";a.type="text/css";try{a.appendChild(e.createTextNode(i))}catch(e){a.styleSheet.cssText=i}t.appendChild(a);var s=this,r=s.dom=(()=>{var e=[],t=document.createElement("div");t.id="J_scaleCon",t.className="scale";for(var a=0;a<8;a++)e.push("<span class='hand"+a+"'></span>");return t.innerHTML=e.join(""),t})();return s.scaleMousemove.fp=s,domUtils.on(r,"mousedown",function(e){var t=e.target||e.srcElement;s.start={x:e.clientX,y:e.clientY},-1!=t.className.indexOf("hand")&&(s.dir=t.className.replace("hand","")),domUtils.on(document.body,"mousemove",s.scaleMousemove),e.stopPropagation?e.stopPropagation():e.cancelBubble=!0}),domUtils.on(document.body,"mouseup",function(e){s.start&&(domUtils.un(document.body,"mousemove",s.scaleMousemove),s.moved&&s.updateScaledElement({position:{x:r.style.left,y:r.style.top},size:{w:r.style.width,h:r.style.height}}),delete s.start,delete s.moved,delete s.dir)}),r},startScale:function(e){this.dom.style.cssText="visibility:visible;top:"+e.style.top+";left:"+e.style.left+";width:"+e.offsetWidth+"px;height:"+e.offsetHeight+"px;",this.scalingElement=e},updateScaledElement:function(e){var t=this.scalingElement,a=e.position,e=e.size;a&&(void 0!==a.x&&(t.style.left=a.x),void 0!==a.y)&&(t.style.top=a.y),e&&(e.w&&(t.style.width=e.w),e.h)&&(t.style.height=e.h)},updateStyleByDir:function(e,t){var a,i=this,s=i.dom;r.def=[1,1,0,0],0!=r[e][0]&&(a=parseInt(s.style.left)+t.x,s.style.left=i._validScaledProp("left",a)+"px"),0!=r[e][1]&&(a=parseInt(s.style.top)+t.y,s.style.top=i._validScaledProp("top",a)+"px"),0!=r[e][2]&&(a=s.clientWidth+r[e][2]*t.x,s.style.width=i._validScaledProp("width",a)+"px"),0!=r[e][3]&&(a=s.clientHeight+r[e][3]*t.y,s.style.height=i._validScaledProp("height",a)+"px"),"def"===e&&i.updateScaledElement({position:{x:s.style.left,y:s.style.top}})},scaleMousemove:function(e){var t=arguments.callee.fp,a=t.start,a={x:e.clientX-a.x,y:e.clientY-a.y};t.updateStyleByDir(t.dir||"def",a),arguments.callee.fp.start={x:e.clientX,y:e.clientY},arguments.callee.fp.moved=1},_validScaledProp:function(e,t){var a=this.dom,i=$G("J_picBoard");switch(t=isNaN(t)?0:t,e){case"left":return t<0?0:t+a.clientWidth>i.clientWidth?i.clientWidth-a.clientWidth:t;case"top":return t<0?0:t+a.clientHeight>i.clientHeight?i.clientHeight-a.clientHeight:t;case"width":return t<=0?1:t+a.offsetLeft>i.clientWidth?i.clientWidth-a.offsetLeft:t;case"height":return t<=0?1:t+a.offsetTop>i.clientHeight?i.clientHeight-a.offsetTop:t}}}})();