123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710 |
- /**
- * 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.1.0 (2019-10-17)
- */
- (function (domGlobals) {
- 'use strict';
- var Cell = function (initial) {
- var value = initial;
- var get = function () {
- return value;
- };
- var set = function (v) {
- value = v;
- };
- var clone = function () {
- return Cell(get());
- };
- return {
- get: get,
- set: set,
- clone: clone
- };
- };
- var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
- var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
- var noop = function () {
- };
- var constant = function (value) {
- return function () {
- return value;
- };
- };
- var never = constant(false);
- var always = constant(true);
- var none = function () {
- return NONE;
- };
- var NONE = function () {
- var eq = function (o) {
- return o.isNone();
- };
- var call = function (thunk) {
- return thunk();
- };
- var id = function (n) {
- return n;
- };
- var me = {
- fold: function (n, s) {
- return n();
- },
- is: never,
- isSome: never,
- isNone: always,
- getOr: id,
- getOrThunk: call,
- getOrDie: function (msg) {
- throw new Error(msg || 'error: getOrDie called on none.');
- },
- getOrNull: constant(null),
- getOrUndefined: constant(undefined),
- or: id,
- orThunk: call,
- map: none,
- each: noop,
- bind: none,
- exists: never,
- forall: always,
- filter: none,
- equals: eq,
- equals_: eq,
- toArray: function () {
- return [];
- },
- toString: constant('none()')
- };
- if (Object.freeze) {
- Object.freeze(me);
- }
- return me;
- }();
- var some = function (a) {
- var constant_a = constant(a);
- var self = function () {
- return me;
- };
- var bind = function (f) {
- return f(a);
- };
- var me = {
- fold: function (n, s) {
- return s(a);
- },
- is: function (v) {
- return a === v;
- },
- isSome: always,
- isNone: never,
- getOr: constant_a,
- getOrThunk: constant_a,
- getOrDie: constant_a,
- getOrNull: constant_a,
- getOrUndefined: constant_a,
- or: self,
- orThunk: self,
- map: function (f) {
- return some(f(a));
- },
- each: function (f) {
- f(a);
- },
- bind: bind,
- exists: bind,
- forall: bind,
- filter: function (f) {
- return f(a) ? me : NONE;
- },
- toArray: function () {
- return [a];
- },
- toString: function () {
- return 'some(' + a + ')';
- },
- equals: function (o) {
- return o.is(a);
- },
- equals_: function (o, elementEq) {
- return o.fold(never, function (b) {
- return elementEq(a, b);
- });
- }
- };
- return me;
- };
- var from = function (value) {
- return value === null || value === undefined ? NONE : some(value);
- };
- var Option = {
- some: some,
- none: none,
- from: from
- };
- function create(width, height) {
- return resize(domGlobals.document.createElement('canvas'), width, height);
- }
- function clone(canvas) {
- var tCanvas = create(canvas.width, canvas.height);
- var ctx = get2dContext(tCanvas);
- ctx.drawImage(canvas, 0, 0);
- return tCanvas;
- }
- function get2dContext(canvas) {
- return canvas.getContext('2d');
- }
- function resize(canvas, width, height) {
- canvas.width = width;
- canvas.height = height;
- return canvas;
- }
- function getWidth(image) {
- return image.naturalWidth || image.width;
- }
- function getHeight(image) {
- return image.naturalHeight || image.height;
- }
- var promise = function () {
- var Promise = function (fn) {
- if (typeof this !== 'object') {
- throw new TypeError('Promises must be constructed via new');
- }
- if (typeof fn !== 'function') {
- throw new TypeError('not a function');
- }
- this._state = null;
- this._value = null;
- this._deferreds = [];
- doResolve(fn, bind(resolve, this), bind(reject, this));
- };
- var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
- domGlobals.setTimeout(fn, 1);
- };
- function bind(fn, thisArg) {
- return function () {
- return fn.apply(thisArg, arguments);
- };
- }
- var isArray = Array.isArray || function (value) {
- return Object.prototype.toString.call(value) === '[object Array]';
- };
- function handle(deferred) {
- var me = this;
- if (this._state === null) {
- this._deferreds.push(deferred);
- return;
- }
- asap(function () {
- var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
- if (cb === null) {
- (me._state ? deferred.resolve : deferred.reject)(me._value);
- return;
- }
- var ret;
- try {
- ret = cb(me._value);
- } catch (e) {
- deferred.reject(e);
- return;
- }
- deferred.resolve(ret);
- });
- }
- function resolve(newValue) {
- try {
- if (newValue === this) {
- throw new TypeError('A promise cannot be resolved with itself.');
- }
- if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
- var then = newValue.then;
- if (typeof then === 'function') {
- doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
- return;
- }
- }
- this._state = true;
- this._value = newValue;
- finale.call(this);
- } catch (e) {
- reject.call(this, e);
- }
- }
- function reject(newValue) {
- this._state = false;
- this._value = newValue;
- finale.call(this);
- }
- function finale() {
- for (var _i = 0, _a = this._deferreds; _i < _a.length; _i++) {
- var deferred = _a[_i];
- handle.call(this, deferred);
- }
- this._deferreds = [];
- }
- function Handler(onFulfilled, onRejected, resolve, reject) {
- this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
- this.onRejected = typeof onRejected === 'function' ? onRejected : null;
- this.resolve = resolve;
- this.reject = reject;
- }
- function doResolve(fn, onFulfilled, onRejected) {
- var done = false;
- try {
- fn(function (value) {
- if (done) {
- return;
- }
- done = true;
- onFulfilled(value);
- }, function (reason) {
- if (done) {
- return;
- }
- done = true;
- onRejected(reason);
- });
- } catch (ex) {
- if (done) {
- return;
- }
- done = true;
- onRejected(ex);
- }
- }
- Promise.prototype.catch = function (onRejected) {
- return this.then(null, onRejected);
- };
- Promise.prototype.then = function (onFulfilled, onRejected) {
- var me = this;
- return new Promise(function (resolve, reject) {
- handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
- });
- };
- Promise.all = function () {
- var values = [];
- for (var _i = 0; _i < arguments.length; _i++) {
- values[_i] = arguments[_i];
- }
- var args = Array.prototype.slice.call(values.length === 1 && isArray(values[0]) ? values[0] : values);
- return new Promise(function (resolve, reject) {
- if (args.length === 0) {
- return resolve([]);
- }
- var remaining = args.length;
- function res(i, val) {
- try {
- if (val && (typeof val === 'object' || typeof val === 'function')) {
- var then = val.then;
- if (typeof then === 'function') {
- then.call(val, function (val) {
- res(i, val);
- }, reject);
- return;
- }
- }
- args[i] = val;
- if (--remaining === 0) {
- resolve(args);
- }
- } catch (ex) {
- reject(ex);
- }
- }
- for (var i = 0; i < args.length; i++) {
- res(i, args[i]);
- }
- });
- };
- Promise.resolve = function (value) {
- if (value && typeof value === 'object' && value.constructor === Promise) {
- return value;
- }
- return new Promise(function (resolve) {
- resolve(value);
- });
- };
- Promise.reject = function (reason) {
- return new Promise(function (resolve, reject) {
- reject(reason);
- });
- };
- Promise.race = function (values) {
- return new Promise(function (resolve, reject) {
- for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
- var value = values_1[_i];
- value.then(resolve, reject);
- }
- });
- };
- return Promise;
- };
- var Promise = window.Promise ? window.Promise : promise();
- function imageToBlob(image) {
- var src = image.src;
- if (src.indexOf('data:') === 0) {
- return dataUriToBlob(src);
- }
- return anyUriToBlob(src);
- }
- function blobToImage(blob) {
- return new Promise(function (resolve, reject) {
- var blobUrl = domGlobals.URL.createObjectURL(blob);
- var image = new domGlobals.Image();
- var removeListeners = function () {
- image.removeEventListener('load', loaded);
- image.removeEventListener('error', error);
- };
- function loaded() {
- removeListeners();
- resolve(image);
- }
- function error() {
- removeListeners();
- reject('Unable to load data of type ' + blob.type + ': ' + blobUrl);
- }
- image.addEventListener('load', loaded);
- image.addEventListener('error', error);
- image.src = blobUrl;
- if (image.complete) {
- loaded();
- }
- });
- }
- function anyUriToBlob(url) {
- return new Promise(function (resolve, reject) {
- var xhr = new domGlobals.XMLHttpRequest();
- xhr.open('GET', url, true);
- xhr.responseType = 'blob';
- xhr.onload = function () {
- if (this.status === 200) {
- resolve(this.response);
- }
- };
- xhr.onerror = function () {
- var _this = this;
- var corsError = function () {
- var obj = new Error('No access to download image');
- obj.code = 18;
- obj.name = 'SecurityError';
- return obj;
- };
- var genericError = function () {
- return new Error('Error ' + _this.status + ' downloading image');
- };
- reject(this.status === 0 ? corsError() : genericError());
- };
- xhr.send();
- });
- }
- function dataUriToBlobSync(uri) {
- var data = uri.split(',');
- var matches = /data:([^;]+)/.exec(data[0]);
- if (!matches) {
- return Option.none();
- }
- var mimetype = matches[1];
- var base64 = data[1];
- var sliceSize = 1024;
- var byteCharacters = domGlobals.atob(base64);
- var bytesLength = byteCharacters.length;
- var slicesCount = Math.ceil(bytesLength / sliceSize);
- var byteArrays = new Array(slicesCount);
- for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
- var begin = sliceIndex * sliceSize;
- var end = Math.min(begin + sliceSize, bytesLength);
- var bytes = new Array(end - begin);
- for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
- bytes[i] = byteCharacters[offset].charCodeAt(0);
- }
- byteArrays[sliceIndex] = new Uint8Array(bytes);
- }
- return Option.some(new domGlobals.Blob(byteArrays, { type: mimetype }));
- }
- function dataUriToBlob(uri) {
- return new Promise(function (resolve, reject) {
- dataUriToBlobSync(uri).fold(function () {
- reject('uri is not base64: ' + uri);
- }, resolve);
- });
- }
- function canvasToBlob(canvas, type, quality) {
- type = type || 'image/png';
- if (domGlobals.HTMLCanvasElement.prototype.toBlob) {
- return new Promise(function (resolve, reject) {
- canvas.toBlob(function (blob) {
- if (blob) {
- resolve(blob);
- } else {
- reject();
- }
- }, type, quality);
- });
- } else {
- return dataUriToBlob(canvas.toDataURL(type, quality));
- }
- }
- function canvasToDataURL(canvas, type, quality) {
- type = type || 'image/png';
- return canvas.toDataURL(type, quality);
- }
- function blobToCanvas(blob) {
- return blobToImage(blob).then(function (image) {
- revokeImageUrl(image);
- var canvas = create(getWidth(image), getHeight(image));
- var context = get2dContext(canvas);
- context.drawImage(image, 0, 0);
- return canvas;
- });
- }
- function blobToDataUri(blob) {
- return new Promise(function (resolve) {
- var reader = new domGlobals.FileReader();
- reader.onloadend = function () {
- resolve(reader.result);
- };
- reader.readAsDataURL(blob);
- });
- }
- function revokeImageUrl(image) {
- domGlobals.URL.revokeObjectURL(image.src);
- }
- var blobToImage$1 = function (blob) {
- return blobToImage(blob);
- };
- var imageToBlob$1 = function (image) {
- return imageToBlob(image);
- };
- function create$1(getCanvas, blob, uri) {
- var initialType = blob.type;
- var getType = constant(initialType);
- function toBlob() {
- return Promise.resolve(blob);
- }
- function toDataURL() {
- return uri;
- }
- function toBase64() {
- return uri.split(',')[1];
- }
- function toAdjustedBlob(type, quality) {
- return getCanvas.then(function (canvas) {
- return canvasToBlob(canvas, type, quality);
- });
- }
- function toAdjustedDataURL(type, quality) {
- return getCanvas.then(function (canvas) {
- return canvasToDataURL(canvas, type, quality);
- });
- }
- function toAdjustedBase64(type, quality) {
- return toAdjustedDataURL(type, quality).then(function (dataurl) {
- return dataurl.split(',')[1];
- });
- }
- function toCanvas() {
- return getCanvas.then(clone);
- }
- return {
- getType: getType,
- toBlob: toBlob,
- toDataURL: toDataURL,
- toBase64: toBase64,
- toAdjustedBlob: toAdjustedBlob,
- toAdjustedDataURL: toAdjustedDataURL,
- toAdjustedBase64: toAdjustedBase64,
- toCanvas: toCanvas
- };
- }
- function fromBlob(blob) {
- return blobToDataUri(blob).then(function (uri) {
- return create$1(blobToCanvas(blob), blob, uri);
- });
- }
- function fromCanvas(canvas, type) {
- return canvasToBlob(canvas, type).then(function (blob) {
- return create$1(Promise.resolve(canvas), blob, canvas.toDataURL());
- });
- }
- function rotate(ir, angle) {
- return ir.toCanvas().then(function (canvas) {
- return applyRotate(canvas, ir.getType(), angle);
- });
- }
- function applyRotate(image, type, angle) {
- var canvas = create(image.width, image.height);
- var context = get2dContext(canvas);
- var translateX = 0;
- var translateY = 0;
- angle = angle < 0 ? 360 + angle : angle;
- if (angle === 90 || angle === 270) {
- resize(canvas, canvas.height, canvas.width);
- }
- if (angle === 90 || angle === 180) {
- translateX = canvas.width;
- }
- if (angle === 270 || angle === 180) {
- translateY = canvas.height;
- }
- context.translate(translateX, translateY);
- context.rotate(angle * Math.PI / 180);
- context.drawImage(image, 0, 0);
- return fromCanvas(canvas, type);
- }
- function flip(ir, axis) {
- return ir.toCanvas().then(function (canvas) {
- return applyFlip(canvas, ir.getType(), axis);
- });
- }
- function applyFlip(image, type, axis) {
- var canvas = create(image.width, image.height);
- var context = get2dContext(canvas);
- if (axis === 'v') {
- context.scale(1, -1);
- context.drawImage(image, 0, -canvas.height);
- } else {
- context.scale(-1, 1);
- context.drawImage(image, -canvas.width, 0);
- }
- return fromCanvas(canvas, type);
- }
- var flip$1 = function (ir, axis) {
- return flip(ir, axis);
- };
- var rotate$1 = function (ir, angle) {
- return rotate(ir, angle);
- };
- var blobToImageResult = function (blob) {
- return fromBlob(blob);
- };
- var global$2 = tinymce.util.Tools.resolve('tinymce.util.Delay');
- var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
- var global$4 = tinymce.util.Tools.resolve('tinymce.util.URI');
- var getToolbarItems = function (editor) {
- return editor.getParam('imagetools_toolbar', 'rotateleft rotateright flipv fliph editimage imageoptions');
- };
- var getProxyUrl = function (editor) {
- return editor.getParam('imagetools_proxy');
- };
- var getCorsHosts = function (editor) {
- return editor.getParam('imagetools_cors_hosts', [], 'string[]');
- };
- var getCredentialsHosts = function (editor) {
- return editor.getParam('imagetools_credentials_hosts', [], 'string[]');
- };
- var getFetchImage = function (editor) {
- return Option.from(editor.getParam('imagetools_fetch_image', null, 'function'));
- };
- var getApiKey = function (editor) {
- return editor.getParam('api_key', editor.getParam('imagetools_api_key', '', 'string'), 'string');
- };
- var getUploadTimeout = function (editor) {
- return editor.getParam('images_upload_timeout', 30000, 'number');
- };
- var shouldReuseFilename = function (editor) {
- return editor.getParam('images_reuse_filename', false, 'boolean');
- };
- function getImageSize(img) {
- var width, height;
- function isPxValue(value) {
- return /^[0-9\.]+px$/.test(value);
- }
- width = img.style.width;
- height = img.style.height;
- if (width || height) {
- if (isPxValue(width) && isPxValue(height)) {
- return {
- w: parseInt(width, 10),
- h: parseInt(height, 10)
- };
- }
- return null;
- }
- width = img.width;
- height = img.height;
- if (width && height) {
- return {
- w: parseInt(width, 10),
- h: parseInt(height, 10)
- };
- }
- return null;
- }
- function setImageSize(img, size) {
- var width, height;
- if (size) {
- width = img.style.width;
- height = img.style.height;
- if (width || height) {
- img.style.width = size.w + 'px';
- img.style.height = size.h + 'px';
- img.removeAttribute('data-mce-style');
- }
- width = img.width;
- height = img.height;
- if (width || height) {
- img.setAttribute('width', size.w);
- img.setAttribute('height', size.h);
- }
- }
- }
- function getNaturalImageSize(img) {
- return {
- w: img.naturalWidth,
- h: img.naturalHeight
- };
- }
- var ImageSize = {
- getImageSize: getImageSize,
- setImageSize: setImageSize,
- getNaturalImageSize: getNaturalImageSize
- };
- var typeOf = function (x) {
- if (x === null) {
- return 'null';
- }
- var t = typeof x;
- if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- }
- if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- }
- return t;
- };
- var isType = function (type) {
- return function (value) {
- return typeOf(value) === type;
- };
- };
- var isFunction = isType('function');
- var nativeSlice = Array.prototype.slice;
- var find = function (xs, pred) {
- for (var i = 0, len = xs.length; i < len; i++) {
- var x = xs[i];
- if (pred(x, i)) {
- return Option.some(x);
- }
- }
- return Option.none();
- };
- var from$1 = isFunction(Array.from) ? Array.from : function (x) {
- return nativeSlice.call(x);
- };
- var isValue = function (obj) {
- return obj !== null && obj !== undefined;
- };
- var traverse = function (json, path) {
- var value;
- value = path.reduce(function (result, key) {
- return isValue(result) ? result[key] : undefined;
- }, json);
- return isValue(value) ? value : null;
- };
- var requestUrlAsBlob = function (url, headers, withCredentials) {
- return new global$3(function (resolve) {
- var xhr;
- xhr = new domGlobals.XMLHttpRequest();
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4) {
- resolve({
- status: xhr.status,
- blob: this.response
- });
- }
- };
- xhr.open('GET', url, true);
- xhr.withCredentials = withCredentials;
- global$1.each(headers, function (value, key) {
- xhr.setRequestHeader(key, value);
- });
- xhr.responseType = 'blob';
- xhr.send();
- });
- };
- var readBlob = function (blob) {
- return new global$3(function (resolve) {
- var fr = new domGlobals.FileReader();
- fr.onload = function (e) {
- var data = e.target;
- resolve(data.result);
- };
- fr.readAsText(blob);
- });
- };
- var parseJson = function (text) {
- var json;
- try {
- json = JSON.parse(text);
- } catch (ex) {
- }
- return json;
- };
- var Utils = {
- traverse: traverse,
- readBlob: readBlob,
- requestUrlAsBlob: requestUrlAsBlob,
- parseJson: parseJson
- };
- var friendlyHttpErrors = [
- {
- code: 404,
- message: 'Could not find Image Proxy'
- },
- {
- code: 403,
- message: 'Rejected request'
- },
- {
- code: 0,
- message: 'Incorrect Image Proxy URL'
- }
- ];
- var friendlyServiceErrors = [
- {
- 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.'
- }
- ];
- var isServiceErrorCode = function (code) {
- return code === 400 || code === 403 || code === 500;
- };
- var getHttpErrorMsg = function (status) {
- var message = find(friendlyHttpErrors, function (error) {
- return status === error.code;
- }).fold(constant('Unknown ImageProxy error'), function (error) {
- return error.message;
- });
- return 'ImageProxy HTTP error: ' + message;
- };
- var handleHttpError = function (status) {
- var message = getHttpErrorMsg(status);
- return global$3.reject(message);
- };
- var getServiceErrorMsg = function (type) {
- return find(friendlyServiceErrors, function (error) {
- return error.type === type;
- }).fold(constant('Unknown service error'), function (error) {
- return error.message;
- });
- };
- var getServiceError = function (text) {
- var serviceError = Utils.parseJson(text);
- var errorType = Utils.traverse(serviceError, [
- 'error',
- 'type'
- ]);
- var errorMsg = errorType ? getServiceErrorMsg(errorType) : 'Invalid JSON in service error message';
- return 'ImageProxy Service error: ' + errorMsg;
- };
- var handleServiceError = function (status, blob) {
- return Utils.readBlob(blob).then(function (text) {
- var serviceError = getServiceError(text);
- return global$3.reject(serviceError);
- });
- };
- var handleServiceErrorResponse = function (status, blob) {
- return isServiceErrorCode(status) ? handleServiceError(status, blob) : handleHttpError(status);
- };
- var Errors = {
- handleServiceErrorResponse: handleServiceErrorResponse,
- handleHttpError: handleHttpError,
- getHttpErrorMsg: getHttpErrorMsg,
- getServiceErrorMsg: getServiceErrorMsg
- };
- var appendApiKey = function (url, apiKey) {
- var separator = url.indexOf('?') === -1 ? '?' : '&';
- if (/[?&]apiKey=/.test(url) || !apiKey) {
- return url;
- } else {
- return url + separator + 'apiKey=' + encodeURIComponent(apiKey);
- }
- };
- var requestServiceBlob = function (url, apiKey) {
- var headers = {
- 'Content-Type': 'application/json;charset=UTF-8',
- 'tiny-api-key': apiKey
- };
- return Utils.requestUrlAsBlob(appendApiKey(url, apiKey), headers, false).then(function (result) {
- return result.status < 200 || result.status >= 300 ? Errors.handleServiceErrorResponse(result.status, result.blob) : global$3.resolve(result.blob);
- });
- };
- function requestBlob(url, withCredentials) {
- return Utils.requestUrlAsBlob(url, {}, withCredentials).then(function (result) {
- return result.status < 200 || result.status >= 300 ? Errors.handleHttpError(result.status) : global$3.resolve(result.blob);
- });
- }
- var getUrl = function (url, apiKey, withCredentials) {
- return apiKey ? requestServiceBlob(url, apiKey) : requestBlob(url, withCredentials);
- };
- var compareDocumentPosition = function (a, b, match) {
- return (a.compareDocumentPosition(b) & match) !== 0;
- };
- var documentPositionPreceding = function (a, b) {
- return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_PRECEDING);
- };
- var documentPositionContainedBy = function (a, b) {
- return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
- };
- var Node = {
- documentPositionPreceding: documentPositionPreceding,
- documentPositionContainedBy: documentPositionContainedBy
- };
- var firstMatch = function (regexes, s) {
- for (var i = 0; i < regexes.length; i++) {
- var x = regexes[i];
- if (x.test(s)) {
- return x;
- }
- }
- return undefined;
- };
- var find$1 = function (regexes, agent) {
- var r = firstMatch(regexes, agent);
- if (!r) {
- return {
- major: 0,
- minor: 0
- };
- }
- var group = function (i) {
- return Number(agent.replace(r, '$' + i));
- };
- return nu(group(1), group(2));
- };
- var detect = function (versionRegexes, agent) {
- var cleanedAgent = String(agent).toLowerCase();
- if (versionRegexes.length === 0) {
- return unknown();
- }
- return find$1(versionRegexes, cleanedAgent);
- };
- var unknown = function () {
- return nu(0, 0);
- };
- var nu = function (major, minor) {
- return {
- major: major,
- minor: minor
- };
- };
- var Version = {
- nu: nu,
- detect: detect,
- unknown: unknown
- };
- var edge = 'Edge';
- var chrome = 'Chrome';
- var ie = 'IE';
- var opera = 'Opera';
- var firefox = 'Firefox';
- var safari = 'Safari';
- var isBrowser = function (name, current) {
- return function () {
- return current === name;
- };
- };
- var unknown$1 = function () {
- return nu$1({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$1 = function (info) {
- var current = info.current;
- var version = info.version;
- return {
- current: current,
- version: version,
- isEdge: isBrowser(edge, current),
- isChrome: isBrowser(chrome, current),
- isIE: isBrowser(ie, current),
- isOpera: isBrowser(opera, current),
- isFirefox: isBrowser(firefox, current),
- isSafari: isBrowser(safari, current)
- };
- };
- var Browser = {
- unknown: unknown$1,
- nu: nu$1,
- edge: constant(edge),
- chrome: constant(chrome),
- ie: constant(ie),
- opera: constant(opera),
- firefox: constant(firefox),
- safari: constant(safari)
- };
- var windows = 'Windows';
- var ios = 'iOS';
- var android = 'Android';
- var linux = 'Linux';
- var osx = 'OSX';
- var solaris = 'Solaris';
- var freebsd = 'FreeBSD';
- var isOS = function (name, current) {
- return function () {
- return current === name;
- };
- };
- var unknown$2 = function () {
- return nu$2({
- current: undefined,
- version: Version.unknown()
- });
- };
- var nu$2 = function (info) {
- var current = info.current;
- var version = info.version;
- return {
- current: current,
- version: version,
- isWindows: isOS(windows, current),
- isiOS: isOS(ios, current),
- isAndroid: isOS(android, current),
- isOSX: isOS(osx, current),
- isLinux: isOS(linux, current),
- isSolaris: isOS(solaris, current),
- isFreeBSD: isOS(freebsd, current)
- };
- };
- var OperatingSystem = {
- unknown: unknown$2,
- nu: nu$2,
- windows: constant(windows),
- ios: constant(ios),
- android: constant(android),
- linux: constant(linux),
- osx: constant(osx),
- solaris: constant(solaris),
- freebsd: constant(freebsd)
- };
- var DeviceType = function (os, browser, userAgent, mediaMatch) {
- var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
- var isiPhone = os.isiOS() && !isiPad;
- var isMobile = os.isiOS() || os.isAndroid();
- var isTouch = isMobile || mediaMatch('(pointer:coarse)');
- var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
- var isPhone = isiPhone || isMobile && !isTablet;
- var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
- var isDesktop = !isPhone && !isTablet && !iOSwebview;
- return {
- isiPad: constant(isiPad),
- isiPhone: constant(isiPhone),
- isTablet: constant(isTablet),
- isPhone: constant(isPhone),
- isTouch: constant(isTouch),
- isAndroid: os.isAndroid,
- isiOS: os.isiOS,
- isWebView: constant(iOSwebview),
- isDesktop: constant(isDesktop)
- };
- };
- var detect$1 = function (candidates, userAgent) {
- var agent = String(userAgent).toLowerCase();
- return find(candidates, function (candidate) {
- return candidate.search(agent);
- });
- };
- var detectBrowser = function (browsers, userAgent) {
- return detect$1(browsers, userAgent).map(function (browser) {
- var version = Version.detect(browser.versionRegexes, userAgent);
- return {
- current: browser.name,
- version: version
- };
- });
- };
- var detectOs = function (oses, userAgent) {
- return detect$1(oses, userAgent).map(function (os) {
- var version = Version.detect(os.versionRegexes, userAgent);
- return {
- current: os.name,
- version: version
- };
- });
- };
- var UaString = {
- detectBrowser: detectBrowser,
- detectOs: detectOs
- };
- var contains = function (str, substr) {
- return str.indexOf(substr) !== -1;
- };
- var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
- var checkContains = function (target) {
- return function (uastring) {
- return contains(uastring, target);
- };
- };
- var browsers = [
- {
- name: 'Edge',
- versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
- search: function (uastring) {
- return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
- }
- },
- {
- name: 'Chrome',
- versionRegexes: [
- /.*?chrome\/([0-9]+)\.([0-9]+).*/,
- normalVersionRegex
- ],
- search: function (uastring) {
- return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
- }
- },
- {
- name: 'IE',
- versionRegexes: [
- /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
- /.*?rv:([0-9]+)\.([0-9]+).*/
- ],
- search: function (uastring) {
- return contains(uastring, 'msie') || contains(uastring, 'trident');
- }
- },
- {
- name: 'Opera',
- versionRegexes: [
- normalVersionRegex,
- /.*?opera\/([0-9]+)\.([0-9]+).*/
- ],
- search: checkContains('opera')
- },
- {
- name: 'Firefox',
- versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
- search: checkContains('firefox')
- },
- {
- name: 'Safari',
- versionRegexes: [
- normalVersionRegex,
- /.*?cpu os ([0-9]+)_([0-9]+).*/
- ],
- search: function (uastring) {
- return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
- }
- }
- ];
- var oses = [
- {
- name: 'Windows',
- search: checkContains('win'),
- versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'iOS',
- search: function (uastring) {
- return contains(uastring, 'iphone') || contains(uastring, 'ipad');
- },
- versionRegexes: [
- /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
- /.*cpu os ([0-9]+)_([0-9]+).*/,
- /.*cpu iphone os ([0-9]+)_([0-9]+).*/
- ]
- },
- {
- name: 'Android',
- search: checkContains('android'),
- versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
- },
- {
- name: 'OSX',
- search: checkContains('os x'),
- versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
- },
- {
- name: 'Linux',
- search: checkContains('linux'),
- versionRegexes: []
- },
- {
- name: 'Solaris',
- search: checkContains('sunos'),
- versionRegexes: []
- },
- {
- name: 'FreeBSD',
- search: checkContains('freebsd'),
- versionRegexes: []
- }
- ];
- var PlatformInfo = {
- browsers: constant(browsers),
- oses: constant(oses)
- };
- var detect$2 = function (userAgent, mediaMatch) {
- var browsers = PlatformInfo.browsers();
- var oses = PlatformInfo.oses();
- var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
- var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
- var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
- return {
- browser: browser,
- os: os,
- deviceType: deviceType
- };
- };
- var PlatformDetection = { detect: detect$2 };
- var mediaMatch = function (query) {
- return domGlobals.window.matchMedia(query).matches;
- };
- var platform = Cell(PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch));
- var detect$3 = function () {
- return platform.get();
- };
- var fromHtml = function (html, scope) {
- var doc = scope || domGlobals.document;
- var div = doc.createElement('div');
- div.innerHTML = html;
- if (!div.hasChildNodes() || div.childNodes.length > 1) {
- domGlobals.console.error('HTML does not have a single root node', html);
- throw new Error('HTML must have a single root node');
- }
- return fromDom(div.childNodes[0]);
- };
- var fromTag = function (tag, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createElement(tag);
- return fromDom(node);
- };
- var fromText = function (text, scope) {
- var doc = scope || domGlobals.document;
- var node = doc.createTextNode(text);
- return fromDom(node);
- };
- var fromDom = function (node) {
- if (node === null || node === undefined) {
- throw new Error('Node cannot be null or undefined');
- }
- return { dom: constant(node) };
- };
- var fromPoint = function (docElm, x, y) {
- var doc = docElm.dom();
- return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
- };
- var Element = {
- fromHtml: fromHtml,
- fromTag: fromTag,
- fromText: fromText,
- fromDom: fromDom,
- fromPoint: fromPoint
- };
- var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
- var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
- var COMMENT = domGlobals.Node.COMMENT_NODE;
- var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
- var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
- var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
- var ELEMENT = domGlobals.Node.ELEMENT_NODE;
- var TEXT = domGlobals.Node.TEXT_NODE;
- var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
- var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
- var ENTITY = domGlobals.Node.ENTITY_NODE;
- var NOTATION = domGlobals.Node.NOTATION_NODE;
- var ELEMENT$1 = ELEMENT;
- var is = function (element, selector) {
- var dom = element.dom();
- if (dom.nodeType !== ELEMENT$1) {
- return false;
- } else {
- var elem = dom;
- if (elem.matches !== undefined) {
- return elem.matches(selector);
- } else if (elem.msMatchesSelector !== undefined) {
- return elem.msMatchesSelector(selector);
- } else if (elem.webkitMatchesSelector !== undefined) {
- return elem.webkitMatchesSelector(selector);
- } else if (elem.mozMatchesSelector !== undefined) {
- return elem.mozMatchesSelector(selector);
- } else {
- throw new Error('Browser lacks native selectors');
- }
- }
- };
- var regularContains = function (e1, e2) {
- var d1 = e1.dom();
- var d2 = e2.dom();
- return d1 === d2 ? false : d1.contains(d2);
- };
- var ieContains = function (e1, e2) {
- return Node.documentPositionContainedBy(e1.dom(), e2.dom());
- };
- var browser = detect$3().browser;
- var contains$1 = browser.isIE() ? ieContains : regularContains;
- var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
- var child = function (scope, predicate) {
- var pred = function (node) {
- return predicate(Element.fromDom(node));
- };
- var result = find(scope.dom().childNodes, pred);
- return result.map(Element.fromDom);
- };
- var child$1 = function (scope, selector) {
- return child(scope, function (e) {
- return is(e, selector);
- });
- };
- var count = 0;
- var getFigureImg = function (elem) {
- return child$1(Element.fromDom(elem), 'img');
- };
- var isFigure = function (editor, elem) {
- return editor.dom.is(elem, 'figure');
- };
- var getEditableImage = function (editor, elem) {
- var isImage = function (imgNode) {
- return editor.dom.is(imgNode, 'img:not([data-mce-object],[data-mce-placeholder])');
- };
- var isEditable = function (imgNode) {
- return isImage(imgNode) && (isLocalImage(editor, imgNode) || isCorsImage(editor, imgNode) || editor.settings.imagetools_proxy);
- };
- if (isFigure(editor, elem)) {
- var imgOpt = getFigureImg(elem);
- return imgOpt.map(function (img) {
- return isEditable(img.dom()) ? Option.some(img.dom()) : Option.none();
- });
- }
- return isEditable(elem) ? Option.some(elem) : Option.none();
- };
- var displayError = function (editor, error) {
- editor.notificationManager.open({
- text: error,
- type: 'error'
- });
- };
- var getSelectedImage = function (editor) {
- var elem = editor.selection.getNode();
- if (isFigure(editor, elem)) {
- return getFigureImg(elem);
- } else {
- return Option.some(Element.fromDom(elem));
- }
- };
- var extractFilename = function (editor, url) {
- var m = url.match(/\/([^\/\?]+)?\.(?:jpeg|jpg|png|gif)(?:\?|$)/i);
- if (m) {
- return editor.dom.encode(m[1]);
- }
- return null;
- };
- var createId = function () {
- return 'imagetools' + count++;
- };
- var isLocalImage = function (editor, img) {
- var url = img.src;
- return url.indexOf('data:') === 0 || url.indexOf('blob:') === 0 || new global$4(url).host === editor.documentBaseURI.host;
- };
- var isCorsImage = function (editor, img) {
- return global$1.inArray(getCorsHosts(editor), new global$4(img.src).host) !== -1;
- };
- var isCorsWithCredentialsImage = function (editor, img) {
- return global$1.inArray(getCredentialsHosts(editor), new global$4(img.src).host) !== -1;
- };
- var defaultFetchImage = function (editor, img) {
- var src = img.src, apiKey;
- if (isCorsImage(editor, img)) {
- return getUrl(img.src, null, isCorsWithCredentialsImage(editor, img));
- }
- if (!isLocalImage(editor, img)) {
- src = getProxyUrl(editor);
- src += (src.indexOf('?') === -1 ? '?' : '&') + 'url=' + encodeURIComponent(img.src);
- apiKey = getApiKey(editor);
- return getUrl(src, apiKey, false);
- }
- return imageToBlob$1(img);
- };
- var imageToBlob$2 = function (editor, img) {
- return getFetchImage(editor).fold(function () {
- return defaultFetchImage(editor, img);
- }, function (customFetchImage) {
- return customFetchImage(img);
- });
- };
- var findBlob = function (editor, img) {
- var blobInfo;
- blobInfo = editor.editorUpload.blobCache.getByUri(img.src);
- if (blobInfo) {
- return global$3.resolve(blobInfo.blob());
- }
- return imageToBlob$2(editor, img);
- };
- var startTimedUpload = function (editor, imageUploadTimerState) {
- var imageUploadTimer = global$2.setEditorTimeout(editor, function () {
- editor.editorUpload.uploadImagesAuto();
- }, getUploadTimeout(editor));
- imageUploadTimerState.set(imageUploadTimer);
- };
- var cancelTimedUpload = function (imageUploadTimerState) {
- global$2.clearTimeout(imageUploadTimerState.get());
- };
- var updateSelectedImage = function (editor, ir, uploadImmediately, imageUploadTimerState, selectedImage, size) {
- return ir.toBlob().then(function (blob) {
- var uri, name, blobCache, blobInfo;
- blobCache = editor.editorUpload.blobCache;
- uri = selectedImage.src;
- if (shouldReuseFilename(editor)) {
- blobInfo = blobCache.getByUri(uri);
- if (blobInfo) {
- uri = blobInfo.uri();
- name = blobInfo.name();
- } else {
- name = extractFilename(editor, uri);
- }
- }
- blobInfo = blobCache.create({
- id: createId(),
- blob: blob,
- base64: ir.toBase64(),
- uri: uri,
- name: name
- });
- blobCache.add(blobInfo);
- editor.undoManager.transact(function () {
- function imageLoadedHandler() {
- editor.$(selectedImage).off('load', imageLoadedHandler);
- editor.nodeChanged();
- if (uploadImmediately) {
- editor.editorUpload.uploadImagesAuto();
- } else {
- cancelTimedUpload(imageUploadTimerState);
- startTimedUpload(editor, imageUploadTimerState);
- }
- }
- editor.$(selectedImage).on('load', imageLoadedHandler);
- if (size) {
- editor.$(selectedImage).attr({
- width: size.w,
- height: size.h
- });
- }
- editor.$(selectedImage).attr({ src: blobInfo.blobUri() }).removeAttr('data-mce-src');
- });
- return blobInfo;
- });
- };
- var selectedImageOperation = function (editor, imageUploadTimerState, fn, size) {
- return function () {
- var imgOpt = getSelectedImage(editor);
- return imgOpt.fold(function () {
- displayError(editor, 'Could not find selected image');
- }, function (img) {
- return editor._scanForImages().then(function () {
- return findBlob(editor, img.dom());
- }).then(blobToImageResult).then(fn).then(function (imageResult) {
- return updateSelectedImage(editor, imageResult, false, imageUploadTimerState, img.dom(), size);
- }, function (error) {
- displayError(editor, error);
- });
- });
- };
- };
- var rotate$2 = function (editor, imageUploadTimerState, angle) {
- return function () {
- var imgOpt = getSelectedImage(editor);
- var flippedSize = imgOpt.fold(function () {
- return null;
- }, function (img) {
- var size = ImageSize.getImageSize(img.dom());
- return size ? {
- w: size.h,
- h: size.w
- } : null;
- });
- return selectedImageOperation(editor, imageUploadTimerState, function (imageResult) {
- return rotate$1(imageResult, angle);
- }, flippedSize)();
- };
- };
- var flip$2 = function (editor, imageUploadTimerState, axis) {
- return function () {
- return selectedImageOperation(editor, imageUploadTimerState, function (imageResult) {
- return flip$1(imageResult, axis);
- })();
- };
- };
- var handleDialogBlob = function (editor, imageUploadTimerState, img, originalSize, blob) {
- return new global$3(function (resolve) {
- blobToImage$1(blob).then(function (newImage) {
- var newSize = ImageSize.getNaturalImageSize(newImage);
- if (originalSize.w !== newSize.w || originalSize.h !== newSize.h) {
- if (ImageSize.getImageSize(img)) {
- ImageSize.setImageSize(img, newSize);
- }
- }
- domGlobals.URL.revokeObjectURL(newImage.src);
- return blob;
- }).then(blobToImageResult).then(function (imageResult) {
- return updateSelectedImage(editor, imageResult, true, imageUploadTimerState, img);
- }, function () {
- });
- });
- };
- var Actions = {
- rotate: rotate$2,
- flip: flip$2,
- getEditableImage: getEditableImage,
- cancelTimedUpload: cancelTimedUpload,
- findBlob: findBlob,
- getSelectedImage: getSelectedImage,
- handleDialogBlob: handleDialogBlob
- };
- var saveState = constant('save-state');
- var disable = constant('disable');
- var enable = constant('enable');
- var createState = function (blob) {
- return {
- blob: blob,
- url: domGlobals.URL.createObjectURL(blob)
- };
- };
- var makeOpen = function (editor, imageUploadTimerState) {
- return function () {
- var getLoadedSpec = function (currentState) {
- return {
- title: 'Edit Image',
- size: 'large',
- body: {
- type: 'panel',
- items: [{
- type: 'imagetools',
- name: 'imagetools',
- label: 'Edit Image',
- currentState: currentState
- }]
- },
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true,
- disabled: true
- }
- ],
- onSubmit: function (api) {
- var blob = api.getData().imagetools.blob;
- originalImgOpt.each(function (originalImg) {
- originalSizeOpt.each(function (originalSize) {
- Actions.handleDialogBlob(editor, imageUploadTimerState, originalImg.dom(), originalSize, blob);
- });
- });
- api.close();
- },
- onCancel: function () {
- },
- onAction: function (api, details) {
- switch (details.name) {
- case saveState():
- if (details.value) {
- api.enable('save');
- } else {
- api.disable('save');
- }
- break;
- case disable():
- api.disable('save');
- api.disable('cancel');
- break;
- case enable():
- api.enable('cancel');
- break;
- }
- }
- };
- };
- var originalImgOpt = Actions.getSelectedImage(editor);
- var originalSizeOpt = originalImgOpt.map(function (origImg) {
- return ImageSize.getNaturalImageSize(origImg.dom());
- });
- var imgOpt = Actions.getSelectedImage(editor);
- imgOpt.each(function (img) {
- Actions.getEditableImage(editor, img.dom()).each(function (_) {
- Actions.findBlob(editor, img.dom()).then(function (blob) {
- var state = createState(blob);
- editor.windowManager.open(getLoadedSpec(state));
- });
- });
- });
- };
- };
- var Dialog = { makeOpen: makeOpen };
- var register = function (editor, imageUploadTimerState) {
- global$1.each({
- mceImageRotateLeft: Actions.rotate(editor, imageUploadTimerState, -90),
- mceImageRotateRight: Actions.rotate(editor, imageUploadTimerState, 90),
- mceImageFlipVertical: Actions.flip(editor, imageUploadTimerState, 'v'),
- mceImageFlipHorizontal: Actions.flip(editor, imageUploadTimerState, 'h'),
- mceEditImage: Dialog.makeOpen(editor, imageUploadTimerState)
- }, function (fn, cmd) {
- editor.addCommand(cmd, fn);
- });
- };
- var Commands = { register: register };
- var setup = function (editor, imageUploadTimerState, lastSelectedImageState) {
- editor.on('NodeChange', function (e) {
- var lastSelectedImage = lastSelectedImageState.get();
- if (lastSelectedImage && lastSelectedImage.src !== e.element.src) {
- Actions.cancelTimedUpload(imageUploadTimerState);
- editor.editorUpload.uploadImagesAuto();
- lastSelectedImageState.set(null);
- }
- Actions.getEditableImage(editor, e.element).each(lastSelectedImageState.set);
- });
- };
- var UploadSelectedImage = { setup: setup };
- var register$1 = function (editor) {
- var cmd = function (command) {
- return function () {
- return editor.execCommand(command);
- };
- };
- editor.ui.registry.addButton('rotateleft', {
- tooltip: 'Rotate counterclockwise',
- icon: 'rotate-left',
- onAction: cmd('mceImageRotateLeft')
- });
- editor.ui.registry.addButton('rotateright', {
- tooltip: 'Rotate clockwise',
- icon: 'rotate-right',
- onAction: cmd('mceImageRotateRight')
- });
- editor.ui.registry.addButton('flipv', {
- tooltip: 'Flip vertically',
- icon: 'flip-vertically',
- onAction: cmd('mceImageFlipVertical')
- });
- editor.ui.registry.addButton('fliph', {
- tooltip: 'Flip horizontally',
- icon: 'flip-horizontally',
- onAction: cmd('mceImageFlipHorizontal')
- });
- editor.ui.registry.addButton('editimage', {
- tooltip: 'Edit image',
- icon: 'edit-image',
- onAction: cmd('mceEditImage'),
- onSetup: function (buttonApi) {
- var setDisabled = function () {
- var elementOpt = Actions.getSelectedImage(editor);
- elementOpt.each(function (element) {
- var disabled = Actions.getEditableImage(editor, element.dom()).isNone();
- buttonApi.setDisabled(disabled);
- });
- };
- editor.on('NodeChange', setDisabled);
- return function () {
- editor.off('NodeChange', setDisabled);
- };
- }
- });
- editor.ui.registry.addButton('imageoptions', {
- tooltip: 'Image options',
- icon: 'image-options',
- onAction: cmd('mceImage')
- });
- editor.ui.registry.addContextMenu('imagetools', {
- update: function (element) {
- return Actions.getEditableImage(editor, element).fold(function () {
- return [];
- }, function (_) {
- return [{
- text: 'Edit image',
- icon: 'edit-image',
- onAction: cmd('mceEditImage')
- }];
- });
- }
- });
- };
- var Buttons = { register: register$1 };
- var register$2 = function (editor) {
- editor.ui.registry.addContextToolbar('imagetools', {
- items: getToolbarItems(editor),
- predicate: function (elem) {
- return Actions.getEditableImage(editor, elem).isSome();
- },
- position: 'node',
- scope: 'node'
- });
- };
- var ContextToolbar = { register: register$2 };
- function Plugin () {
- global.add('imagetools', function (editor) {
- var imageUploadTimerState = Cell(0);
- var lastSelectedImageState = Cell(null);
- Commands.register(editor, imageUploadTimerState);
- Buttons.register(editor);
- ContextToolbar.register(editor);
- UploadSelectedImage.setup(editor, imageUploadTimerState, lastSelectedImageState);
- });
- }
- Plugin();
- }(window));
|