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

1 line
2.3 KiB
JavaScript
Raw Normal View History

2014-07-14 22:59:00 +08:00
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,a=t.selection.getContent(),o=/<img.*?\/>/g,d=a.match(o),c=document.createElement("p"),g=[];for(var h in d){c.innerHTML=d[h];var l=c.firstChild;if(l&&"IMG"==l.nodeName){var s={};s.src=r.getAttrib(l,"data-src")||r.getAttrib(l,"src"),s.width=r.getAttrib(l,"width"),s.height=r.getAttrib(l,"height"),s.title=r.getAttrib(l,"title"),g.push(s)}}LEAUI_DATAS=g,win=t.windowManager.open({title:"Manage Image",width:885,height:475,html:n(),buttons:[{text:"Insert Image",subtype:"primary",onclick:function(n){for(var a=document.getElementById("leauiIfr").contentWindow,o=a.document.getElementById("preview"),d=o.childNodes,c=[],g=0;g<d.length;++g){var n=d[g];if(n.firstChild&&"IMG"==n.firstChild.nodeName){var h=n.firstChild,l={};l.src=h.getAttribute("src"),l.width=h.getAttribute("data-width"),l.height=h.getAttribute("data-height"),l.title=h.getAttribute("data-title"),c.push(l)}}for(var g in c){var s,m=c[g],u=m.src;s=-1!=u.indexOf("http://")||-1!=u.indexOf("https://")?u:e+"/"+u,m.src=s;var f=function(e,i){var n,a={};return a.id="__mcenew"+i,a.src="http://leanote.com/images/loading-24.gif",n=r.createHTML("img",a),t.insertContent(n),n=r.get(a.id),log(n),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)}}(m,g);i(m.src,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")})});