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