2014-03-03 20:57:15 -05:00
|
|
|
tinymce.PluginManager.add("image",function(a){function b(a,b){function c(a,c){d.parentNode&&d.parentNode.removeChild(d),b({width:a,height:c})}var d=document.createElement("img");d.onload=function(){c(d.clientWidth,d.clientHeight)},d.onerror=function(){c()};var e=d.style;e.visibility="hidden",e.position="fixed",e.bottom=e.left=0,e.width=e.height="auto",document.body.appendChild(d),d.src=a}function c(b){return function(){var c=a.settings.image_list;"string"==typeof c?tinymce.util.XHR.send({url:c,success:function(a){b(tinymce.util.JSON.parse(a))}}):b(c)}}function d(c){function d(b,c,d){var e,f=[];return tinymce.each(a.settings[b]||d,function(a){var b={text:a.text||a.title,value:a.value};f.push(b),(p[c]===a.value||!e&&a.selected)&&(e=b)}),e&&!p[c]&&(p[c]=e.value,e.selected=!0),f}function e(){var b=[{text:"None",value:""}];return tinymce.each(c,function(c){b.push({text:c.text||c.title,value:a.convertURL(c.value||c.url,"src"),menu:c.menu})}),b}function f(){var a,b,c,d;a=k.find("#width")[0],b=k.find("#height")[0],c=a.value(),d=b.value(),k.find("#constrain")[0].checked()&&l&&m&&c&&d&&(l!=c?(d=Math.round(c/l*d),b.value(d)):(c=Math.round(d/m*c),a.value(c))),l=c,m=d}function g(){function b(b){function c(){b.onload=b.onerror=null,a.selection.select(b),a.nodeChanged()}b.onload=function(){p.width||p.height||(q.setAttribs(b,{width:b.clientWidth,height:b.clientHeight}),a.fire("wpNewImageRefresh",{node:b})),c()},b.onerror=c}j(),f(),p=tinymce.extend(p,k.toJSON());var c=p.caption;""===p.width&&(p.width=null),""===p.height&&(p.height=null),""===p.style&&(p.style=null),p={src:p.src,alt:p.alt,width:p.width,height:p.height,style:p.style,"class":p["class"]},p["class"]||delete p["class"],a.undoManager.transact(function(){var d={node:r,data:p,caption:c};return a.fire("wpImageFormSubmit",{imgData:d}),d.cancel?void b(d.node):p.src?(r?q.setAttribs(r,p):(p.id="__mcenew",a.focus(),a.selection.setContent(q.createHTML("img",p)),r=q.get("__mcenew"),q.setAttrib(r,"id",null)),void b(r)):void(r&&(q.remove(r),a.focus(),a.nodeChanged()))})}function h(a){return a&&(a=a.replace(/px$/,"")),a}function i(){n&&n.value(a.convertURL(this.value(),"src")),b(this.value(),function(a){a.width&&a.height&&(l=a.width,m=a.height,k.find("#width").value(l),k.find("#height").value(m))})}function j(){function b(a){return a.length>0&&/^[0-9]+$/.test(a)&&(a+="px"),a}if(a.settings.image_advtab){var c=k.toJSON(),d=q.parseStyle(c.style);delete d.margin,d["margin-top"]=d["margin-bottom"]=b(c.vspace),d["margin-left"]=d["margin-right"]=b(c.hspace),d["border-width"]=b(c.border),k.find("#style").value(q.serializeStyle(q.parseStyle(q.serializeStyle(d))))}}var k,l,m,n,o,p={},q=a.dom,r=a.selection.getNode();l=q.getAttrib(r,"width"),m=q.getAttrib(r,"height"),"IMG"!=r.nodeName||r.getAttribute("data-mce-object")||r.getAttribute("data-mce-placeholder")?r=null:(p={src:q.getAttrib(r,"src"),alt:q.getAttrib(r,"alt"),"class":q.getAttrib(r,"class"),width:l,height:m},a.fire("wpLoadImageData",{imgData:{data:p,node:r}})),c&&(n={type:"listbox",label:"Image list",values:e(),value:p.src&&a.convertURL(p.src,"src"),onselect:function(a){var b=k.find("#alt");(!b.value()||a.lastControl&&b.value()==a.lastControl.text())&&b.value(a.control.text()),k.find("#src").value(a.control.value())},onPostRender:function(){n=this}}),a.settings.image_class_list&&(o={name:"class",type:"listbox",label:"Class",values:d("image_class_list","class")});var s=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:i},n,{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:5,size:3,onchange:f,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:3,onchange:f,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]},o];a.fire("wpLoadImageForm",{data:s}),a.settings.image_advtab?(r&&(p.hspace=h(r.style.marginLeft||r.style.marginRight),p.vspace=h(r.style.marginTop||r.style.marginBottom),p.border=h(r.st
|