11 lines
22 KiB
JavaScript
11 lines
22 KiB
JavaScript
/**
|
|
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
|
* Licensed under the LGPL or a commercial license.
|
|
* For LGPL see License.txt in the project root for license information.
|
|
* For commercial licenses see https://www.tiny.cloud/
|
|
*
|
|
* Version: 5.0.5 (2019-05-09)
|
|
*/
|
|
|
|
!function(l){"use strict";var e,n,t,r,o=function(e){var n=e,t=function(){return n};return{get:t,set:function(e){n=e},clone:function(){return o(t())}}},i=tinymce.util.Tools.resolve("tinymce.PluginManager"),a=tinymce.util.Tools.resolve("tinymce.util.Tools"),v=function(e){return function(){return e}},u=v(!1),c=v(!0),s=u,f=c,d=function(){return m},m=(r={fold:function(e,n){return e()},is:s,isSome:s,isNone:f,getOr:t=function(e){return e},getOrThunk:n=function(e){return e()},getOrDie:function(e){throw new Error(e||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:t,orThunk:n,map:d,ap:d,each:function(){},bind:d,flatten:d,exists:s,forall:f,filter:d,equals:e=function(e){return e.isNone()},equals_:e,toArray:function(){return[]},toString:v("none()")},Object.freeze&&Object.freeze(r),r),h=function(t){var e=function(){return t},n=function(){return o},r=function(e){return e(t)},o={fold:function(e,n){return n(t)},is:function(e){return t===e},isSome:f,isNone:s,getOr:e,getOrThunk:e,getOrDie:e,getOrNull:e,getOrUndefined:e,or:n,orThunk:n,map:function(e){return h(e(t))},ap:function(e){return e.fold(d,function(e){return h(e(t))})},each:function(e){e(t)},bind:r,flatten:e,exists:r,forall:r,filter:function(e){return e(t)?o:m},equals:function(e){return e.is(t)},equals_:function(e,n){return e.fold(s,function(e){return n(t,e)})},toArray:function(){return[t]},toString:function(){return"some("+t+")"}};return o},p={some:h,none:d,from:function(e){return null===e||e===undefined?m:h(e)}},g="undefined"!=typeof l.window?l.window:Function("return this;")(),y=function(e,n){return function(e,n){for(var t=n!==undefined&&null!==n?n:g,r=0;r<e.length&&t!==undefined&&null!==t;++r)t=t[e[r]];return t}(e.split("."),n)},w={getOrDie:function(e,n){var t=y(e,n);if(t===undefined||null===t)throw e+" not available on this browser";return t}};function b(){return new(w.getOrDie("FileReader"))}var O={atob:function(e){return w.getOrDie("atob")(e)},requestAnimationFrame:function(e){w.getOrDie("requestAnimationFrame")(e)}};function E(e,n){return N(l.document.createElement("canvas"),e,n)}function I(e){var n=E(e.width,e.height);return T(n).drawImage(e,0,0),n}function T(e){return e.getContext("2d")}function N(e,n,t){return e.width=n,e.height=t,e}var S=window.Promise?window.Promise:function(){var i=function(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],f(e,r(o,this),r(a,this))},e=i.immediateFn||"function"==typeof window.setImmediate&&window.setImmediate||function(e){l.setTimeout(e,1)};function r(e,n){return function(){return e.apply(n,arguments)}}var t=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};function u(r){var o=this;null!==this._state?e(function(){var e=o._state?r.onFulfilled:r.onRejected;if(null!==e){var n;try{n=e(o._value)}catch(t){return void r.reject(t)}r.resolve(n)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}function o(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void f(r(n,e),r(o,this),r(a,this))}this._state=!0,this._value=e,c.call(this)}catch(t){a.call(this,t)}}function a(e){this._state=!1,this._value=e,c.call(this)}function c(){for(var e=0,n=this._deferreds;e<n.length;e++){var t=n[e];u.call(this,t)}this._deferreds=[]}function s(e,n,t,r){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.resolve=t,this.reject=r}function f(e,n,t){var r=!1;try{e(function(e){r||(r=!0,n(e))},function(e){r||(r=!0,t(e))})}catch(o){if(r)return;r=!0,t(o)}}return i.prototype["catch"]=function(e){return this.then(null,e)},i.prototype.then=function(t,r){var o=this;return new i(function(e,n){u.call(o,new s(t,r,e,n))})},i.all=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];var c=Array.prototype.slice.call(1===e.length&&t(e[0])?e[0]:e);return new i(function(o,i){if(0===c.length)return o([]);var u=c.length;function a(n,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var t=e.then;if("function"==typeof t)return void t.call(e,function(e){a(n,e)},i)}c[n]=e,0==--u&&o(c)}catch(r){i(r)}}for(var e=0;e<c.length;e++)a(e,c[e])})},i.resolve=function(n){return n&&"object"==typeof n&&n.constructor===i?n:new i(function(e){e(n)})},i.reject=function(t){return new i(function(e,n){n(t)})},i.race=function(o){return new i(function(e,n){for(var t=0,r=o;t<r.length;t++)r[t].then(e,n)})},i}();function x(e){var n=e.src;return 0===n.indexOf("data:")?A(n):function t(r){return new S(function(e,t){var n=new l.XMLHttpRequest;n.open("GET",r,!0),n.responseType="blob",n.onload=function(){200===this.status&&e(this.response)},n.onerror=function(){var e,n=this;t(0===this.status?((e=new Error("No access to download image")).code=18,e.name="SecurityError",e):new Error("Error "+n.status+" downloading image"))},n.send()})}(n)}function _(a){return new S(function(e,n){var t=l.URL.createObjectURL(a),r=new l.Image,o=function(){r.removeEventListener("load",i),r.removeEventListener("error",u)};function i(){o(),e(r)}function u(){o(),n("Unable to load data of type "+a.type+": "+t)}r.addEventListener("load",i),r.addEventListener("error",u),r.src=t,r.complete&&i()})}function R(e){var n=e.split(","),t=/data:([^;]+)/.exec(n[0]);if(!t)return p.none();for(var r,o=t[1],i=n[1],u=O.atob(i),a=u.length,c=Math.ceil(a/1024),s=new Array(c),f=0;f<c;++f){for(var l=1024*f,d=Math.min(l+1024,a),m=new Array(d-l),h=l,g=0;h<d;++g,++h)m[g]=u[h].charCodeAt(0);s[f]=(r=m,new(w.getOrDie("Uint8Array"))(r))}return p.some(function v(e,n){return new(w.getOrDie("Blob"))(e,n)}(s,{type:o}))}function A(t){return new S(function(e,n){R(t).fold(function(){n("uri is not base64: "+t)},e)})}function D(e,r,o){return r=r||"image/png",l.HTMLCanvasElement.prototype.toBlob?new S(function(n,t){e.toBlob(function(e){e?n(e):t()},r,o)}):A(e.toDataURL(r,o))}function C(e){return _(e).then(function(e){!function t(e){l.URL.revokeObjectURL(e.src)}(e);var n=E(function r(e){return e.naturalWidth||e.width}(e),function o(e){return e.naturalHeight||e.height}(e));return T(n).drawImage(e,0,0),n})}function U(e,n,t){var r=n.type;function o(n,t){return e.then(function(e){return function r(e,n,t){return n=n||"image/png",e.toDataURL(n,t)}(e,n,t)})}return{getType:v(r),toBlob:function i(){return S.resolve(n)},toDataURL:function u(){return t},toBase64:function a(){return t.split(",")[1]},toAdjustedBlob:function c(n,t){return e.then(function(e){return D(e,n,t)})},toAdjustedDataURL:o,toAdjustedBase64:function s(e,n){return o(e,n).then(function(e){return e.split(",")[1]})},toCanvas:function f(){return e.then(I)}}}function j(n){return function e(t){return new S(function(e){var n=b();n.onloadend=function(){e(n.result)},n.readAsDataURL(t)})}(n).then(function(e){return U(C(n),n,e)})}function L(n,e){return D(n,e).then(function(e){return U(S.resolve(n),e,n.toDataURL())})}function k(n,t){return n.toCanvas().then(function(e){return function a(e,n,t){var r=E(e.width,e.height),o=T(r),i=0,u=0;return 90!==(t=t<0?360+t:t)&&270!==t||N(r,r.height,r.width),90!==t&&180!==t||(i=r.width),270!==t&&180!==t||(u=r.height),o.translate(i,u),o.rotate(t*Math.PI/180),o.drawImage(e,0,0),L(r,n)}(e,n.getType(),t)})}function P(n,t){return n.toCanvas().then(function(e){return function i(e,n,t){var r=E(e.width,e.height),o=T(r);return"v"===t?(o.scale(1,-1),o.drawImage(e,0,-r.height)):(o.scale(-1,1),o.drawImage(e,-r.width,0)),L(r,n)}(e,n.getType(),t)})}(function pn(e){return x(e).then(function(e){return j(e)})});var M,F=function(e){return j(e)},B=function(){return w.getOrDie("URL")},z=function(e){return B().createObjectURL(e)},H=function(e){B().revokeObjectURL(e)},q=tinymce.util.Tools.resolve("tinymce.util.Delay"),$=tinymce.util.Tools.resolve("tinymce.util.Promise"),X=tinymce.util.Tools.resolve("tinymce.util.URI"),W={getImageSize:function yn(e){var n,t;function r(e){return/^[0-9\.]+px$/.test(e)}return n=e.style.width,t=e.style.height,n||t?r(n)&&r(t)?{w:parseInt(n,10),h:parseInt(t,10)}:null:(n=e.width,t=e.height,n&&t?{w:parseInt(n,10),h:parseInt(t,10)}:null)},setImageSize:function wn(e,n){var t,r;n&&(t=e.style.width,r=e.style.height,(t||r)&&(e.style.width=n.w+"px",e.style.height=n.h+"px",e.removeAttribute("data-mce-style")),t=e.width,r=e.height,(t||r)&&(e.setAttribute("width",n.w),e.setAttribute("height",n.h)))},getNaturalImageSize:function bn(e){return{w:e.naturalWidth,h:e.naturalHeight}}},G=(M="function",function(e){return function(e){if(null===e)return"null";var n=typeof e;return"object"===n&&Array.prototype.isPrototypeOf(e)?"array":"object"===n&&String.prototype.isPrototypeOf(e)?"string":n}(e)===M}),V=function(e,n){for(var t=0,r=e.length;t<r;t++){var o=e[t];if(n(o,t,e))return p.some(o)}return p.none()};Array.prototype.slice;G(Array.from)&&Array.from;var Y,J,K,Q=function(e){return null!==e&&e!==undefined},Z=function(e,n){var t;return t=n.reduce(function(e,n){return Q(e)?e[n]:undefined},e),Q(t)?t:null},ee=function(n){return new $(function(t){var e=b();e.onload=function(e){var n=e.target;t(n.result)},e.readAsText(n)})},ne=function(r,o,i){return new $(function(e){var t;(t=function n(){return new(w.getOrDie("XMLHttpRequest"))}()).onreadystatechange=function(){4===t.readyState&&e({status:t.status,blob:this.response})},t.open("GET",r,!0),t.withCredentials=i,a.each(o,function(e,n){t.setRequestHeader(n,e)}),t.responseType="blob",t.send()})},te=function(e){var n;try{n=JSON.parse(e)}catch(t){}return n},re=[{code:404,message:"Could not find Image Proxy"},{code:403,message:"Rejected request"},{code:0,message:"Incorrect Image Proxy URL"}],oe=[{type:"key_missing",message:"The request did not include an api key."},{type:"key_not_found",message:"The provided api key could not be found."},{type:"domain_not_trusted",message:"The api key is not valid for the request origins."}],ie=function(n){return"ImageProxy HTTP error: "+V(re,function(e){return n===e.code}).fold(v("Unknown ImageProxy error"),function(e){return e.message})},ue=function(e){var n=ie(e);return $.reject(n)},ae=function(n){return V(oe,function(e){return e.type===n}).fold(v("Unknown service error"),function(e){return e.message})},ce=function(e,n){return ee(n).then(function(e){var n,t,r=(n=te(e),"ImageProxy Service error: "+((t=Z(n,["error","type"]))?ae(t):"Invalid JSON in service error message"));return $.reject(r)})},se=function(e,n){return 400===(t=e)||403===t||500===t?ce(0,n):ue(e);var t},fe=ue,le=function(e,n){var t,r,o,i={"Content-Type":"application/json;charset=UTF-8","tiny-api-key":n};return ne((t=e,r=n,o=-1===t.indexOf("?")?"?":"&",/[?&]apiKey=/.test(t)||!r?t:t+o+"apiKey="+encodeURIComponent(r)),i,!1).then(function(e){return e.status<200||300<=e.status?se(e.status,e.blob):$.resolve(e.blob)})},de=function(e,n,t){return n?le(e,n):function r(e,n){return ne(e,{},n).then(function(e){return e.status<200||300<=e.status?fe(e.status):$.resolve(e.blob)})}(e,t)},me=function(e,n){var t=function(e,n){for(var t=0;t<e.length;t++){var r=e[t];if(r.test(n))return r}return undefined}(e,n);if(!t)return{major:0,minor:0};var r=function(e){return Number(n.replace(t,"$"+e))};return ge(r(1),r(2))},he=function(){return ge(0,0)},ge=function(e,n){return{major:e,minor:n}},ve={nu:ge,detect:function(e,n){var t=String(n).toLowerCase();return 0===e.length?he():me(e,t)},unknown:he},pe="Firefox",ye=function(e,n){return function(){return n===e}},we=function(e){var n=e.current;return{current:n,version:e.version,isEdge:ye("Edge",n),isChrome:ye("Chrome",n),isIE:ye("IE",n),isOpera:ye("Opera",n),isFirefox:ye(pe,n),isSafari:ye("Safari",n)}},be={unknown:function(){return we({current:undefined,version:ve.unknown()})},nu:we,edge:v("Edge"),chrome:v("Chrome"),ie:v("IE"),opera:v("Opera"),firefox:v(pe),safari:v("Safari")},Oe="Windows",Ee="Android",Ie="Solaris",Te="FreeBSD",Ne=function(e,n){return function(){return n===e}},Se=function(e){var n=e.current;return{current:n,version:e.version,isWindows:Ne(Oe,n),isiOS:Ne("iOS",n),isAndroid:Ne(Ee,n),isOSX:Ne("OSX",n),isLinux:Ne("Linux",n),isSolaris:Ne(Ie,n),isFreeBSD:Ne(Te,n)}},xe={unknown:function(){return Se({current:undefined,version:ve.unknown()})},nu:Se,windows:v(Oe),ios:v("iOS"),android:v(Ee),linux:v("Linux"),osx:v("OSX"),solaris:v(Ie),freebsd:v(Te)},_e=function(e,n){var t=String(n).toLowerCase();return V(e,function(e){return e.search(t)})},Re=function(e,t){return _e(e,t).map(function(e){var n=ve.detect(e.versionRegexes,t);return{current:e.name,version:n}})},Ae=function(e,t){return _e(e,t).map(function(e){var n=ve.detect(e.versionRegexes,t);return{current:e.name,version:n}})},De=function(e,n){return-1!==e.indexOf(n)},Ce=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,Ue=function(n){return function(e){return De(e,n)}},je=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(e){return De(e,"edge/")&&De(e,"chrome")&&De(e,"safari")&&De(e,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,Ce],search:function(e){return De(e,"chrome")&&!De(e,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(e){return De(e,"msie")||De(e,"trident")}},{name:"Opera",versionRegexes:[Ce,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:Ue("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:Ue("firefox")},{name:"Safari",versionRegexes:[Ce,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(e){return(De(e,"safari")||De(e,"mobile/"))&&De(e,"applewebkit")}}],Le=[{name:"Windows",search:Ue("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(e){return De(e,"iphone")||De(e,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:Ue("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:Ue("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:Ue("linux"),versionRegexes:[]},{name:"Solaris",search:Ue("sunos"),versionRegexes:[]},{name:"FreeBSD",search:Ue("freebsd"),versionRegexes:[]}],ke={browsers:v(je),oses:v(Le)},Pe=function(e){var n,t,r,o,i,u,a,c,s,f,l,d=ke.browsers(),m=ke.oses(),h=Re(d,e).fold(be.unknown,be.nu),g=Ae(m,e).fold(xe.unknown,xe.nu);return{browser:h,os:g,deviceType:(t=h,r=e,o=(n=g).isiOS()&&!0===/ipad/i.test(r),i=n.isiOS()&&!o,u=n.isAndroid()&&3===n.version.major,a=n.isAndroid()&&4===n.version.major,c=o||u||a&&!0===/mobile/i.test(r),s=n.isiOS()||n.isAndroid(),f=s&&!c,l=t.isSafari()&&n.isiOS()&&!1===/safari/i.test(r),{isiPad:v(o),isiPhone:v(i),isTablet:v(c),isPhone:v(f),isTouch:v(s),isAndroid:n.isAndroid,isiOS:n.isiOS,isWebView:v(l)})}},Me={detect:(Y=function(){var e=l.navigator.userAgent;return Pe(e)},K=!1,function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return K||(K=!0,J=Y.apply(null,e)),J})},Fe=function(e){if(null===e||e===undefined)throw new Error("Node cannot be null or undefined");return{dom:v(e)}},Be={fromHtml:function(e,n){var t=(n||l.document).createElement("div");if(t.innerHTML=e,!t.hasChildNodes()||1<t.childNodes.length)throw l.console.error("HTML does not have a single root node",e),new Error("HTML must have a single root node");return Fe(t.childNodes[0])},fromTag:function(e,n){var t=(n||l.document).createElement(e);return Fe(t)},fromText:function(e,n){var t=(n||l.document).createTextNode(e);return Fe(t)},fromDom:Fe,fromPoint:function(e,n,t){var r=e.dom();return p.from(r.elementFromPoint(n,t)).map(Fe)}},ze=(l.Node.ATTRIBUTE_NODE,l.Node.CDATA_SECTION_NODE,l.Node.COMMENT_NODE,l.Node.DOCUMENT_NODE,l.Node.DOCUMENT_TYPE_NODE,l.Node.DOCUMENT_FRAGMENT_NODE,l.Node.ELEMENT_NODE),He=(l.Node.TEXT_NODE,l.Node.PROCESSING_INSTRUCTION_NODE,l.Node.ENTITY_REFERENCE_NODE,l.Node.ENTITY_NODE,l.Node.NOTATION_NODE,ze),qe=(Me.detect().browser.isIE(),0),$e=function(e){return Me.detect().browser.isIE(),n=Be.fromDom(e),t="img",r=function(e){return function(e,n){var t=e.dom();if(t.nodeType!==He)return!1;if(t.matches!==undefined)return t.matches(n);if(t.msMatchesSelector!==undefined)return t.msMatchesSelector(n);if(t.webkitMatchesSelector!==undefined)return t.webkitMatchesSelector(n);if(t.mozMatchesSelector!==undefined)return t.mozMatchesSelector(n);throw new Error("Browser lacks native selectors")}(e,t)},V(n.dom().childNodes,(o=r,i=Be.fromDom,function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return o(i.apply(null,e))})).map(Be.fromDom);var n,t,r,o,i},Xe=function(e,n){return e.dom.is(n,"figure")},We=function(e,n){e.notificationManager.open({text:n,type:"error"})},Ge=function(e){var n=e.selection.getNode();return Xe(e,n)?$e(n):p.some(Be.fromDom(n))},Ve=function(e,n){var t=n.src;return 0===t.indexOf("data:")||0===t.indexOf("blob:")||new X(t).host===e.documentBaseURI.host},Ye=function(e,n){return-1!==a.inArray(e.getParam("imagetools_cors_hosts",[],"string[]"),new X(n.src).host)},Je=function(e,n){var t,r,o,i,u=n.src;return Ye(e,n)?de(n.src,null,(r=e,o=n,-1!==a.inArray(r.getParam("imagetools_credentials_hosts",[],"string[]"),new X(o.src).host))):Ve(e,n)?x(n):(u=e.getParam("imagetools_proxy"),u+=(-1===u.indexOf("?")?"?":"&")+"url="+encodeURIComponent(n.src),t=(i=e).getParam("api_key",i.getParam("imagetools_api_key","","string"),"string"),de(u,t,!1))},Ke=function(e,n){var t;return(t=e.editorUpload.blobCache.getByUri(n.src))?$.resolve(t.blob()):Je(e,n)},Qe=function(e){q.clearTimeout(e.get())},Ze=function(a,c,s,f,l,d){return c.toBlob().then(function(e){var n,t,r,o,i,u;return r=a.editorUpload.blobCache,n=l.src,a.getParam("images_reuse_filename",!1,"boolean")&&(t=(o=r.getByUri(n))?(n=o.uri(),o.name()):(i=a,(u=n.match(/\/([^\/\?]+)?\.(?:jpeg|jpg|png|gif)(?:\?|$)/i))?i.dom.encode(u[1]):null)),o=r.create({id:"imagetools"+qe++,blob:e,base64:c.toBase64(),uri:n,name:t}),r.add(o),a.undoManager.transact(function(){a.$(l).on("load",function r(){var e,n,t;a.$(l).off("load",r),a.nodeChanged(),s?a.editorUpload.uploadImagesAuto():(Qe(f),e=a,n=f,t=q.setEditorTimeout(e,function(){e.editorUpload.uploadImagesAuto()},e.getParam("images_upload_timeout",3e4,"number")),n.set(t))}),d&&a.$(l).attr({width:d.w,height:d.h}),a.$(l).attr({src:o.blobUri()}).removeAttr("data-mce-src")}),o})},en=function(t,r,e,o){return function(){return Ge(t).fold(function(){We(t,"Could not find selected image")},function(n){return t._scanForImages().then(function(){return Ke(t,n.dom())}).then(F).then(e).then(function(e){return Ze(t,e,!1,r,n.dom(),o)},function(e){We(t,e)})})}},nn=function(n,t,r){return function(){var e=Ge(n).fold(function(){return null},function(e){var n=W.getImageSize(e.dom());return n?{w:n.h,h:n.w}:null});return en(n,t,function(e){return k(e,r)},e)()}},tn=function(e,n,t){return function(){return en(e,n,function(e){return P(e,t)})()}},rn=function(t,e){var n=function(e){return n=e,t.dom.is(n,"img:not([data-mce-object],[data-mce-placeholder])")&&(Ve(t,e)||Ye(t,e)||t.settings.imagetools_proxy);var n};return Xe(t,e)?$e(e).map(function(e){return n(e.dom())?p.some(e.dom()):p.none()}):n(e)?p.some(e):p.none()},on=Qe,un=Ke,an=Ge,cn=function(t,r,o,i,u){return new $(function(e){var n;(n=u,_(n)).then(function(e){var n=W.getNaturalImageSize(e);return i.w===n.w&&i.h===n.h||W.getImageSize(o)&&W.setImageSize(o,n),H(e.src),u}).then(F).then(function(e){return Ze(t,e,!0,r,o)},function(){})})},sn=v("save-state"),fn=v("disable"),ln=v("enable"),dn=function(i,u){return function(){var r=an(i),o=r.map(function(e){return W.getNaturalImageSize(e.dom())});an(i).each(function(n){rn(i,n.dom()).each(function(e){un(i,n.dom()).then(function(e){var n,t={blob:n=e,url:z(n)};i.windowManager.open({title:"Edit Image",size:"large",body:{type:"panel",items:[{type:"imagetools",name:"imagetools",label:"Edit Image",currentState:t}]},buttons:[{type:"cancel",name:"cancel",text:"Cancel"},{type:"submit",name:"save",text:"Save",primary:!0,disabled:!0}],onSubmit:function(e){var t=e.getData().imagetools.blob;r.each(function(n){o.each(function(e){cn(i,u,n.dom(),e,t)})}),e.close()},onCancel:function(){},onAction:function(e,n){switch(n.name){case sn():n.value?e.enable("save"):e.disable("save");break;case fn():e.disable("save"),e.disable("cancel");break;case ln():e.enable("cancel")}}})})})})}},mn=function(t,e){a.each({mceImageRotateLeft:nn(t,e,-90),mceImageRotateRight:nn(t,e,90),mceImageFlipVertical:tn(t,e,"v"),mceImageFlipHorizontal:tn(t,e,"h"),mceEditImage:dn(t,e)},function(e,n){t.addCommand(n,e)})},hn=function(t,r,o){t.on("NodeChange",function(e){var n=o.get();n&&n.src!==e.element.src&&(on(r),t.editorUpload.uploadImagesAuto(),o.set(null)),rn(t,e.element).each(o.set)})},gn=function(r){var n=function(e){return function(){return r.execCommand(e)}};r.ui.registry.addButton("rotateleft",{tooltip:"Rotate counterclockwise",icon:"rotate-left",onAction:n("mceImageRotateLeft")}),r.ui.registry.addButton("rotateright",{tooltip:"Rotate clockwise",icon:"rotate-right",onAction:n("mceImageRotateRight")}),r.ui.registry.addButton("flipv",{tooltip:"Flip vertically",icon:"flip-vertically",onAction:n("mceImageFlipVertical")}),r.ui.registry.addButton("fliph",{tooltip:"Flip horizontally",icon:"flip-horizontally",onAction:n("mceImageFlipHorizontal")}),r.ui.registry.addButton("editimage",{tooltip:"Edit image",icon:"edit-image",onAction:n("mceEditImage"),onSetup:function(t){var e=function(){an(r).each(function(e){var n=rn(r,e.dom()).isNone();t.setDisabled(n)})};return r.on("NodeChange",e),function(){r.off("NodeChange",e)}}}),r.ui.registry.addButton("imageoptions",{tooltip:"Image options",icon:"image-options",onAction:n("mceImage")}),r.ui.registry.addContextMenu("imagetools",{update:function(e){return rn(r,e).fold(function(){return[]},function(e){return[{text:"Edit image",icon:"edit-image",onAction:n("mceEditImage")}]})}})},vn=function(n){var e;n.ui.registry.addContextToolbar("imagetools",{items:(e=n,e.getParam("imagetools_toolbar","rotateleft rotateright flipv fliph editimage imageoptions")),predicate:function(e){return rn(n,e).isSome()},position:"node",scope:"node"})};i.add("imagetools",function(e){var n=o(0),t=o(null);mn(e,n),gn(e),vn(e),hn(e,n,t)}),function On(){}}(window);
|