summaryrefslogtreecommitdiff
path: root/program/js/tinymce/plugins/image/plugin.min.js
blob: 14e5bbd9612764725ef9b5985ec19dd113340430 (plain)
1
tinymce.PluginManager.add("image",function(e){function t(e,t){function i(e,i){n.parentNode&&n.parentNode.removeChild(n),t({width:e,height:i})}var n=document.createElement("img");n.onload=function(){i(n.clientWidth,n.clientHeight)},n.onerror=function(){i()};var a=n.style;a.visibility="hidden",a.position="fixed",a.bottom=a.left=0,a.width=a.height="auto",document.body.appendChild(n),n.src=e}function i(e,t,i){function n(e,i){return i=i||[],tinymce.each(e,function(e){var a={text:e.text||e.title};e.menu?a.menu=n(e.menu):(a.value=e.value,t(a)),i.push(a)}),i}return n(e,i||[])}function n(t){return function(){var i=e.settings.image_list;"string"==typeof i?tinymce.util.XHR.send({url:i,success:function(e){t(tinymce.util.JSON.parse(e))}}):"function"==typeof i?i(t):t(i)}}function a(n){function a(){var e,t,i,n;e=c.find("#width")[0],t=c.find("#height")[0],e&&t&&(i=e.value(),n=t.value(),c.find("#constrain")[0].checked()&&d&&u&&i&&n&&(d!=i?(n=Math.round(i/d*n),t.value(n)):(i=Math.round(n/u*i),e.value(i))),d=i,u=n)}function l(){function t(t){function i(){t.onload=t.onerror=null,e.selection&&(e.selection.select(t),e.nodeChanged())}t.onload=function(){m.width||m.height||!y||p.setAttribs(t,{width:t.clientWidth,height:t.clientHeight}),i()},t.onerror=i}s(),a(),m=tinymce.extend(m,c.toJSON()),m.alt||(m.alt=""),""===m.width&&(m.width=null),""===m.height&&(m.height=null),m.style||(m.style=null),m={src:m.src,alt:m.alt,width:m.width,height:m.height,style:m.style,"class":m["class"]},e.undoManager.transact(function(){return m.src?(f?p.setAttribs(f,m):(m.id="__mcenew",e.focus(),e.selection.setContent(p.createHTML("img",m)),f=p.get("__mcenew"),p.setAttrib(f,"id",null)),void t(f)):void(f&&(p.remove(f),e.focus(),e.nodeChanged()))})}function o(e){return e&&(e=e.replace(/px$/,"")),e}function r(i){var n=i.meta||{};g&&g.value(e.convertURL(this.value(),"src")),tinymce.each(n,function(e,t){c.find("#"+t).value(e)}),n.width||n.height||t(this.value(),function(e){e.width&&e.height&&y&&(d=e.width,u=e.height,c.find("#width").value(d),c.find("#height").value(u))})}function s(){function t(e){return e.length>0&&/^[0-9]+$/.test(e)&&(e+="px"),e}if(e.settings.image_advtab){var i=c.toJSON(),n=p.parseStyle(i.style);delete n.margin,n["margin-top"]=n["margin-bottom"]=t(i.vspace),n["margin-left"]=n["margin-right"]=t(i.hspace),n["border-width"]=t(i.border),c.find("#style").value(p.serializeStyle(p.parseStyle(p.serializeStyle(n))))}}var c,d,u,g,h,m={},p=e.dom,f=e.selection.getNode(),y=e.settings.image_dimensions!==!1;d=p.getAttrib(f,"width"),u=p.getAttrib(f,"height"),"IMG"!=f.nodeName||f.getAttribute("data-mce-object")||f.getAttribute("data-mce-placeholder")?f=null:m={src:p.getAttrib(f,"src"),alt:p.getAttrib(f,"alt"),"class":p.getAttrib(f,"class"),width:d,height:u},n&&(g={type:"listbox",label:"Image list",values:i(n,function(t){t.value=e.convertURL(t.value||t.url,"src")},[{text:"None",value:""}]),value:m.src&&e.convertURL(m.src,"src"),onselect:function(e){var t=c.find("#alt");(!t.value()||e.lastControl&&t.value()==e.lastControl.text())&&t.value(e.control.text()),c.find("#src").value(e.control.value()).fire("change")},onPostRender:function(){g=this}}),e.settings.image_class_list&&(h={name:"class",type:"listbox",label:"Class",values:i(e.settings.image_class_list,function(t){t.value&&(t.textStyle=function(){return e.formatter.getCssText({inline:"img",classes:[t.value]})})})});var b=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:r},g];e.settings.image_description!==!1&&b.push({name:"alt",type:"textbox",label:"Image description"}),y&&b.push({type:"container",label:"Dimensions",layout:"flex",direction:"row",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:3,onchange:a,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:3,onchange:a,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}),b.push(h),e.settings.image_advtab?(f&&(m.hspace=o(f.style.marginLeft||f.style.marginRight),m.vspace=o(f.style.marginTop||f.style.marginBottom),m.border=o(f.style.borderWidth),m.style=e.dom.serializeStyle(e.dom.parseStyle(e.dom.getAttrib(f,"style")))),c=e.windowManager.open({title:"Insert/edit image",data:m,bodyType:"tabpanel",body:[{title:"General",type:"form",items:b},{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:s},items:[{label:"Vertical space",name:"vspace"},{label:"Horizontal space",name:"hspace"},{label:"Border",name:"border"}]}]}],onSubmit:l})):c=e.windowManager.open({title:"Insert/edit image",data:m,body:b,onSubmit:l})}e.addButton("image",{icon:"image",tooltip:"Insert/edit image",onclick:n(a),stateSelector:"img:not([data-mce-object],[data-mce-placeholder])"}),e.addMenuItem("image",{icon:"image",text:"Insert image",onclick:n(a),context:"insert",prependToContext:!0}),e.addCommand("mceImage",n(a))});