Files
leanote/public/tinymce/plugins/leaui_image/plugin.min.js

1 line
2.8 KiB
JavaScript
Raw Normal View History

var LEAUI_DATAS=[];tinymce.PluginManager.add("leaui_image",function(t,e){function i(t,e){function i(t,i){n.parentNode.removeChild(n),e({width:t,height:i})}var n=document.createElement("img");n.onload=function(){i(n.clientWidth,n.clientHeight)},n.onerror=function(){i()},n.src=t;var r=n.style;r.visibility="hidden",r.position="fixed",r.bottom=r.left=0,r.width=r.height="auto",document.body.appendChild(n)}function n(){function n(){var t='<iframe id="leauiIfr" src="'+e+"/index.html?"+(new Date).getTime()+'" frameborder="0"></iframe>';return t}var r=t.dom,o=t.selection.getContent(),a=/<img.*?\/>/g,d=o.match(a),c=document.createElement("p"),l=[];for(var s in d){c.innerHTML=d[s];var g=c.firstChild;if(g&&"IMG"==g.nodeName){var h={};h.src=r.getAttrib(g,"data-src")||r.getAttrib(g,"src"),h.width=r.getAttrib(g,"width"),h.height=r.getAttrib(g,"height"),h.title=r.getAttrib(g,"title"),l.push(h)}}LEAUI_DATAS=l,win=t.windowManager.open({title:"Manage Image",width:885,height:475,html:n(),buttons:[{text:"Insert Image",subtype:"primary",onclick:function(n){for(var o=document.getElementById("leauiIfr").contentWindow,a=o.document.getElementById("preview"),d=a.childNodes,c=[],l=0;l<d.length;++l){var n=d[l];if(n.firstChild&&"IMG"==n.firstChild.nodeName){var s=n.firstChild,g={};g.src=s.getAttribute("src"),g.width=s.getAttribute("data-width"),g.height=s.getAttribute("data-height"),g.title=s.getAttribute("data-title"),c.push(g)}}for(var l in c){var h,f=c[l],u=f.src;h=-1!=u.indexOf("http://")||-1!=u.indexOf("https://")?u:e+"/"+u,f.src=h;var m=function(e){var n=function(e,i){var n,o={};return o.id="__mcenew"+i,o.src="http://leanote.com/images/loading-24.gif",n=r.createHTML("img",o),t.insertContent(n),n=r.get(o.id),function(t){t&&t.width&&(t.width>600&&(t.width=600),e.width=t.width),r.setAttrib(n,"src",e.src),r.setAttrib(n,"width",e.width),r.setAttrib(n,"title",e.title),r.setAttrib(n,"id",null)}}(e,l);i(e.src,n)},I="";if(fileIds=h.split("fileId="),2==fileIds.length&&fileIds[1].length=="53aecf8a8a039a43c8036282".length&&(I=fileIds[1]),I){var p=Note.getCurNote();p&&p.UserId!=UserInfo.UserId?!function(t){ajaxPost("/file/copyImage",{userId:UserInfo.UserId,fileId:I,toUserId:p.UserId},function(e){if(reIsOk(e)&&e.Id){var i=window.location.protocol+"//"+window.location.host;t.src=i+"/file/outputImage?fileId="+e.Id}m(t)})}(f):m(f)}else m(f)}this.parent().parent().close()}},{text:"Cancel",onclick:function(){this.parent().parent().close()}}]})}t.addButton("leaui_image",{icon:"image",tooltip:"Insert/edit image",onclick:n,stateSelector:"img:not([data-mce-object])"}),t.addMenuItem("leaui_image",{icon:"image",text:"Insert image",onclick:n,context:"insert",prependToContext:!0});var r=!1;t.on("dragstart",function(){r=!0}),t.on("dragend",function(){r=!1}),t.on("dragover",function(){r||$("body").trigger("dragover")})});