!function(){var a={},b=function(b){for(var c=a[b],e=c.deps,f=c.defn,g=e.length,h=new Array(g),i=0;i=300?void f("HTTP Error: "+i.status):(a=JSON.parse(i.responseText),a&&"string"==typeof a.location?void e(g(b.basePath,a.location)):void f("Invalid JSON: "+i.responseText))},j=new c.FormData,j.append("file",d.blob(),d.filename()),i.send(j)},i=function(a,b){return new d(function(c,d){try{b(a,c,d,f)}catch(a){d(a.message)}})},j=function(a){return a===h},k=function(a){return!b.url&&j(b.handler)?d.reject("Upload url missng from the settings."):i(a,b.handler)};return b=e.extend({credentials:!1,handler:h},b),{upload:k}}}),g("g",["7","9","j"],function(a,b,c){var d=function(a,c){return b.max(parseInt(a,10),parseInt(c,10))},e=function(a,b){function e(a,c){f.parentNode&&f.parentNode.removeChild(f),b({width:a,height:c})}var f=c.createElement("img");f.onload=function(){var a=d(f.width,f.clientWidth),b=d(f.height,f.clientHeight);e(a,b)},f.onerror=function(){e()};var g=f.style;g.visibility="hidden",g.position="fixed",g.bottom=g.left=0,g.width=g.height="auto",c.body.appendChild(f),f.src=a},f=function(b,c,d){function e(b,d){return d=d||[],a.each(b,function(a){var b={text:a.text||a.title};a.menu?b.menu=e(a.menu):(b.value=a.value,c(b)),d.push(b)}),d}return e(b,d||[])},g=function(a){return a&&(a=a.replace(/px$/,"")),a},h=function(a){return a.length>0&&/^[0-9]+$/.test(a)&&(a+="px"),a},i=function(a){if(a.margin){var b=a.margin.split(" ");switch(b.length){case 1:a["margin-top"]=a["margin-top"]||b[0],a["margin-right"]=a["margin-right"]||b[0],a["margin-bottom"]=a["margin-bottom"]||b[0],a["margin-left"]=a["margin-left"]||b[0];break;case 2:a["margin-top"]=a["margin-top"]||b[0],a["margin-right"]=a["margin-right"]||b[1],a["margin-bottom"]=a["margin-bottom"]||b[0],a["margin-left"]=a["margin-left"]||b[1];break;case 3:a["margin-top"]=a["margin-top"]||b[0],a["margin-right"]=a["margin-right"]||b[1],a["margin-bottom"]=a["margin-bottom"]||b[2],a["margin-left"]=a["margin-left"]||b[1];break;case 4:a["margin-top"]=a["margin-top"]||b[0],a["margin-right"]=a["margin-right"]||b[1],a["margin-bottom"]=a["margin-bottom"]||b[2],a["margin-left"]=a["margin-left"]||b[3]}delete a.margin}return a};return{getImageSize:e,buildListItems:f,removePixelSuffix:g,addPixelSuffix:h,mergeMargins:i}}),g("6",["8","9","a","b","c","7","d","e","f","g"],function(a,b,c,d,e,f,g,h,i,j){return function(k){function l(a){var b=h.getImageList(k);"string"==typeof b?g.send({url:b,success:function(b){a(e.parse(b))}}):"function"==typeof b?b(a):a(b)}function m(e){function g(){var b=d.get("Throbber"),c=new b(t.getEl()),e=this.value(),f=new i({url:C.images_upload_url,basePath:C.images_upload_base_path,credentials:C.images_upload_credentials,handler:C.images_upload_handler}),g=k.editorUpload.blobCache.create({blob:e,name:e.name?e.name.replace(/\.[^\.]+$/,""):null,base64:"data:image/fake;base64,="}),h=function(){c.hide(),a.revokeObjectURL(g.blobUri())};return c.show(),f.upload(g).then(function(a){var b=t.find("#src");return b.value(a),t.find("tabpanel")[0].activateTab(0),b.fire("change"),h(),a},function(a){k.windowManager.alert(a),h()})}function l(a){return k.schema.getTextBlockElements()[a.nodeName]}function m(){var a,c,d,e;a=t.find("#width")[0],c=t.find("#height")[0],a&&c&&(d=parseInt(a.value(),10),e=parseInt(c.value(),10),t.find("#constrain")[0].checked()&&w&&x&&d&&e&&(w!==d?(e=b.round(d/w*e),isNaN(e)||c.value(e)):(d=b.round(e/x*d),isNaN(d)||a.value(d))),w=d,x=e)}function n(){if(h.hasAdvTab(k)){var a=t.toJSON(),b=B.parseStyle(a.style);b=j.mergeMargins(b),a.vspace&&(b["margin-top"]=b["margin-bottom"]=j.addPixelSuffix(a.vspace)),a.hspace&&(b["margin-left"]=b["margin-right"]=j.addPixelSuffix(a.hspace)),a.border&&(b["border-width"]=j.addPixelSuffix(a.border)),t.find("#style").value(B.serializeStyle(B.parseStyle(B.serializeStyle(b))))}}function o(){if(h.hasAdvTab(k)){var a=t.toJSON(),b=B.parseStyle(a.style);t.find("#vspace").value(""),t.find("#hspace").value(""),b=j.mergeMargins(b),(b["margin-top"]&&b["margin-bottom"]||b["margin-right"]&&b["margin-left"])&&(b["margin-top"]===b["margin-bottom"]?t.find("#vspace").value(j.removePixelSuffix(b["margin-top"])):t.find("#vspace").value(""),b["margin-right"]===b["margin-left"]?t.find("#hspace").value(j.removePixelSuffix(b["margin-right"])):t.find("#hspace").value("")),b["border-width"]&&t.find("#border").value(j.removePixelSuffix(b["border-width"])),t.find("#style").value(B.serializeStyle(B.parseStyle(B.serializeStyle(b))))}}function p(a){function b(){a.onload=a.onerror=null,k.selection&&(k.selection.select(a),k.nodeChanged())}a.onload=function(){A.width||A.height||!D||B.setAttribs(a,{width:a.clientWidth,height:a.clientHeight}),b()},a.onerror=b}function q(){var a,b;n(),m(),A=f.extend(A,t.toJSON()),A.alt||(A.alt=""),A.title||(A.title=""),""===A.width&&(A.width=null),""===A.height&&(A.height=null),A.style||(A.style=null),A={src:A.src,alt:A.alt,title:A.title,width:A.width,height:A.height,style:A.style,caption:A.caption,"class":A["class"]},k.undoManager.transact(function(){if(A.src){if(""===A.title&&(A.title=null),u?B.setAttribs(u,A):(A.id="__mcenew",k.focus(),k.selection.setContent(B.createHTML("img",A)),u=B.get("__mcenew"),B.setAttrib(u,"id",null)),k.editorUpload.uploadImagesAuto(),A.caption===!1&&B.is(u.parentNode,"figure.image")&&(a=u.parentNode,B.setAttrib(u,"contenteditable",null),B.insertAfter(u,a),B.remove(a),k.selection.select(u),k.nodeChanged()),A.caption!==!0)p(u);else if(!B.is(u.parentNode,"figure.image")){b=u,u=u.cloneNode(!0),u.contentEditable=!0,a=B.create("figure",{"class":"image"}),a.appendChild(u),a.appendChild(B.create("figcaption",{contentEditable:!0},"Caption")),a.contentEditable=!1;var c=B.getParent(b,l);c?B.split(c,b,a):B.replace(a,b),k.selection.select(a)}}else if(u){var d=B.is(u.parentNode,"figure.image")?u.parentNode:u;B.remove(d),k.focus(),k.nodeChanged(),B.isEmpty(k.getBody())&&(k.setContent(""),k.selection.setCursorLocation())}})}function r(a){var b,d,e,g=a.meta||{};y&&y.value(k.convertURL(this.value(),"src")),f.each(g,function(a,b){t.find("#"+b).value(a)}),g.width||g.height||(b=k.convertURL(this.value(),"src"),d=h.getPrependUrl(k),e=new c("^(?:[a-z]+:)?//","i"),d&&!e.test(b)&&b.substring(0,d.length)!==d&&(b=d+b),this.value(b),j.getImageSize(k.documentBaseURI.toAbsolute(this.value()),function(a){a.width&&a.height&&D&&(w=a.width,x=a.height,t.find("#width").value(w),t.find("#height").value(x))}))}function s(a){a.meta=t.toJSON()}var t,u,v,w,x,y,z,A={},B=k.dom,C=k.settings,D=h.hasDimensions(k);u=k.selection.getNode(),v=B.getParent(u,"figure.image"),v&&(u=B.select("img",v)[0]),u&&("IMG"!==u.nodeName||u.getAttribute("data-mce-object")||u.getAttribute("data-mce-placeholder"))&&(u=null),u&&(w=B.getAttrib(u,"width"),x=B.getAttrib(u,"height"),A={src:B.getAttrib(u,"src"),alt:B.getAttrib(u,"alt"),title:B.getAttrib(u,"title"),"class":B.getAttrib(u,"class"),width:w,height:x,caption:!!v}),e&&(y={type:"listbox",label:"Image list",values:j.buildListItems(e,function(a){a.value=k.convertURL(a.value||a.url,"src")},[{text:"None",value:""}]),value:A.src&&k.convertURL(A.src,"src"),onselect:function(a){var b=t.find("#alt");(!b.value()||a.lastControl&&b.value()===a.lastControl.text())&&b.value(a.control.text()),t.find("#src").value(a.control.value()).fire("change")},onPostRender:function(){y=this}}),h.getClassList(k)&&(z={name:"class",type:"listbox",label:"Class",values:j.buildListItems(h.getClassList(k),function(a){a.value&&(a.textStyle=function(){return k.formatter.getCssText({inline:"img",classes:[a.value]})})})});var E=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:r,onbeforecall:s},y];if(h.hasDescription(k)&&E.push({name:"alt",type:"textbox",label:"Image description"}),h.hasImageTitle(k)&&E.push({name:"title",type:"textbox",label:"Image Title"}),D&&E.push({type:"container",label:"Dimensions",layout:"flex",direction:"row",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:3,onchange:m,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:3,onchange:m,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}),E.push(z),h.hasImageCaption(k)&&E.push({name:"caption",type:"checkbox",label:"Caption"}),h.hasAdvTab(k)||k.settings.images_upload_url){var F=[{title:"General",type:"form",items:E}];if(h.hasAdvTab(k)&&(u&&(u.style.marginLeft&&u.style.marginRight&&u.style.marginLeft===u.style.marginRight&&(A.hspace=j.removePixelSuffix(u.style.marginLeft)),u.style.marginTop&&u.style.marginBottom&&u.style.marginTop===u.style.marginBottom&&(A.vspace=j.removePixelSuffix(u.style.marginTop)),u.style.borderWidth&&(A.border=j.removePixelSuffix(u.style.borderWidth)),A.style=k.dom.serializeStyle(k.dom.parseStyle(k.dom.getAttrib(u,"style")))),F.push({title:"Advanced",type:"form",pack:"start",items:[{label:"Style",name:"style",type:"textbox",onchange:o},{type:"form",layout:"grid",packV:"start",columns:2,padding:0,alignH:["left","right"],defaults:{type:"textbox",maxWidth:50,onchange:n},items:[{label:"Vertical space",name:"vspace"},{label:"Horizontal space",name:"hspace"},{label:"Border",name:"border"}]}]})),k.settings.images_upload_url){var G=".jpg,.jpeg,.png,.gif",H={title:"Upload",type:"form",layout:"flex",direction:"column",align:"stretch",padding:"20 20 20 20",items:[{type:"container",layout:"flex",direction:"column",align:"center",spacing:10,items:[{text:"Browse for an image",type:"browsebutton",accept:G,onchange:g},{text:"OR",type:"label"}]},{text:"Drop an image here",type:"dropzone",accept:G,height:100,onchange:g}]};F.push(H)}t=k.windowManager.open({title:"Insert/edit image",data:A,bodyType:"tabpanel",body:F,onSubmit:q})}else t=k.windowManager.open({title:"Insert/edit image",data:A,body:E,onSubmit:q})}function n(){l(m)}return{open:n}}}),g("2",["6"],function(a){var b=function(b){b.addCommand("mceImage",a(b).open)};return{register:b}}),g("3",["7"],function(a){var b=function(a){var b=a.attr("class");return b&&/\bimage\b/.test(b)},c=function(c){return function(d){for(var e,f=d.length,g=function(a){a.attr("contenteditable",c?"true":null)};f--;)e=d[f],b(e)&&(e.attr("contenteditable",c?"false":null),a.each(e.getAll("figcaption"),g),a.each(e.getAll("img"),g))}},d=function(a){a.on("preInit",function(){a.parser.addNodeFilter("figure",c(!0)),a.serializer.addNodeFilter("figure",c(!1))})};return{setup:d}}),g("4",["6"],function(a){var b=function(b){b.addButton("image",{icon:"image",tooltip:"Insert/edit image",onclick:a(b).open,stateSelector:"img:not([data-mce-object],[data-mce-placeholder]),figure.image"}),b.addMenuItem("image",{icon:"image",text:"Image",onclick:a(b).open,context:"insert",prependToContext:!0})};return{register:b}}),g("0",["1","2","3","4"],function(a,b,c,d){return a.add("image",function(a){c.setup(a),d.register(a),b.register(a)}),function(){}}),d("0")()}();