Files
gangyan/chat_web_front/public/UEditorPlus/dialogs/image/image.js

2 lines
16 KiB
JavaScript
Raw Normal View History

/*! UEditorPlus v2.0.0*/
!function(){function initTabs(){for(var a=$G("tabhead").children,b=0;b<a.length;b++)domUtils.on(a[b],"click",function(a){var b=a.target||a.srcElement;setTabFocus(b.getAttribute("data-content-id"))});editorOpt.disableUpload||($G("tabhead").querySelector('[data-content-id="upload"]').style.display="inline-block"),editorOpt.disableOnline||($G("tabhead").querySelector('[data-content-id="online"]').style.display="inline-block"),editorOpt.selectCallback&&($G("imageSelect").style.display="inline-block",domUtils.on($G("imageSelect"),"click",function(a){editorOpt.selectCallback(editor,function(a){if(a){$G("url").value=a.path,$G("title").value=a.name;var b=new Image;b.onload=function(){$G("width").value=b.width,$G("height").value=b.height,remoteImage.setPreview()},b.onerror=function(){remoteImage.setPreview()},b.src=a.path}})}));var c=editor.selection.getRange().getClosedNode();setTabFocus((c&&c.tagName&&"img"==c.tagName.toLowerCase(),"remote"))}function setTabFocus(a){if(a){var b,c,d=$G("tabhead").children;for(b=0;b<d.length;b++)c=d[b].getAttribute("data-content-id"),c==a?(domUtils.addClass(d[b],"focus"),domUtils.addClass($G(c),"focus")):(domUtils.removeClasses(d[b],"focus"),domUtils.removeClasses($G(c),"focus"));switch(a){case"remote":remoteImage=remoteImage||new RemoteImage;break;case"upload":setAlign(editor.getOpt("imageInsertAlign")),uploadImage=uploadImage||new UploadImage("queueList");break;case"online":setAlign(editor.getOpt("imageManagerInsertAlign")),onlineImage=onlineImage||new OnlineImage("imageList"),onlineImage.reset()}}}function initButtons(){dialog.onok=function(){for(var a,b=!1,c=[],d=$G("tabhead").children,e=0;e<d.length;e++)if(domUtils.hasClass(d[e],"focus")){a=d[e].getAttribute("data-content-id");break}switch(a){case"remote":c=remoteImage.getInsertList();break;case"upload":c=uploadImage.getInsertList();var f=uploadImage.getQueueCount();if(f)return $(".info","#queueList").html('<span style="color:red;">'+"还有2个未上传文件".replace(/[\d]/,f)+"</span>"),!1;break;case"online":c=onlineImage.getInsertList()}c&&(editor.execCommand("insertimage",c),b&&editor.fireEvent("catchRemoteImage"))}}function initAlign(){domUtils.on($G("alignIcon"),"click",function(a){var b=a.target||a.srcElement;b.className&&b.className.indexOf("-align")!=-1&&setAlign(b.getAttribute("data-align"))})}function setAlign(a){a=a||"none";var b=$G("alignIcon").children;for(i=0;i<b.length;i++)b[i].getAttribute("data-align")==a?(domUtils.addClass(b[i],"focus"),$G("align").value=b[i].getAttribute("data-align")):domUtils.removeClasses(b[i],"focus")}function getAlign(){var a=$G("align").value||"none";return"none"==a?"":a}function RemoteImage(a){this.container=utils.isString(a)?document.getElementById(a):a,this.init()}function UploadImage(a){this.$wrap=a.constructor==String?$("#"+a):$(a),this.init()}function OnlineImage(a){this.container=utils.isString(a)?document.getElementById(a):a,this.init()}var remoteImage,uploadImage,onlineImage,editorOpt={};window.onload=function(){editorOpt=editor.getOpt("imageConfig"),initTabs(),initAlign(),initButtons()},RemoteImage.prototype={init:function(){this.initContainer(),this.initEvents()},initContainer:function(){this.dom={url:$G("url"),width:$G("width"),height:$G("height"),border:$G("border"),vhSpace:$G("vhSpace"),title:$G("title"),align:$G("align")};var a=editor.selection.getRange().getClosedNode();a&&this.setImage(a)},initEvents:function(){function a(){b.setPreview()}var b=this,c=$G("lock");domUtils.on($G("url"),"keyup",a),domUtils.on($G("border"),"keyup",a),domUtils.on($G("title"),"keyup",a),domUtils.on($G("width"),"keyup",function(){if(c.checked){var d=c.getAttribute("data-proportion");$G("height").value=Math.round(this.value/d)}else b.updateLocker();a()}),domUtils.on($G("height"),"keyup",function(){if(c.checked){var d=c.getAttribute("data-proportion");$G("width").value=Math.round(this.value*d)}else b.updateLocker();a()}),domUtils.on($G("lock"),"change",function(){var a=parseInt($G("width").value)/parseInt($G("height").value);c.setAttribute("data-proportion",a)})},updateLocker:function(){var a=$G("width").v