Files
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

1 line
3.8 KiB
JavaScript

tinymce.PluginManager.add("image",function(c){function b(h,g){function k(i,l){f.parentNode.removeChild(f),g({width:i,height:l})}var f=new Image;f.onload=function(){k(f.clientWidth,f.clientHeight)},f.onerror=function(){k()},f.src=h;var j=f.style;j.visibility="hidden",j.position="fixed",j.bottom=j.left=0,j.width=j.height="auto",document.body.appendChild(f)}function d(e){return function(){var f=c.settings.image_list;"string"==typeof f?tinymce.util.XHR.send({url:f,success:function(g){e(tinymce.util.JSON.parse(g))}}):e(f)}}function a(q){function w(){var f=[{text:"None",value:""}];return tinymce.each(q,function(g){f.push({text:g.text||g.title,value:g.value||g.url,menu:g.menu})}),f}function k(h){var g,m,f,l;g=B.find("#width")[0],m=B.find("#height")[0],f=g.value(),l=m.value(),B.find("#constrain")[0].checked()&&A&&t&&f&&l&&(h.control==g?(l=Math.round(f/A*l),m.value(l)):(f=Math.round(l/t*f),g.value(f))),A=f,t=l}function C(){function f(l){function h(){l.onload=l.onerror=null,c.selection.select(l),c.nodeChanged()}l.onload=function(){g.width||g.height||y.setAttribs(l,{width:l.clientWidth,height:l.clientHeight}),h()},l.onerror=h}var g=B.toJSON();""===g.width&&(g.width=null),""===g.height&&(g.height=null),""===g.style&&(g.style=null),g={src:g.src,alt:g.alt,width:g.width,height:g.height,style:g.style},z?y.setAttribs(z,g):(g.id="__mcenew",c.insertContent(y.createHTML("img",g)),z=y.get("__mcenew"),y.setAttrib(z,"id",null)),f(z)}function v(f){return f&&(f=f.replace(/px$/,"")),f}function e(){b(this.value(),function(f){f.width&&f.height&&(A=f.width,t=f.height,B.find("#width").value(A),B.find("#height").value(t))})}function E(){function g(i){return i.length>0&&/^[0-9]+$/.test(i)&&(i+="px"),i}var f=B.toJSON(),h=y.parseStyle(f.style);delete h.margin,h["margin-top"]=h["margin-bottom"]=g(f.vspace),h["margin-left"]=h["margin-right"]=g(f.hspace),h["border-width"]=g(f.border),B.find("#style").value(y.serializeStyle(y.parseStyle(y.serializeStyle(h))))}var B,D,A,t,x,y=c.dom,z=c.selection.getNode();A=y.getAttrib(z,"width"),t=y.getAttrib(z,"height"),"IMG"!=z.nodeName||z.getAttribute("data-mce-object")?z=null:D={src:y.getAttrib(z,"src"),alt:y.getAttrib(z,"alt"),width:A,height:t},q&&(x={name:"target",type:"listbox",label:"Image list",values:w(),onselect:function(g){var f=B.find("#alt");(!f.value()||g.lastControl&&f.value()==g.lastControl.text())&&f.value(g.control.text()),B.find("#src").value(g.control.value())}});var j=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:e},x,{name:"alt",type:"textbox",label:"Image description"},{type:"container",label:"Dimensions",layout:"flex",direction:"row",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:3,size:3,onchange:k},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:3,size:3,onchange:k},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}];c.settings.image_advtab?(z&&(D.hspace=v(z.style.marginLeft||z.style.marginRight),D.vspace=v(z.style.marginTop||z.style.marginBottom),D.border=v(z.style.borderWidth),D.style=c.dom.serializeStyle(c.dom.parseStyle(c.dom.getAttrib(z,"style")))),B=c.windowManager.open({title:"Insert/edit image",data:D,bodyType:"tabpanel",body:[{title:"General",type:"form",items:j},{title:"Advanced",type:"form",pack:"start",items:[{label:"Style",name:"style",type:"textbox"},{type:"form",layout:"grid",packV:"start",columns:2,padding:0,alignH:["left","right"],defaults:{type:"textbox",maxWidth:50,onchange:E},items:[{label:"Vertical space",name:"vspace"},{label:"Horizontal space",name:"hspace"},{label:"Border",name:"border"}]}]}],onSubmit:C})):B=c.windowManager.open({title:"Edit image",data:D,body:j,onSubmit:C})}c.addButton("image",{icon:"image",tooltip:"Insert/edit image",onclick:d(a),stateSelector:"img:not([data-mce-object])"}),c.addMenuItem("image",{icon:"image",text:"Insert image",onclick:d(a),context:"insert",prependToContext:!0})});