iotgateway/IoTGateway/wwwroot/layuiadmin/ueditor/dialogs/image/image.js

3 lines
100 KiB
JavaScript
Raw Normal View History

2021-12-12 06:55:48 +00:00
/** layuiAdmin.pro-v1.2.1 LPPL License By http://www.layui.com/admin/ */
;!function(){function initTabs(){for(var C=$G("tabhead").children,B=0;B<C.length;B++)domUtils.on(C[B],"click",function(C){var B=C.target||C.srcElement;setTabFocus(B.getAttribute("data-content-id"))});var D=editor.selection.getRange().getClosedNode();setTabFocus(D&&D.tagName&&"img"==D.tagName.toLowerCase()?"remote":"upload")}function setTabFocus(C){if(C){var B,D,E=$G("tabhead").children;for(B=0;B<E.length;B++)D=E[B].getAttribute("data-content-id"),D==C?(domUtils.addClass(E[B],"focus"),domUtils.addClass($G(D),"focus")):(domUtils.removeClasses(E[B],"focus"),domUtils.removeClasses($G(D),"focus"));switch(C){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();break;case"search":setAlign(editor.getOpt("imageManagerInsertAlign")),searchImage=searchImage||new SearchImage}}}function initButtons(){dialog.onok=function(){for(var C,B=!1,D=[],E=$G("tabhead").children,F=0;F<E.length;F++)if(domUtils.hasClass(E[F],"focus")){C=E[F].getAttribute("data-content-id");break}switch(C){case"remote":D=remoteImage.getInsertList();break;case"upload":D=uploadImage.getInsertList();var A=uploadImage.getQueueCount();if(A)return $(".info","#queueList").html('<span style="color:red;">'+"还有2个未上传文件".replace(/[\d]/,A)+"</span>"),!1;break;case"online":D=onlineImage.getInsertList();break;case"search":D=searchImage.getInsertList(),B=!0}D&&(editor.execCommand("insertimage",D),B&&editor.fireEvent("catchRemoteImage"))}}function initAlign(){domUtils.on($G("alignIcon"),"click",function(C){var B=C.target||C.srcElement;B.className&&B.className.indexOf("-align")!=-1&&setAlign(B.getAttribute("data-align"))})}function setAlign(C){C=C||"none";var B=$G("alignIcon").children;for(i=0;i<B.length;i++)B[i].getAttribute("data-align")==C?(domUtils.addClass(B[i],"focus"),$G("align").value=B[i].getAttribute("data-align")):domUtils.removeClasses(B[i],"focus")}function getAlign(){var C=$G("align").value||"none";return"none"==C?"":C}function RemoteImage(C){this.container=utils.isString(C)?document.getElementById(C):C,this.init()}function UploadImage(C){this.$wrap=C.constructor==String?$("#"+C):$(C),this.init()}function OnlineImage(C){this.container=utils.isString(C)?document.getElementById(C):C,this.init()}function SearchImage(){this.init()}var remoteImage,uploadImage,onlineImage,searchImage;window.onload=function(){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 C=editor.selection.getRange().getClosedNode();C&&this.setImage(C)},initEvents:function(){function C(){B.setPreview()}var B=this,D=$G("lock");domUtils.on($G("url"),"keyup",C),domUtils.on($G("border"),"keyup",C),domUtils.on($G("title"),"keyup",C),domUtils.on($G("width"),"keyup",function(){if(C(),D.checked){var E=D.getAttribute("data-proportion");$G("height").value=Math.round(this.value/E)}else B.updateLocker()}),domUtils.on($G("height"),"keyup",function(){if(C(),D.checked){var E=D.getAttribute("data-proportion");$G("width").value=Math.round(this.value*E)}else B.updateLocker()}),domUtils.on($G("lock"),"change",function(){var C=parseInt($G("width").value)/parseInt($G("height").value);D.setAttribute("data-proportion",C)})},updateLocker:function(){var C=$G("width").value,B=$G("height").value,D=$G("lock");C&&B&&C==parseInt(C)&&B==parseInt(B)?(D.disabled=!1,D.title=""):(D.checked=!1,D.disabled="disabled",D.title=lang.remoteLockError)},setImage:function(C){if(C.tagName&&("img"==C.tagName.toLowerCase()||C.getAttribute("src"))&&C.src){var B=C.getAttribute("word_img"),D=B?B.replace("&amp;","&"):C.getAttribute("_src")||C.getAttribute("src",2).replace("&amp;","&"),E=editor.queryCommandValue("imageFloat");D!==$G("url").value&&($G
var F=C.charAt(E),A=C.charCodeAt(E);if(" "==F)B+="+";else if(A>=19968&&A<=40869){var e=A-19968;B+="%"+D.substr(4*e,2)+"%"+D.substr(4*e+2,2)}else B+="%"+C.charCodeAt(E).toString(16)}return B},scale:function(C,B,D){var E=C.width,F=C.height;E>=F?(C.width=B*E/F,C.height=D,C.style.marginLeft="-"+parseInt((C.width-B)/2)+"px"):(C.width=B,C.height=D*F/E,C.style.marginTop="-"+parseInt((C.height-D)/2)+"px")},getImageData:function(){var C=this,B=$G("searchTxt").value,D=($G("searchType").value,editor.options.keepOriginName?"1":"0","http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1569221553883_R&pv=&ic=0&nc=1&z=0&hd=0&latest=0&copyright=0&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&sid=&word="+C.encodeToGb2312(B));$G("searchListUl").innerHTML=lang.searchLoading,ajax.request(D,{dataType:"jsonp",charset:"GB18030",onsuccess:function(B){var D=[];if(B&&B.data)for(var E=0;E<B.data.length;E++)B.data[E].objURL&&D.push({title:B.data[E].fromPageTitleEnc,src:B.data[E].objURL,url:B.data[E].fromURL});C.setList(D)},onerror:function(){$G("searchListUl").innerHTML=lang.searchRetry}})},setList:function(C){var B,D,E,F,A,e=this,t=$G("searchListUl");if(t.innerHTML="",C.length)for(B=0;B<C.length;B++)D=document.createElement("li"),E=document.createElement("p"),F=document.createElement("img"),A=document.createElement("a"),F.onload=function(){e.scale(this,113,113)},F.width=113,F.setAttribute("src",C[B].src),A.href=C[B].url,A.target="_blank",A.title=C[B].title,A.innerHTML=C[B].title,E.appendChild(F),D.appendChild(E),D.appendChild(A),t.appendChild(D);else t.innerHTML=lang.searchRetry},getInsertList:function(){for(var C,B,D=getAlign(),E=[],F=$G("searchListUl").children,A=0;A<F.length;A++)C=F[A].firstChild&&F[A].firstChild.firstChild,C.tagName&&"img"==C.tagName.toLowerCase()&&domUtils.hasClass(F[A],"selected")&&(B=C.src,E.push({src:B,_src:B,alt:B.substr(B.lastIndexOf("/")+1),floatStyle:D}));return E}}}();