2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
!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<g;++i)h[i]=d(e[i]);var j=f.apply(null,h);if(void 0===j)throw"module ["+b+"] returned undefined";c.instance=j},c=function(b,c,d){if("string"!=typeof b)throw"module id must be a string";if(void 0===c)throw"no dependencies for "+b;if(void 0===d)throw"no definition function for "+b;a[b]={deps:c,defn:d,instance:void 0}},d=function(c){var d=a[c];if(void 0===d)throw"module ["+c+"] was undefined";return void 0===d.instance&&b(c),d.instance},e=function(a,b){for(var c=a.length,e=new Array(c),f=0;f<c;++f)e[f]=d(a[f]);b.apply(null,e)},f={};f.bolt={module:{api:{define:c,require:e,demand:d}}};var g=c,h=function(a,b){g(a,[],function(){return b})};h("5",tinymce.util.Tools.resolve),g("1",["5"],function(a){return a("tinymce.PluginManager")}),h("8",Math),h("9",RegExp),g("7",["5"],function(a){return a("tinymce.util.Tools")}),g("a",[],function(){var a=function(a){return a.settings.image_dimensions!==!1},b=function(a){return a.settings.image_advtab===!0},c=function(a){return a.getParam("image_prepend_url","")},d=function(a){return a.getParam("image_class_list")},e=function(a){return a.settings.image_description!==!1},f=function(a){return a.settings.image_title===!0},g=function(a){return a.settings.image_caption===!0},h=function(a){return a.getParam("image_list",!1)},i=function(a){return a.getParam("images_upload_url",!1)},j=function(a){return a.getParam("images_upload_handler",!1)},k=function(a){return a.getParam("images_upload_url")},l=function(a){return a.getParam("images_upload_handler")},m=function(a){return a.getParam("images_upload_base_path")},n=function(a){return a.getParam("images_upload_credentials")};return{hasDimensions:a,hasAdvTab:b,getPrependUrl:c,getClassList:d,hasDescription:e,hasImageTitle:f,hasImageCaption:g,getImageList:h,hasUploadUrl:i,hasUploadHandler:j,getUploadUrl:k,getUploadHandler:l,getUploadBasePath:m,getUploadCredentials:n}}),h("g",document),g("r",[],function(){var a="undefined"!=typeof window?window:Function("return this;")();return a}),g("q",["r"],function(a){var b=function(b,c){for(var d=void 0!==c?c:a,e=0;e<b.length&&void 0!==d&&null!==d;++e)d=d[b[e]];return d},c=function(a,c){var d=a.split(".");return b(d,c)},d=function(a,b){return void 0!==a[b]&&null!==a[b]||(a[b]={}),a[b]},e=function(b,c){for(var e=void 0!==c?c:a,f=0;f<b.length;++f)e=d(e,b[f]);return e},f=function(a,b){var c=a.split(".");return e(c,b)};return{path:b,resolve:c,forge:e,namespace:f}}),g("n",["q"],function(a){var b=function(b,c){return a.resolve(b,c)},c=function(a,c){var d=b(a,c);if(void 0===d)throw a+" not available on this browser";return d};return{getOrDie:c}}),g("h",["n"],function(a){return function(){var b=a.getOrDie("FileReader");return new b}}),g("i",["5"],function(a){return a("tinymce.util.Promise")}),g("j",["5"],function(a){return a("tinymce.util.XHR")}),g("b",["8","g","h","i","7","j","a"],function(a,b,c,d,e,f,g){var h=function(b,c){return a.max(parseInt(b,10),parseInt(c,10))},i=function(a,c){function d(a,b){e.parentNode&&e.parentNode.removeChild(e),c({width:a,height:b})}var e=b.createElement("img");e.onload=function(){var a=h(e.width,e.clientWidth),b=h(e.height,e.clientHeight);d(a,b)},e.onerror=function(){d()};var f=e.style;f.visibility="hidden",f.position="fixed",f.bottom=f.left=0,f.width=f.height="auto",b.body.appendChild(e),e.src=a},j=function(a,b,c){function d(a,c){return c=c||[],e.each(a,function(a){var e={text:a.text||a.title};a.menu?e.menu=d(a.menu):(e.value=a.value,b(e)),c.push(e)}),c}return d(a,c||[])},k=function(a){return a&&(a=a.replace(/px$/,"")),a},l=function(a){return a.length>0&&/^[0-9]+$/.test(a)&&(a+="px"),a},m=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},n=function(a,b){var c=g.getImageList(a);"string"==typeof c?f.send({url:c,success:function(a){b(JSON.parse(a))}}):"function"==typeof c?c(b):b(c)},o=function(a,b,c){function d(){c.onload=c.onerror=null,a.selection&&(a.selection.select(c),a.nodeChanged())}c.onload=function(){b.width||b.height||!g.hasDimensions(a)||a.dom.setAttribs(c,{width:c.clientWidth,height:c.clientHeight}),d()},c.onerror=d},p=function(a){return new d(function(b,d){var e=new c;e.onload=function(){b(e.result)},e.onerror=function(){d(c.error.message)},e.readAsDataURL(a)})};return{getImageSize:i,buildListItems:j,removePixelSuffix:k,addPixelSuffix:l,mergeMargins:m,createImageList:n,waitLoadImage:o,blobToDataUri:p}}),g("c",["a","b"],function(a,b){var c=function(c){return function(d){var e=c.dom,f=d.control.rootControl;if(a.hasAdvTab(c)){var g=f.toJSON(),h=e.parseStyle(g.style);f.find("#vspace").value(""),f.find("#hspace").value(""),h=b.mergeMargins(h),(h["margin-top"]&&h["margin-bottom"]||h["margin-right"]&&h["margin-left"])&&(h["margin-top"]===h["margin-bottom"]?f.find("#vspace").value(b.removePixelSuffix(h["margin-top"])):f.find("#vspace").value(""),h["margin-right"]===h["margin-left"]?f.find("#hspace").value(b.removePixelSuffix(h["margin-right"])):f.find("#hspace").value("")),h["border-width"]&&f.find("#border").value(b.removePixelSuffix(h["border-width"])),f.find("#style").value(e.serializeStyle(e.parseStyle(e.serializeStyle(h))))}}},d=function(a,b){return{title:"Advanced",type:"form",pack:"start",items:[{label:"Style",name:"style",type:"textbox",onchange:c(a)},{type:"form",layout:"grid",packV:"start",columns:2,padding:0,alignH:["left","right"],defaults:{type:"textbox",maxWidth:50,onchange:function(c){b(a,c.control.rootControl)}},items:[{label:"Vertical space",name:"vspace"},{label:"Horizontal space",name:"hspace"},{label:"Border",name:"border"}]}]}};return{makeTab:d}}),g("e",[],function(){var a=function(a,b){a.state.set("oldVal",a.value()),b.state.set("oldVal",b.value())},b=function(a,b){var c=a.find("#width")[0],d=a.find("#height")[0],e=a.find("#constrain")[0];c&&d&&e&&b(c,d,e.checked())},c=function(b,c,d){var e=b.state.get("oldVal"),f=c.state.get("oldVal"),g=b.value(),h=c.value();d&&e&&f&&g&&h&&(g!==e?(h=Math.round(g/e*h),isNaN(h)||c.value(h)):(g=Math.round(h/f*g),isNaN(g)||b.value(g))),a(b,c)},d=function(c){b(c,a)},e=function(a){b(a,c)},f=function(){var a=function(a){e(a.control.rootControl)};return{type:"container",label:"Dimensions",layout:"flex",align:"center",spacing:5,items:[{name:"width",type:"textbox",maxLength:5,size:5,onchange:a,ariaLabel:"Width"},{type:"label",text:"x"},{name:"height",type:"textbox",maxLength:5,size:5,onchange:a,ariaLabel:"Height"},{name:"constrain",type:"checkbox",checked:!0,text:"Constrain proportions"}]}};return{createUi:f,syncSize:d,updateSize:e}}),g("d",["7","a","b","e"],function(a,b,c,d){var e=function(e,f){var g,h,i,j=e.meta||{},k=e.control,l=k.rootControl,m=l.find("#image-list")[0];m&&m.value(f.convertURL(k.value(),"src")),a.each(j,function(a,b){l.find("#"+b).value(a)}),j.width||j.height||(g=f.convertURL(k.value(),"src"),h=b.getPrependUrl(f),i=new RegExp("^(?:[a-z]+:)?//","i"),h&&!i.test(g)&&g.substring(0,h.length)!==h&&(g=h+g),k.value(g),c.getImageSize(f.documentBaseURI.toAbsolute(k.value()),function(a){a.width&&a.height&&b.hasDimensions(f)&&(l.find("#width").value(a.width),l.find("#height").value(a.height),d.updateSize(l))}))},f=function(a){a.meta=a.control.rootControl.toJSON()},g=function(a,g){var h=[{name:"src",type:"filepicker",filetype:"image",label:"Source",autofocus:!0,onchange:function(b){e(b,a)},onbeforecall:f},g];return b.hasDescription(a)&&h.push({name:"alt",type:"textbox",label:"Image description"}),b.hasImageTitle(a)&&h.push({name:"title",type:"textbox",label:"Image Title"}),b.hasDimensions(a)&&h.push(d.createUi()),b.getClassList(a)&&h.push({name:"class",type:"listbox",label:"Class",values:c.buildListItems(b.getClassList(a),function(b){b.value&&(b.textStyle=function(){return a.formatter.getCssText({inline:"img",classes:[b.value]})})})}),b.hasImageCaption(a)&&h.push({name:"caption",type:"checkbox",label:"Caption"}),h},h=function(a,b){return{title:"General",type:"form",items:g(a,b)}};return{makeTab:h,getGeneralItems:g}}),g("k",["n"],function(a){var b=function(){return a.getOrDie("URL")},c=function(a){return b().createObjectURL(a)},d=function(a){b().revokeObjectURL(a)};return{createObjectURL:c,revokeObjectURL:d}}),g("l",["5"],function(a){return a("tinymce.ui.Factory")}),g("o",["n"],function(a){return function(){var b=a.getOrDie("XMLHttpRequest");return new b}}),h("p",window),g("m",["o","g","p","i","7"],function(a,b,c,d,e){var f=function(){},g=function(a,b){return a?a.replace(/\/$/,"")+"/"+b.replace(/^\//,""):b};return function(b){var h=function(d,e,f,h){var i,j;i=new a,i.open("POST",b.url),i.withCredentials=b.credentials,i.upload.onprogress=function(a){h(a.loaded/a.total*100)},i.onerror=function(){f("Image upload failed due to a XHR Transport error. Code: "+i.status)},i.onload=function(){var a;return i.status<200||i.status>=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 missing from the settings."):i(a,b.handler)};return b=e.extend({credentials:!1,handler:h},b),{upload:k}}}),g("f",["k","l","a","b","m"],function(a,b,c,d,e){var f=function(f){return function(g){var h=b.get("Throbber"),i=g.control.rootControl,j=new h(i.getEl()),k=g.control.value(),l=a.createObjectURL(k),m=new e({url:c.getUploadUrl(f),basePath:c.getUploadBasePath(f),credentials:c.getUploadCredentials(f),handler:c.getUploadHandler(f)}),n=function(){j.hide(),a.revokeObjectURL(l)};return j.show(),d.blobToDataUri(k).then(function(a){var b=f.editorUpload.blobCache.create({blob:k,blobUri:l,name:k.name?k.name.replace(/\.[^\.]+$/,""):null,base64:a.split(",")[1]});return m.upload(b).then(function(a){var b=i.find("#src");return b.value(a),i.find("tabpanel")[0].activateTab(0),b.fire("change"),n(),a})})["catch"](function(a){f.windowManager.alert(a),n()})}},g=".jpg,.jpeg,.png,.gif",h=function(a){return{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:f(a)},{text:"OR",type:"label"}]},{text:"Drop an image here",type:"dropzone",accept:g,height:100,onchange:f(a)}]}};return{makeTab:h}}),g("6",["8","9","7","a","b","c","d","e","f"],function(a,b,c,d,e,f,g,h,i){return function(a){function b(b){function j(){var b,d;h.updateSize(l),k(a,l),p=c.extend(p,l.toJSON()),p.alt||(p.alt=""),p.title||(p.title=""),""===p.width&&(p.width=null),""===p.height&&(p.height=null),p.style||(p.style=null),p={src:p.src,alt:p.alt,title:p.title,width:p.width,height:p.height,style:p.style,caption:p.caption,"class":p["class"]},a.undoManager.transact(function(){if(p.src){if(""===p.title&&(p.title=null),m?q.setAttribs(m,p):(p.id="__mcenew",a.focus(),a.selection.setContent(q.createHTML("img",p)),m=q.get("__mcenew"),q.setAttrib(m,"id",null)),a.editorUpload.uploadImagesAuto(),p.caption===!1&&q.is(m.parentNode,"figure.image")&&(b=m.parentNode,q.insertAfter(m,b),q.remove(b)),p.caption!==!0)e.waitLoadImage(a,p,m);else if(!q.is(m.parentNode,"figure.image")){d=m,m=m.cloneNode(!0),b=q.create("figure",{"class":"image"}),b.appendChild(m),b.appendChild(q.create("figcaption",{contentEditable:!0},"Caption")),b.contentEditable=!1;var c=q.getParent(d,function(b){return a.schema.getTextBlockElements()[b.nodeName]});c?q.split(c,d,b):q.replace(b,d),a.selection.select(b)}}else if(m){var f=q.is(m.parentNode,"figure.image")?m.parentNode:m;q.remove(f),a.focus(),a.nodeChanged(),q.isEmpty(a.getBody())&&(a.setContent(""),a.selection.setCursorLocation())}})}var l,m,n,o,p={},q=a.dom;if(m=a.selection.getNode(),n=q.getParent(m,"figure.image"),n&&(m=q.select("img",n)[0]),m&&("IMG"!==m.nodeName||m.getAttribute("data-mce-object")||m.getAttribute("data-mce-placeholder"))&&(m=null),m&&(p={src:q.getAttrib(m,"src"),alt:q.getAttrib(m,"alt"),title:q.getAttrib(m,"title"),"class":q.getAttrib(m,"class"),width:q.getAttrib(m,"width"),height:q.getAttrib(m,"height"),caption:!!n}),b&&(o={type:"listbox",label:"Image list",name:"image-list",values:e.buildListItems(b,function(b){b.value=a.convertURL(b.value||b.url,"src")},[{text:"None",value:""}]),value:p.src&&a.convertURL(p.src,"src"),onselect:function(a){var b=l.find("#alt");(!b.value()||a.lastControl&&b.value()===a.lastControl.text())&&b.value(a.control.text()),l.find("#src").value(a.control.value()).fire("change")},onPostRender:function(){o=this}}),d.hasAdvTab(a)||d.hasUploadUrl(a)||d.hasUploadHandler(a)){var r=[g.makeTab(a,o)];d.hasAdvTab(a)&&(m&&(m.style.marginLeft&&m.style.marginRight&&m.style.marginLeft===m.style.marginRight&&(p.hspace=e.removePixelSuffix(m.style.marginLeft)),m.style.marginTop&&m.style.marginBottom&&m.style.marginTop===m.style.marginBottom&&(p.vspace=e.removePixelSuffix(m.style.marginTop)),m.style.borderWidth&&(p.border=e.removePixelSuffix(m.style.borderWidth)),p.style=a.dom.serializeStyle(a.dom.parseStyle(a.dom.getAttrib(m,"style")))),r.push(f.makeTab(a,k))),(d.hasUploadUrl(a)||d.hasUploadHandler(a))&&r.push(i.makeTab(a)),l=a.windowManager.open({title:"Insert/edit image",data:p,bodyType:"tabpanel",body:r,onSubmit:j})}else l=a.windowManager.open({title:"Insert/edit image",data:p,body:g.getGeneralItems(a,o),onSubmit:j});h.syncSize(l)}function j(){e.createImageList(a,b)}var k=function(a,b){if(d.hasAdvTab(a)){var c=a.dom,f=b.toJSON(),g=c.parseStyle(f.style);g=e.mergeMargins(g),f.vspace&&(g["margin-top"]=g["margin-bottom"]=e.addPixelSuffix(f.vspace)),f.hspace&&(g["margin-left"]=g["margin-right"]=e.addPixelSuffix(f.hspace)),f.border&&(g["border-width"]=e.addPixelSuffix(f.border)),b.find("#style").value(c.serializeStyle(c.parseStyle(c.serializeStyle(g))))}};return{open:j}}}),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))}},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")()}();
|