1 line
32 KiB
JavaScript
1 line
32 KiB
JavaScript
!function(m){"use strict";var r=function(t){var e=t,n=function(){return e};return{get:n,set:function(t){e=t},clone:function(){return r(n())}}},t=tinymce.util.Tools.resolve("tinymce.PluginManager"),G=tinymce.util.Tools.resolve("tinymce.util.Tools"),i=function(t){return function(){return t}};function a(r){for(var o=[],t=1;t<arguments.length;t++)o[t-1]=arguments[t];return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=o.concat(t);return r.apply(null,n)}}var e,n,o,u,c=i(!1),l=i(!0),f=c,s=l,d=function(){return h},h=(u={fold:function(t,e){return t()},is:f,isSome:f,isNone:s,getOr:o=function(t){return t},getOrThunk:n=function(t){return t()},getOrDie:function(t){throw new Error(t||"error: getOrDie called on none.")},getOrNull:function(){return null},getOrUndefined:function(){return undefined},or:o,orThunk:n,map:d,ap:d,each:function(){},bind:d,flatten:d,exists:f,forall:s,filter:d,equals:e=function(t){return t.isNone()},equals_:e,toArray:function(){return[]},toString:i("none()")},Object.freeze&&Object.freeze(u),u),p=function(n){var t=function(){return n},e=function(){return o},r=function(t){return t(n)},o={fold:function(t,e){return e(n)},is:function(t){return n===t},isSome:s,isNone:f,getOr:t,getOrThunk:t,getOrDie:t,getOrNull:t,getOrUndefined:t,or:e,orThunk:e,map:function(t){return p(t(n))},ap:function(t){return t.fold(d,function(t){return p(t(n))})},each:function(t){t(n)},bind:r,flatten:t,exists:r,forall:r,filter:function(t){return t(n)?o:h},equals:function(t){return t.is(n)},equals_:function(t,e){return t.fold(f,function(t){return e(n,t)})},toArray:function(){return[n]},toString:function(){return"some("+n+")"}};return o},g={some:p,none:d,from:function(t){return null===t||t===undefined?h:p(t)}};function v(t,e){return b(m.document.createElement("canvas"),t,e)}function y(t){var e=v(t.width,t.height);return w(e).drawImage(t,0,0),e}function w(t){return t.getContext("2d")}function b(t,e,n){return t.width=e,t.height=n,t}function x(t){return t.naturalWidth||t.width}function k(t){return t.naturalHeight||t.height}var R=window.Promise?window.Promise:function(){var i=function(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],f(t,r(o,this),r(u,this))},t=i.immediateFn||"function"==typeof window.setImmediate&&window.setImmediate||function(t){m.setTimeout(t,1)};function r(t,e){return function(){return t.apply(e,arguments)}}var n=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function a(r){var o=this;null!==this._state?t(function(){var t=o._state?r.onFulfilled:r.onRejected;if(null!==t){var e;try{e=t(o._value)}catch(n){return void r.reject(n)}r.resolve(e)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}function o(t){try{if(t===this)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var e=t.then;if("function"==typeof e)return void f(r(e,t),r(o,this),r(u,this))}this._state=!0,this._value=t,c.call(this)}catch(n){u.call(this,n)}}function u(t){this._state=!1,this._value=t,c.call(this)}function c(){for(var t=0,e=this._deferreds;t<e.length;t++){var n=e[t];a.call(this,n)}this._deferreds=[]}function l(t,e,n,r){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.resolve=n,this.reject=r}function f(t,e,n){var r=!1;try{t(function(t){r||(r=!0,e(t))},function(t){r||(r=!0,n(t))})}catch(o){if(r)return;r=!0,n(o)}}return i.prototype["catch"]=function(t){return this.then(null,t)},i.prototype.then=function(n,r){var o=this;return new i(function(t,e){a.call(o,new l(n,r,t,e))})},i.all=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var c=Array.prototype.slice.call(1===t.length&&n(t[0])?t[0]:t);return new i(function(o,i){if(0===c.length)return o([]);var a=c.length;function u(e,t){try{if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if("function"==typeof n)return void n.call(t,function(t){u(e,t)},i)}c[e]=t,0==--a&&o(c)}catch(r){i(r)}}for(var t=0;t<c.length;t++)u(t,c[t])})},i.resolve=function(e){return e&&"object"==typeof e&&e.constructor===i?e:new i(function(t){t(e)})},i.reject=function(n){return new i(function(t,e){e(n)})},i.race=function(o){return new i(function(t,e){for(var n=0,r=o;n<r.length;n++)r[n].then(t,e)})},i}();function I(t){var r,e=t.src;return 0===e.indexOf("data:")?T(e):(r=e,new R(function(t,n){var e=new m.XMLHttpRequest;e.open("GET",r,!0),e.responseType="blob",e.onload=function(){200===this.status&&t(this.response)},e.onerror=function(){var t,e=this;n(0===this.status?((t=new Error("No access to download image")).code=18,t.name="SecurityError",t):new Error("Error "+e.status+" downloading image"))},e.send()}))}function M(u){return new R(function(t,e){var n=m.URL.createObjectURL(u),r=new m.Image,o=function(){r.removeEventListener("load",i),r.removeEventListener("error",a)};function i(){o(),t(r)}function a(){o(),e("Unable to load data of type "+u.type+": "+n)}r.addEventListener("load",i),r.addEventListener("error",a),r.src=n,r.complete&&i()})}function T(n){return new R(function(t,e){(function(t){var e=t.split(","),n=/data:([^;]+)/.exec(e[0]);if(!n)return g.none();for(var r=n[1],o=e[1],i=m.atob(o),a=i.length,u=Math.ceil(a/1024),c=new Array(u),l=0;l<u;++l){for(var f=1024*l,s=Math.min(f+1024,a),d=new Array(s-f),h=f,p=0;h<s;++p,++h)d[p]=i[h].charCodeAt(0);c[l]=new Uint8Array(d)}return g.some(new m.Blob(c,{type:r}))})(n).fold(function(){e("uri is not base64: "+n)},t)})}function U(t,r,o){return r=r||"image/png",m.HTMLCanvasElement.prototype.toBlob?new R(function(e,n){t.toBlob(function(t){t?e(t):n()},r,o)}):T(t.toDataURL(r,o))}function C(t){return M(t).then(function(t){var e;e=t,m.URL.revokeObjectURL(e.src);var n=v(x(t),k(t));return w(n).drawImage(t,0,0),n})}function A(t,e,n){var r=e.type;function o(r,o){return t.then(function(t){return n=o,e=(e=r)||"image/png",t.toDataURL(e,n);var e,n})}return{getType:i(r),toBlob:function(){return R.resolve(e)},toDataURL:function(){return n},toBase64:function(){return n.split(",")[1]},toAdjustedBlob:function(e,n){return t.then(function(t){return U(t,e,n)})},toAdjustedDataURL:o,toAdjustedBase64:function(t,e){return o(t,e).then(function(t){return t.split(",")[1]})},toCanvas:function(){return t.then(y)}}}function E(e){return(n=e,new R(function(t){var e=new m.FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n)})).then(function(t){return A(C(e),e,t)});var n}function O(e,t){return U(e,t).then(function(t){return A(R.resolve(e),t,e.toDataURL())})}function _(t,e,n){var r="string"==typeof t?parseFloat(t):t;return n<r?r=n:r<e&&(r=e),r}var j=[0,.01,.02,.04,.05,.06,.07,.08,.1,.11,.12,.14,.15,.16,.17,.18,.2,.21,.22,.24,.25,.27,.28,.3,.32,.34,.36,.38,.4,.42,.44,.46,.48,.5,.53,.56,.59,.62,.65,.68,.71,.74,.77,.8,.83,.86,.89,.92,.95,.98,1,1.06,1.12,1.18,1.24,1.3,1.36,1.42,1.48,1.54,1.6,1.66,1.72,1.78,1.84,1.9,1.96,2,2.12,2.25,2.37,2.5,2.62,2.75,2.87,3,3.2,3.4,3.6,3.8,4,4.3,4.7,4.9,5,5.5,6,6.5,6.8,7,7.3,7.5,7.8,8,8.4,8.7,9,9.4,9.6,9.8,10];function z(t,e){for(var n,r=[],o=new Array(25),i=0;i<5;i++){for(var a=0;a<5;a++)r[a]=e[a+5*i];for(a=0;a<5;a++){for(var u=n=0;u<5;u++)n+=t[a+5*u]*r[u];o[a+5*i]=n}}return o}function L(t,n){return n=_(n,0,1),t.map(function(t,e){return e%6==0?t=1-(1-t)*n:t*=n,_(t,0,1)})}function B(a,u){return a.toCanvas().then(function(t){return e=t,n=a.getType(),r=u,o=w(e),i=function(t,e){for(var n,r,o,i,a=t.data,u=e[0],c=e[1],l=e[2],f=e[3],s=e[4],d=e[5],h=e[6],p=e[7],m=e[8],g=e[9],v=e[10],y=e[11],w=e[12],b=e[13],x=e[14],k=e[15],R=e[16],I=e[17],M=e[18],T=e[19],U=0;U<a.length;U+=4)n=a[U],r=a[U+1],o=a[U+2],i=a[U+3],a[U]=n*u+r*c+o*l+i*f+s,a[U+1]=n*d+r*h+o*p+i*m+g,a[U+2]=n*v+r*y+o*w+i*b+x,a[U+3]=n*k+r*R+o*I+i*M+T;return t}(o.getImageData(0,0,e.width,e.height),r),o.putImageData(i,0,0),O(e,n);var e,n,r,o,i})}function S(u,c){return u.toCanvas().then(function(t){return e=t,n=u.getType(),r=c,o=w(e),i=o.getImageData(0,0,e.width,e.height),a=o.getImageData(0,0,e.width,e.height),a=function(t,e,n){function r(t,e,n){return n<t?t=n:t<e&&(t=e),t}for(var o=Math.round(Math.sqrt(n.length)),i=Math.floor(o/2),a=t.data,u=e.data,c=t.width,l=t.height,f=0;f<l;f++)for(var s=0;s<c;s++){for(var d=0,h=0,p=0,m=0;m<o;m++)for(var g=0;g<o;g++){var v=r(s+g-i,0,c-1),y=r(f+m-i,0,l-1),w=4*(y*c+v),b=n[m*o+g];d+=a[w]*b,h+=a[w+1]*b,p+=a[w+2]*b}var x=4*(f*c+s);u[x]=r(d,0,255),u[x+1]=r(h,0,255),u[x+2]=r(p,0,255)}return e}(i,a,r),o.putImageData(a,0,0),O(e,n);var e,n,r,o,i,a})}function P(u){return function(e,n){return e.toCanvas().then(function(t){return function(t,e,n){for(var r=w(t),o=new Array(256),i=0;i<o.length;i++)o[i]=u(i,n);var a=function(t,e){for(var n=t.data,r=0;r<n.length;r+=4)n[r]=e[n[r]],n[r+1]=e[n[r+1]],n[r+2]=e[n[r+2]];return t}(r.getImageData(0,0,t.width,t.height),o);return r.putImageData(a,0,0),O(t,e)}(t,e.getType(),n)})}}function H(n){return function(t,e){return B(t,n([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1],e))}}function D(e){return function(t){return S(t,e)}}var F,V=(F=[-1,0,0,0,255,0,-1,0,0,255,0,0,-1,0,255,0,0,0,1,0,0,0,0,0,1],function(t){return B(t,F)}),W=H(function(t,e){return z(t,[1,0,0,0,e=_(255*e,-255,255),0,1,0,0,e,0,0,1,0,e,0,0,0,1,0,0,0,0,0,1])}),N=H(function(t,e){e=_(e,-180,180)/180*Math.PI;var n=Math.cos(e),r=Math.sin(e),o=.213,i=.715,a=.072;return z(t,[o+.787*n+r*-o,i+n*-i+r*-i,a+n*-a+.928*r,0,0,o+n*-o+.143*r,i+n*(1-i)+.14*r,a+n*-a+-.283*r,0,0,o+n*-o+-.787*r,i+n*-i+r*i,a+.928*n+r*a,0,0,0,0,0,1,0,0,0,0,0,1])}),q=H(function(t,e){var n=1+(0<(e=_(e,-1,1))?3*e:e);return z(t,[.3086*(1-n)+n,.6094*(1-n),.082*(1-n),0,0,.3086*(1-n),.6094*(1-n)+n,.082*(1-n),0,0,.3086*(1-n),.6094*(1-n),.082*(1-n)+n,0,0,0,0,0,1,0,0,0,0,0,1])}),$=H(function(t,e){var n;return e=_(e,-1,1),z(t,[(n=(e*=100)<0?127+e/100*127:127*(n=0==(n=e%1)?j[e]:j[Math.floor(e)]*(1-n)+j[Math.floor(e)+1]*n)+127)/127,0,0,0,.5*(127-n),0,n/127,0,0,.5*(127-n),0,0,n/127,0,.5*(127-n),0,0,0,1,0,0,0,0,0,1])}),X=H(function(t,e){return z(t,L([.33,.34,.33,0,0,.33,.34,.33,0,0,.33,.34,.33,0,0,0,0,0,1,0,0,0,0,0,1],e=_(e,0,1)))}),Y=H(function(t,e){return z(t,L([.393,.769,.189,0,0,.349,.686,.168,0,0,.272,.534,.131,0,0,0,0,0,1,0,0,0,0,0,1],e=_(e,0,1)))}),K=function(t,e,n,r){return B(t,(o=n,i=r,z([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1],[_(e,0,2),0,0,0,0,0,o=_(o,0,2),0,0,0,0,0,i=_(i,0,2),0,0,0,0,0,1,0,0,0,0,0,1])));var o,i},J=D([0,-1,0,-1,5,-1,0,-1,0]),Z=D([-2,-1,0,-1,1,1,0,1,2]),Q=P(function(t,e){return 255*Math.pow(t/255,1-e)}),tt=P(function(t,e){return 255*(1-Math.exp(-t/255*e))});function et(t,e,n){var r=x(t),o=k(t),i=e/r,a=n/o,u=!1;(i<.5||2<i)&&(i=i<.5?.5:2,u=!0),(a<.5||2<a)&&(a=a<.5?.5:2,u=!0);var c,l,f,s=(c=t,l=i,f=a,new R(function(t){var e=x(c),n=k(c),r=Math.floor(e*l),o=Math.floor(n*f),i=v(r,o),a=w(i);a.drawImage(c,0,0,e,n,0,0,r,o),t(i)}));return u?s.then(function(t){return et(t,e,n)}):s}function nt(c,l){return c.toCanvas().then(function(t){return e=t,n=c.getType(),r=l,o=v(e.width,e.height),i=w(o),90!==(r=r<(u=a=0)?360+r:r)&&270!==r||b(o,o.height,o.width),90!==r&&180!==r||(a=o.width),270!==r&&180!==r||(u=o.height),i.translate(a,u),i.rotate(r*Math.PI/180),i.drawImage(e,0,0),O(o,n);var e,n,r,o,i,a,u})}function rt(a,u){return a.toCanvas().then(function(t){return e=t,n=a.getType(),r=u,o=v(e.width,e.height),i=w(o),"v"===r?(i.scale(1,-1),i.drawImage(e,0,-o.height)):(i.scale(-1,1),i.drawImage(e,-o.width,0)),O(o,n);var e,n,r,o,i})}function ot(a,u,c,l,f){return a.toCanvas().then(function(t){return e=t,n=a.getType(),r=u,o=c,w(i=v(l,f)).drawImage(e,-r,-o),O(i,n);var e,n,r,o,i})}var it=function(t){return V(t)},at=function(t){return J(t)},ut=function(t){return Z(t)},ct=function(t,e){return Q(t,e)},lt=function(t,e){return tt(t,e)},ft=function(t,e,n,r){return K(t,e,n,r)},st=function(t,e){return W(t,e)},dt=function(t,e){return N(t,e)},ht=function(t,e){return q(t,e)},pt=function(t,e){return $(t,e)},mt=function(t,e){return X(t,e)},gt=function(t,e){return Y(t,e)},vt=function(t,e){return rt(t,e)},yt=function(t,e,n,r,o){return ot(t,e,n,r,o)},wt=function(t,e,n){return o=e,i=n,(r=t).toCanvas().then(function(t){return et(t,o,i).then(function(t){return O(t,r.getType())})});var r,o,i},bt=function(t,e){return nt(t,e)},xt=function(t){return E(t)},kt="undefined"!=typeof m.window?m.window:Function("return this;")(),Rt=function(t,e){return function(t,e){for(var n=e!==undefined&&null!==e?e:kt,r=0;r<t.length&&n!==undefined&&null!==n;++r)n=n[t[r]];return n}(t.split("."),e)},It=function(t,e){var n=Rt(t,e);if(n===undefined||null===n)throw new Error(t+" not available on this browser");return n},Mt=function(){return It("URL")},Tt={createObjectURL:function(t){return Mt().createObjectURL(t)},revokeObjectURL:function(t){Mt().revokeObjectURL(t)}},Ut=tinymce.util.Tools.resolve("tinymce.util.Delay"),Ct=tinymce.util.Tools.resolve("tinymce.util.Promise"),At=tinymce.util.Tools.resolve("tinymce.util.URI"),Et=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),Ot=tinymce.util.Tools.resolve("tinymce.ui.Factory"),_t=tinymce.util.Tools.resolve("tinymce.geom.Rect"),jt=function(n){return new Ct(function(t){var e=function(){n.removeEventListener("load",e),t(n)};n.complete?t(n):n.addEventListener("load",e)})},zt=tinymce.util.Tools.resolve("tinymce.dom.DomQuery"),Lt=tinymce.util.Tools.resolve("tinymce.util.Observable"),Bt=tinymce.util.Tools.resolve("tinymce.util.VK"),St=0,Pt={create:function(t){return new(Ot.get("Control").extend({Defaults:{classes:"imagepanel"},selection:function(t){return arguments.length?(this.state.set("rect",t),this):this.state.get("rect")},imageSize:function(){var t=this.state.get("viewRect");return{w:t.w,h:t.h}},toggleCropRect:function(t){this.state.set("cropEnabled",t)},imageSrc:function(t){var o=this,i=new m.Image;i.src=t,jt(i).then(function(){var t,e,n=o.state.get("viewRect");if((e=o.$el.find("img"))[0])e.replaceWith(i);else{var r=m.document.createElement("div");r.className="mce-imagepanel-bg",o.getEl().appendChild(r),o.getEl().appendChild(i)}t={x:0,y:0,w:i.naturalWidth,h:i.naturalHeight},o.state.set("viewRect",t),o.state.set("rect",_t.inflate(t,-20,-20)),n&&n.w===t.w&&n.h===t.h||o.zoomFit(),o.repaintImage(),o.fire("load")})},zoom:function(t){return arguments.length?(this.state.set("zoom",t),this):this.state.get("zoom")},postRender:function(){return this.imageSrc(this.settings.imageSrc),this._super()},zoomFit:function(){var t,e,n,r,o,i;t=this.$el.find("img"),e=this.getEl().clientWidth,n=this.getEl().clientHeight,r=t[0].naturalWidth,o=t[0].naturalHeight,1<=(i=Math.min((e-10)/r,(n-10)/o))&&(i=1),this.zoom(i)},repaintImage:function(){var t,e,n,r,o,i,a,u,c,l,f;f=this.getEl(),c=this.zoom(),l=this.state.get("rect"),a=this.$el.find("img"),u=this.$el.find(".mce-imagepanel-bg"),o=f.offsetWidth,i=f.offsetHeight,n=a[0].naturalWidth*c,r=a[0].naturalHeight*c,t=Math.max(0,o/2-n/2),e=Math.max(0,i/2-r/2),a.css({left:t,top:e,width:n,height:r}),u.css({left:t,top:e,width:n,height:r}),this.cropRect&&(this.cropRect.setRect({x:l.x*c+t,y:l.y*c+e,w:l.w*c,h:l.h*c}),this.cropRect.setClampRect({x:t,y:e,w:n,h:r}),this.cropRect.setViewPortRect({x:0,y:0,w:o,h:i}))},bindStates:function(){var r=this;function n(t){r.cropRect=function(l,n,f,r,o){var s,a,t,i,e="mce-",u=e+"crid-"+St++;function d(t,e){return{x:e.x-t.x,y:e.y-t.y,w:e.w,h:e.h}}function c(t,e,n,r){var o,i,a,u,c;o=e.x,i=e.y,a=e.w,u=e.h,o+=n*t.deltaX,i+=r*t.deltaY,(a+=n*t.deltaW)<20&&(a=20),(u+=r*t.deltaH)<20&&(u=20),c=l=_t.clamp({x:o,y:i,w:a,h:u},f,"move"===t.name),c=d(f,c),s.fire("updateRect",{rect:c}),m(c)}function h(e){function t(t,e){e.h<0&&(e.h=0),e.w<0&&(e.w=0),zt("#"+u+"-"+t,r).css({left:e.x,top:e.y,width:e.w,height:e.h})}G.each(a,function(t){zt("#"+u+"-"+t.name,r).css({left:e.w*t.xMul+e.x,top:e.h*t.yMul+e.y})}),t("top",{x:n.x,y:n.y,w:n.w,h:e.y-n.y}),t("right",{x:e.x+e.w,y:e.y,w:n.w-e.x-e.w+n.x,h:e.h}),t("bottom",{x:n.x,y:e.y+e.h,w:n.w,h:n.h-e.y-e.h+n.y}),t("left",{x:n.x,y:e.y,w:e.x-n.x,h:e.h}),t("move",e)}function p(t){h(l=t)}function m(t){var e,n;p((e=f,{x:(n=t).x+e.x,y:n.y+e.y,w:n.w,h:n.h}))}return a=[{name:"move",xMul:0,yMul:0,deltaX:1,deltaY:1,deltaW:0,deltaH:0,label:"Crop Mask"},{name:"nw",xMul:0,yMul:0,deltaX:1,deltaY:1,deltaW:-1,deltaH:-1,label:"Top Left Crop Handle"},{name:"ne",xMul:1,yMul:0,deltaX:0,deltaY:1,deltaW:1,deltaH:-1,label:"Top Right Crop Handle"},{name:"sw",xMul:0,yMul:1,deltaX:1,deltaY:0,deltaW:-1,deltaH:1,label:"Bottom Left Crop Handle"},{name:"se",xMul:1,yMul:1,deltaX:0,deltaY:0,deltaW:1,deltaH:1,label:"Bottom Right Crop Handle"}],i=["top","right","bottom","left"],zt('<div id="'+u+'" class="'+e+'croprect-container" role="grid" aria-dropeffect="execute">').appendTo(r),G.each(i,function(t){zt("#"+u,r).append('<div id="'+u+"-"+t+'"class="'+e+'croprect-block" style="display: none" data-mce-bogus="all">')}),G.each(a,function(t){zt("#"+u,r).append('<div id="'+u+"-"+t.name+'" class="'+e+"croprect-handle "+e+"croprect-handle-"+t.name+'"style="display: none" data-mce-bogus="all" role="gridcell" tabindex="-1" aria-label="'+t.label+'" aria-grabbed="false">')}),t=G.map(a,function(e){var n;return new(Ot.get("DragHelper"))(u,{document:r.ownerDocument,handle:u+"-"+e.name,start:function(){n=l},drag:function(t){c(e,n,t.deltaX,t.deltaY)}})}),h(l),zt(r).on("focusin focusout",function(t){zt(t.target).attr("aria-grabbed","focus"===t.type)}),zt(r).on("keydown",function(e){var i;function t(t,e,n,r,o){t.stopPropagation(),t.preventDefault(),c(i,n,r,o)}switch(G.each(a,function(t){if(e.target.id===u+"-"+t.name)return i=t,!1}),e.keyCode){case Bt.LEFT:t(e,0,l,-10,0);break;case Bt.RIGHT:t(e,0,l,10,0);break;case Bt.UP:t(e,0,l,0,-10);break;case Bt.DOWN:t(e,0,l,0,10);break;case Bt.ENTER:case Bt.SPACEBAR:e.preventDefault(),o()}}),s=G.extend({toggleVisibility:function(t){var e;e=G.map(a,function(t){return"#"+u+"-"+t.name}).concat(G.map(i,function(t){return"#"+u+"-"+t})).join(","),t?zt(e,r).show():zt(e,r).hide()},setClampRect:function(t){f=t,h(l)},setRect:p,getInnerRect:function(){return d(f,l)},setInnerRect:m,setViewPortRect:function(t){n=t,h(l)},destroy:function(){G.each(t,function(t){t.destroy()}),t=[]}},Lt)}(t,r.state.get("viewRect"),r.state.get("viewRect"),r.getEl(),function(){r.fire("crop")}),r.cropRect.on("updateRect",function(t){var e=t.rect,n=r.zoom();e={x:Math.round(e.x/n),y:Math.round(e.y/n),w:Math.round(e.w/n),h:Math.round(e.h/n)},r.state.set("rect",e)}),r.on("remove",r.cropRect.destroy)}r.state.on("change:cropEnabled",function(t){r.cropRect.toggleVisibility(t.value),r.repaintImage()}),r.state.on("change:zoom",function(){r.repaintImage()}),r.state.on("change:rect",function(t){var e=t.value;r.cropRect||n(e),r.cropRect.setRect(e)})}}))(t)}};function Ht(t){return{blob:t,url:Tt.createObjectURL(t)}}function Dt(t){t&&Tt.revokeObjectURL(t.url)}function Ft(t){G.each(t,Dt)}function Vt(i,a,t,e){var u,n,r,c,o,l,f,s,d,h,p,m,g,v,y,w,b,x,k,R,I,M,T,U,C,A,E,O=function(){var n=[],r=-1;function t(){return 0<r}function e(){return-1!==r&&r<n.length-1}return{data:n,add:function(t){var e;return e=n.splice(++r),n.push(t),{state:t,removed:e}},undo:function(){if(t())return n[--r]},redo:function(){if(e())return n[++r]},canUndo:t,canRedo:e}}(),_=function(t){return i.rtl?t.reverse():t};function j(t){var e,n,r,o;e=u.find("#w")[0],n=u.find("#h")[0],r=parseInt(e.value(),10),o=parseInt(n.value(),10),u.find("#constrain")[0].checked()&&U&&C&&r&&o&&("w"===t.control.settings.name?(o=Math.round(r*A),n.value(o)):(r=Math.round(o*E),e.value(r))),U=r,C=o}function z(t){return Math.round(100*t)+"%"}function L(){u.find("#undo").disabled(!O.canUndo()),u.find("#redo").disabled(!O.canRedo()),u.statusbar.find("#save").disabled(!O.canUndo())}function B(){u.find("#undo").disabled(!0),u.find("#redo").disabled(!0)}function S(t){t&&s.imageSrc(t.url)}function P(e){return function(){var t=G.grep(T,function(t){return t.settings.name!==e});G.each(t,function(t){t.hide()}),e.show(),e.focus()}}function H(t){S(c=Ht(t))}function D(t){S(a=Ht(t)),Ft(O.add(a).removed),L()}function F(){var e=s.selection();xt(a.blob).then(function(t){yt(t,e.x,e.y,e.w,e.h).then($).then(function(t){D(t),W()})})}var V=function(e){var n=[].slice.call(arguments,1);return function(){xt((c||a).blob).then(function(t){e.apply(this,[t].concat(n)).then($).then(H)})}};function W(){S(a),Dt(c),P(n)(),L()}function N(){c?(D(c.blob),W()):function t(e,n){c?n():setTimeout(function(){0<e--?t(e,n):i.windowManager.alert("Error: failed to apply image operation.")},10)}(100,N)}function q(t){return Ot.create("Form",{layout:"flex",direction:"row",labelGap:5,border:"0 0 1 0",align:"center",pack:"center",padding:"0 10 0 10",spacing:5,flex:0,minHeight:60,defaults:{classes:"imagetool",type:"button"},items:t})}var $=function(t){return t.toBlob()};function X(t,e){return q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:N}])).hide().on("show",function(){B(),xt(a.blob).then(function(t){return e(t)}).then($).then(function(t){var e=Ht(t);S(e),Dt(c),c=e})})}function Y(t,n,e,r,o){return q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{type:"slider",flex:1,ondragend:function(t){var e;e=t.value,xt(a.blob).then(function(t){return n(t,e)}).then($).then(function(t){var e=Ht(t);S(e),Dt(c),c=e})},minValue:i.rtl?o:r,maxValue:i.rtl?r:o,value:e,previewFilter:z},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:N}])).hide().on("show",function(){this.find("slider").value(e),B()})}o=q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:F}])).hide().on("show hide",function(t){s.toggleCropRect("show"===t.type)}).on("show",B),l=q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{type:"textbox",name:"w",label:"Width",size:4,onkeyup:j},{type:"textbox",name:"h",label:"Height",size:4,onkeyup:j},{type:"checkbox",name:"constrain",text:"Constrain proportions",checked:!0,onchange:function(t){!0===t.control.value()&&(A=C/U,E=U/C)}},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:"submit"}])).hide().on("submit",function(t){var e=parseInt(u.find("#w").value(),10),n=parseInt(u.find("#h").value(),10);t.preventDefault(),function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=[].slice.call(arguments,1);return function(){xt(a.blob).then(function(t){e.apply(this,[t].concat(r)).then($).then(D)})}}(wt,e,n)(),W()}).on("show",B),f=q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{icon:"fliph",tooltip:"Flip horizontally",onclick:V(vt,"h")},{icon:"flipv",tooltip:"Flip vertically",onclick:V(vt,"v")},{icon:"rotateleft",tooltip:"Rotate counterclockwise",onclick:V(bt,-90)},{icon:"rotateright",tooltip:"Rotate clockwise",onclick:V(bt,90)},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:N}])).hide().on("show",B),p=X(0,it),k=X(0,at),R=X(0,ut),m=Y(0,st,0,-1,1),g=Y(0,dt,180,0,360),v=Y(0,ht,0,-1,1),y=Y(0,pt,0,-1,1),w=Y(0,mt,0,0,1),b=Y(0,gt,0,0,1),x=function(t,o){function e(){var e,n,r;e=u.find("#r")[0].value(),n=u.find("#g")[0].value(),r=u.find("#b")[0].value(),xt(a.blob).then(function(t){return o(t,e,n,r)}).then($).then(function(t){var e=Ht(t);S(e),Dt(c),c=e})}var n=i.rtl?2:0,r=i.rtl?0:2;return q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{type:"slider",label:"R",name:"r",minValue:n,value:1,maxValue:r,ondragend:e,previewFilter:z},{type:"slider",label:"G",name:"g",minValue:n,value:1,maxValue:r,ondragend:e,previewFilter:z},{type:"slider",label:"B",name:"b",minValue:n,value:1,maxValue:r,ondragend:e,previewFilter:z},{type:"spacer",flex:1},{text:"Apply",subtype:"primary",onclick:N}])).hide().on("show",function(){u.find("#r,#g,#b").value(1),B()})}(0,ft),I=Y(0,ct,0,-1,1),M=Y(0,lt,1,0,2),r=q(_([{text:"Back",onclick:W},{type:"spacer",flex:1},{text:"hue",icon:"hue",onclick:P(g)},{text:"saturate",icon:"saturate",onclick:P(v)},{text:"sepia",icon:"sepia",onclick:P(b)},{text:"emboss",icon:"emboss",onclick:P(R)},{text:"exposure",icon:"exposure",onclick:P(M)},{type:"spacer",flex:1}])).hide(),n=q(_([{tooltip:"Crop",icon:"crop",onclick:P(o)},{tooltip:"Resize",icon:"resize2",onclick:P(l)},{tooltip:"Orientation",icon:"orientation",onclick:P(f)},{tooltip:"Brightness",icon:"sun",onclick:P(m)},{tooltip:"Sharpen",icon:"sharpen",onclick:P(k)},{tooltip:"Contrast",icon:"contrast",onclick:P(y)},{tooltip:"Color levels",icon:"drop",onclick:P(x)},{tooltip:"Gamma",icon:"gamma",onclick:P(I)},{tooltip:"Invert",icon:"invert",onclick:P(p)}])),s=Pt.create({flex:1,imageSrc:a.url}),d=Ot.create("Container",{layout:"flex",direction:"column",pack:"start",border:"0 1 0 0",padding:5,spacing:5,items:[{type:"button",icon:"undo",tooltip:"Undo",name:"undo",onclick:function(){S(a=O.undo()),L()}},{type:"button",icon:"redo",tooltip:"Redo",name:"redo",onclick:function(){S(a=O.redo()),L()}},{type:"button",icon:"zoomin",tooltip:"Zoom in",onclick:function(){var t=s.zoom();t<2&&(t+=.1),s.zoom(t)}},{type:"button",icon:"zoomout",tooltip:"Zoom out",onclick:function(){var t=s.zoom();.1<t&&(t-=.1),s.zoom(t)}}]}),h=Ot.create("Container",{type:"container",layout:"flex",direction:"row",align:"stretch",flex:1,items:_([d,s])}),T=[n,o,l,f,r,p,m,g,v,y,w,b,x,k,R,I,M],(u=i.windowManager.open({layout:"flex",direction:"column",align:"stretch",minWidth:Math.min(Et.DOM.getViewPort().w,800),minHeight:Math.min(Et.DOM.getViewPort().h,650),title:"Edit image",items:T.concat([h]),buttons:_([{text:"Save",name:"save",subtype:"primary",onclick:function(){t(a.blob),u.close()}},{text:"Cancel",onclick:"close"}])})).on("close",function(){e(),Ft(O.data),c=O=null}),O.add(a),L(),s.on("load",function(){U=s.imageSize().w,C=s.imageSize().h,A=C/U,E=U/C,u.find("#w").value(U),u.find("#h").value(C)}),s.on("crop",F)}var Wt,Nt={edit:function(r,t){return new Ct(function(e,n){return t.toBlob().then(function(t){Vt(r,Ht(t),e,n)})})}},qt={getImageSize:function(t){var e,n;function r(t){return/^[0-9\.]+px$/.test(t)}return e=t.style.width,n=t.style.height,e||n?r(e)&&r(n)?{w:parseInt(e,10),h:parseInt(n,10)}:null:(e=t.width,n=t.height,e&&n?{w:parseInt(e,10),h:parseInt(n,10)}:null)},setImageSize:function(t,e){var n,r;e&&(n=t.style.width,r=t.style.height,(n||r)&&(t.style.width=e.w+"px",t.style.height=e.h+"px",t.removeAttribute("data-mce-style")),n=t.width,r=t.height,(n||r)&&(t.setAttribute("width",e.w),t.setAttribute("height",e.h)))},getNaturalImageSize:function(t){return{w:t.naturalWidth,h:t.naturalHeight}}},$t=(Wt="function",function(t){return function(t){if(null===t)return"null";var e=typeof t;return"object"===e&&(Array.prototype.isPrototypeOf(t)||t.constructor&&"Array"===t.constructor.name)?"array":"object"===e&&(String.prototype.isPrototypeOf(t)||t.constructor&&"String"===t.constructor.name)?"string":e}(t)===Wt}),Xt=(Array.prototype.slice,function(t,e){for(var n=0,r=t.length;n<r;n++){var o=t[n];if(e(o,n,t))return g.some(o)}return g.none()});$t(Array.from)&&Array.from;var Yt=function(t){return null!==t&&t!==undefined},Gt=function(t,e){var n;return n=e.reduce(function(t,e){return Yt(t)?t[e]:undefined},t),Yt(n)?n:null},Kt=function(e){return new Ct(function(n){var t=new(It("FileReader"));t.onload=function(t){var e=t.target;n(e.result)},t.readAsText(e)})},Jt=function(e,r,o){return new Ct(function(t){var n;(n=new(It("XMLHttpRequest"))).onreadystatechange=function(){4===n.readyState&&t({status:n.status,blob:this.response})},n.open("GET",e,!0),n.withCredentials=o,G.each(r,function(t,e){n.setRequestHeader(e,t)}),n.responseType="blob",n.send()})},Zt=function(t){var e;try{e=JSON.parse(t)}catch(n){}return e},Qt=[{code:404,message:"Could not find Image Proxy"},{code:403,message:"Rejected request"},{code:0,message:"Incorrect Image Proxy URL"}],te=[{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."}],ee=function(e){return"ImageProxy HTTP error: "+Xt(Qt,function(t){return e===t.code}).fold(i("Unknown ImageProxy error"),function(t){return t.message})},ne=function(t){var e=ee(t);return Ct.reject(e)},re=function(e){return Xt(te,function(t){return t.type===e}).fold(i("Unknown service error"),function(t){return t.message})},oe=function(t,e){return Kt(e).then(function(t){var e,n,r=(e=Zt(t),"ImageProxy Service error: "+((n=Gt(e,["error","type"]))?re(n):"Invalid JSON in service error message"));return Ct.reject(r)})},ie=function(t,e){return 400===(n=t)||403===n||500===n?oe(0,e):ne(t);var n},ae=ne,ue=function(t,e){var n,r,o,i={"Content-Type":"application/json;charset=UTF-8","tiny-api-key":e};return Jt((n=t,r=e,o=-1===n.indexOf("?")?"?":"&",/[?&]apiKey=/.test(n)||!r?n:n+o+"apiKey="+encodeURIComponent(r)),i,!1).then(function(t){return t.status<200||300<=t.status?ie(t.status,t.blob):Ct.resolve(t.blob)})},ce=function(t,e,n){return e?ue(t,e):Jt(t,{},n).then(function(t){return t.status<200||300<=t.status?ae(t.status):Ct.resolve(t.blob)})},le=0,fe=function(t,e){t.notificationManager.open({text:e,type:"error"})},se=function(t){return t.selection.getNode()},de=function(t,e){var n=e.src;return 0===n.indexOf("data:")||0===n.indexOf("blob:")||new At(n).host===t.documentBaseURI.host},he=function(t,e){return-1!==G.inArray(t.getParam("imagetools_cors_hosts",[],"string[]"),new At(e.src).host)},pe=function(t,e){var n,r,o,i,a=e.src;return he(t,e)?ce(e.src,null,(r=t,o=e,-1!==G.inArray(r.getParam("imagetools_credentials_hosts",[],"string[]"),new At(o.src).host))):de(t,e)?I(e):(a=t.getParam("imagetools_proxy"),a+=(-1===a.indexOf("?")?"?":"&")+"url="+encodeURIComponent(e.src),n=(i=t).getParam("api_key",i.getParam("imagetools_api_key","","string"),"string"),ce(a,n,!1))},me=function(t){var e;return(e=t.editorUpload.blobCache.getByUri(se(t).src))?Ct.resolve(e.blob()):pe(t,se(t))},ge=function(t){clearTimeout(t.get())},ve=function(c,l,f,s,d){return l.toBlob().then(function(t){var e,n,r,o,i,a,u;return r=c.editorUpload.blobCache,e=(i=se(c)).src,c.getParam("images_reuse_filename",!1,"boolean")&&((o=r.getByUri(e))?(e=o.uri(),n=o.name()):(a=c,n=(u=e.match(/\/([^\/\?]+)?\.(?:jpeg|jpg|png|gif)(?:\?|$)/i))?a.dom.encode(u[1]):null)),o=r.create({id:"imagetools"+le++,blob:t,base64:l.toBase64(),uri:e,name:n}),r.add(o),c.undoManager.transact(function(){c.$(i).on("load",function t(){var e,n,r;c.$(i).off("load",t),c.nodeChanged(),f?c.editorUpload.uploadImagesAuto():(ge(s),e=c,n=s,r=Ut.setEditorTimeout(e,function(){e.editorUpload.uploadImagesAuto()},e.getParam("images_upload_timeout",3e4,"number")),n.set(r))}),d&&c.$(i).attr({width:d.w,height:d.h}),c.$(i).attr({src:o.blobUri()}).removeAttr("data-mce-src")}),o})},ye=function(e,n,t,r){return function(){return e._scanForImages().then(a(me,e)).then(xt).then(t).then(function(t){return ve(e,t,!1,n,r)},function(t){fe(e,t)})}},we=function(n,r,o){return function(){var t=qt.getImageSize(se(n)),e=t?{w:t.h,h:t.w}:null;return ye(n,r,function(t){return bt(t,o)},e)()}},be=function(t,e,n){return function(){return ye(t,e,function(t){return vt(t,n)})()}},xe=function(e,r){return function(){var o=se(e),i=qt.getNaturalImageSize(o),n=function(r){return new Ct(function(n){var t;(t=r,M(t)).then(function(t){var e=qt.getNaturalImageSize(t);i.w===e.w&&i.h===e.h||qt.getImageSize(o)&&qt.setImageSize(o,e),Tt.revokeObjectURL(t.src),n(r)})})};me(e).then(xt).then(a(function(e,t){return Nt.edit(e,t).then(n).then(xt).then(function(t){return ve(e,t,!0,r)},function(){})},e),function(t){fe(e,t)})}},ke=function(t,e){return t.dom.is(e,"img:not([data-mce-object],[data-mce-placeholder])")&&(de(t,e)||he(t,e)||t.settings.imagetools_proxy)},Re=ge,Ie=function(n,t){G.each({mceImageRotateLeft:we(n,t,-90),mceImageRotateRight:we(n,t,90),mceImageFlipVertical:be(n,t,"v"),mceImageFlipHorizontal:be(n,t,"h"),mceEditImage:xe(n,t)},function(t,e){n.addCommand(e,t)})},Me=function(n,r,o){n.on("NodeChange",function(t){var e=o.get();e&&e.src!==t.element.src&&(Re(r),n.editorUpload.uploadImagesAuto(),o.set(null)),ke(n,t.element)&&o.set(t.element)})},Te=function(t){t.addButton("rotateleft",{title:"Rotate counterclockwise",cmd:"mceImageRotateLeft"}),t.addButton("rotateright",{title:"Rotate clockwise",cmd:"mceImageRotateRight"}),t.addButton("flipv",{title:"Flip vertically",cmd:"mceImageFlipVertical"}),t.addButton("fliph",{title:"Flip horizontally",cmd:"mceImageFlipHorizontal"}),t.addButton("editimage",{title:"Edit image",cmd:"mceEditImage"}),t.addButton("imageoptions",{title:"Image options",icon:"options",cmd:"mceImage"})},Ue=function(t){t.addContextToolbar(a(ke,t),t.getParam("imagetools_toolbar","rotateleft rotateright | flipv fliph | crop editimage imageoptions"))};t.add("imagetools",function(t){var e=r(0),n=r(null);Ie(t,e),Te(t),Ue(t),Me(t,e,n)})}(window); |