123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662 |
- /**
- * 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.3.0 (2020-05-21)
- */
- (function (domGlobals) {
- 'use strict';
- var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
- 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()')
- };
- 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
- };
- var typeOf = function (x) {
- var t = typeof x;
- if (x === null) {
- return 'null';
- } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
- return 'array';
- } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
- return 'string';
- } else {
- return t;
- }
- };
- var isType = function (type) {
- return function (value) {
- return typeOf(value) === type;
- };
- };
- var isSimpleType = function (type) {
- return function (value) {
- return typeof value === type;
- };
- };
- var eq = function (t) {
- return function (a) {
- return t === a;
- };
- };
- var isString = isType('string');
- var isObject = isType('object');
- var isArray = isType('array');
- var isNull = eq(null);
- var isBoolean = isSimpleType('boolean');
- var isNumber = isSimpleType('number');
- var nativePush = Array.prototype.push;
- var flatten = function (xs) {
- var r = [];
- for (var i = 0, len = xs.length; i < len; ++i) {
- if (!isArray(xs[i])) {
- throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
- }
- nativePush.apply(r, xs[i]);
- }
- return r;
- };
- var head = function (xs) {
- return xs.length === 0 ? Option.none() : Option.some(xs[0]);
- };
- var findMap = function (arr, f) {
- for (var i = 0; i < arr.length; i++) {
- var r = f(arr[i], i);
- if (r.isSome()) {
- return r;
- }
- }
- return Option.none();
- };
- var hasOwnProperty = Object.prototype.hasOwnProperty;
- var deep = function (old, nu) {
- var bothObjects = isObject(old) && isObject(nu);
- return bothObjects ? deepMerge(old, nu) : nu;
- };
- var baseMerge = function (merger) {
- return function () {
- var objects = new Array(arguments.length);
- for (var i = 0; i < objects.length; i++) {
- objects[i] = arguments[i];
- }
- if (objects.length === 0) {
- throw new Error('Can\'t merge zero objects');
- }
- var ret = {};
- for (var j = 0; j < objects.length; j++) {
- var curObject = objects[j];
- for (var key in curObject) {
- if (hasOwnProperty.call(curObject, key)) {
- ret[key] = merger(ret[key], curObject[key]);
- }
- }
- }
- return ret;
- };
- };
- var deepMerge = baseMerge(deep);
- var __assign = function () {
- __assign = Object.assign || function __assign(t) {
- for (var s, i = 1, n = arguments.length; i < n; i++) {
- s = arguments[i];
- for (var p in s)
- if (Object.prototype.hasOwnProperty.call(s, p))
- t[p] = s[p];
- }
- return t;
- };
- return __assign.apply(this, arguments);
- };
- var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
- var rawSet = function (dom, key, value) {
- if (isString(value) || isBoolean(value) || isNumber(value)) {
- dom.setAttribute(key, value + '');
- } else {
- domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
- throw new Error('Attribute value was not simple');
- }
- };
- var set = function (element, key, value) {
- rawSet(element.dom(), key, value);
- };
- var remove = function (element, key) {
- element.dom().removeAttribute(key);
- };
- 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 global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
- var global$2 = tinymce.util.Tools.resolve('tinymce.util.Promise');
- var global$3 = tinymce.util.Tools.resolve('tinymce.util.XHR');
- var hasDimensions = function (editor) {
- return editor.getParam('image_dimensions', true, 'boolean');
- };
- var hasAdvTab = function (editor) {
- return editor.getParam('image_advtab', false, 'boolean');
- };
- var hasUploadTab = function (editor) {
- return editor.getParam('image_uploadtab', true, 'boolean');
- };
- var getPrependUrl = function (editor) {
- return editor.getParam('image_prepend_url', '', 'string');
- };
- var getClassList = function (editor) {
- return editor.getParam('image_class_list');
- };
- var hasDescription = function (editor) {
- return editor.getParam('image_description', true, 'boolean');
- };
- var hasImageTitle = function (editor) {
- return editor.getParam('image_title', false, 'boolean');
- };
- var hasImageCaption = function (editor) {
- return editor.getParam('image_caption', false, 'boolean');
- };
- var getImageList = function (editor) {
- return editor.getParam('image_list', false);
- };
- var hasUploadUrl = function (editor) {
- return !!getUploadUrl(editor);
- };
- var hasUploadHandler = function (editor) {
- return !!getUploadHandler(editor);
- };
- var getUploadUrl = function (editor) {
- return editor.getParam('images_upload_url', '', 'string');
- };
- var getUploadHandler = function (editor) {
- return editor.getParam('images_upload_handler', undefined, 'function');
- };
- var getUploadBasePath = function (editor) {
- return editor.getParam('images_upload_base_path', undefined, 'string');
- };
- var getUploadCredentials = function (editor) {
- return editor.getParam('images_upload_credentials', false, 'boolean');
- };
- var showAccessibilityOptions = function (editor) {
- return editor.getParam('a11y_advanced_options', false, 'boolean');
- };
- var isAutomaticUploadsEnabled = function (editor) {
- return editor.getParam('automatic_uploads', true, 'boolean');
- };
- var parseIntAndGetMax = function (val1, val2) {
- return Math.max(parseInt(val1, 10), parseInt(val2, 10));
- };
- var getImageSize = function (url) {
- return new global$2(function (callback) {
- var img = domGlobals.document.createElement('img');
- var done = function (dimensions) {
- if (img.parentNode) {
- img.parentNode.removeChild(img);
- }
- callback(dimensions);
- };
- img.onload = function () {
- var width = parseIntAndGetMax(img.width, img.clientWidth);
- var height = parseIntAndGetMax(img.height, img.clientHeight);
- var dimensions = {
- width: width,
- height: height
- };
- done(global$2.resolve(dimensions));
- };
- img.onerror = function () {
- done(global$2.reject('Failed to get image dimensions for: ' + url));
- };
- var style = img.style;
- style.visibility = 'hidden';
- style.position = 'fixed';
- style.bottom = style.left = '0px';
- style.width = style.height = 'auto';
- domGlobals.document.body.appendChild(img);
- img.src = url;
- });
- };
- var removePixelSuffix = function (value) {
- if (value) {
- value = value.replace(/px$/, '');
- }
- return value;
- };
- var addPixelSuffix = function (value) {
- if (value.length > 0 && /^[0-9]+$/.test(value)) {
- value += 'px';
- }
- return value;
- };
- var mergeMargins = function (css) {
- if (css.margin) {
- var splitMargin = String(css.margin).split(' ');
- switch (splitMargin.length) {
- case 1:
- css['margin-top'] = css['margin-top'] || splitMargin[0];
- css['margin-right'] = css['margin-right'] || splitMargin[0];
- css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
- css['margin-left'] = css['margin-left'] || splitMargin[0];
- break;
- case 2:
- css['margin-top'] = css['margin-top'] || splitMargin[0];
- css['margin-right'] = css['margin-right'] || splitMargin[1];
- css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
- css['margin-left'] = css['margin-left'] || splitMargin[1];
- break;
- case 3:
- css['margin-top'] = css['margin-top'] || splitMargin[0];
- css['margin-right'] = css['margin-right'] || splitMargin[1];
- css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
- css['margin-left'] = css['margin-left'] || splitMargin[1];
- break;
- case 4:
- css['margin-top'] = css['margin-top'] || splitMargin[0];
- css['margin-right'] = css['margin-right'] || splitMargin[1];
- css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
- css['margin-left'] = css['margin-left'] || splitMargin[3];
- }
- delete css.margin;
- }
- return css;
- };
- var createImageList = function (editor, callback) {
- var imageList = getImageList(editor);
- if (typeof imageList === 'string') {
- global$3.send({
- url: imageList,
- success: function (text) {
- callback(JSON.parse(text));
- }
- });
- } else if (typeof imageList === 'function') {
- imageList(callback);
- } else {
- callback(imageList);
- }
- };
- var waitLoadImage = function (editor, data, imgElm) {
- var selectImage = function () {
- imgElm.onload = imgElm.onerror = null;
- if (editor.selection) {
- editor.selection.select(imgElm);
- editor.nodeChanged();
- }
- };
- imgElm.onload = function () {
- if (!data.width && !data.height && hasDimensions(editor)) {
- editor.dom.setAttribs(imgElm, {
- width: String(imgElm.clientWidth),
- height: String(imgElm.clientHeight)
- });
- }
- selectImage();
- };
- imgElm.onerror = selectImage;
- };
- var blobToDataUri = function (blob) {
- return new global$2(function (resolve, reject) {
- var reader = new domGlobals.FileReader();
- reader.onload = function () {
- resolve(reader.result);
- };
- reader.onerror = function () {
- reject(reader.error.message);
- };
- reader.readAsDataURL(blob);
- });
- };
- var isPlaceholderImage = function (imgElm) {
- return imgElm.nodeName === 'IMG' && (imgElm.hasAttribute('data-mce-object') || imgElm.hasAttribute('data-mce-placeholder'));
- };
- var DOM = global$1.DOM;
- var getHspace = function (image) {
- if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {
- return removePixelSuffix(image.style.marginLeft);
- } else {
- return '';
- }
- };
- var getVspace = function (image) {
- if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {
- return removePixelSuffix(image.style.marginTop);
- } else {
- return '';
- }
- };
- var getBorder = function (image) {
- if (image.style.borderWidth) {
- return removePixelSuffix(image.style.borderWidth);
- } else {
- return '';
- }
- };
- var getAttrib = function (image, name) {
- if (image.hasAttribute(name)) {
- return image.getAttribute(name);
- } else {
- return '';
- }
- };
- var getStyle = function (image, name) {
- return image.style[name] ? image.style[name] : '';
- };
- var hasCaption = function (image) {
- return image.parentNode !== null && image.parentNode.nodeName === 'FIGURE';
- };
- var updateAttrib = function (image, name, value) {
- if (value === '') {
- image.removeAttribute(name);
- } else {
- image.setAttribute(name, value);
- }
- };
- var wrapInFigure = function (image) {
- var figureElm = DOM.create('figure', { class: 'image' });
- DOM.insertAfter(figureElm, image);
- figureElm.appendChild(image);
- figureElm.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
- figureElm.contentEditable = 'false';
- };
- var removeFigure = function (image) {
- var figureElm = image.parentNode;
- DOM.insertAfter(image, figureElm);
- DOM.remove(figureElm);
- };
- var toggleCaption = function (image) {
- if (hasCaption(image)) {
- removeFigure(image);
- } else {
- wrapInFigure(image);
- }
- };
- var normalizeStyle = function (image, normalizeCss) {
- var attrValue = image.getAttribute('style');
- var value = normalizeCss(attrValue !== null ? attrValue : '');
- if (value.length > 0) {
- image.setAttribute('style', value);
- image.setAttribute('data-mce-style', value);
- } else {
- image.removeAttribute('style');
- }
- };
- var setSize = function (name, normalizeCss) {
- return function (image, name, value) {
- if (image.style[name]) {
- image.style[name] = addPixelSuffix(value);
- normalizeStyle(image, normalizeCss);
- } else {
- updateAttrib(image, name, value);
- }
- };
- };
- var getSize = function (image, name) {
- if (image.style[name]) {
- return removePixelSuffix(image.style[name]);
- } else {
- return getAttrib(image, name);
- }
- };
- var setHspace = function (image, value) {
- var pxValue = addPixelSuffix(value);
- image.style.marginLeft = pxValue;
- image.style.marginRight = pxValue;
- };
- var setVspace = function (image, value) {
- var pxValue = addPixelSuffix(value);
- image.style.marginTop = pxValue;
- image.style.marginBottom = pxValue;
- };
- var setBorder = function (image, value) {
- var pxValue = addPixelSuffix(value);
- image.style.borderWidth = pxValue;
- };
- var setBorderStyle = function (image, value) {
- image.style.borderStyle = value;
- };
- var getBorderStyle = function (image) {
- return getStyle(image, 'borderStyle');
- };
- var isFigure = function (elm) {
- return elm.nodeName === 'FIGURE';
- };
- var isImage = function (elm) {
- return elm.nodeName === 'IMG';
- };
- var getIsDecorative = function (image) {
- return DOM.getAttrib(image, 'alt').length === 0 && DOM.getAttrib(image, 'role') === 'presentation';
- };
- var getAlt = function (image) {
- if (getIsDecorative(image)) {
- return '';
- } else {
- return getAttrib(image, 'alt');
- }
- };
- var defaultData = function () {
- return {
- src: '',
- alt: '',
- title: '',
- width: '',
- height: '',
- class: '',
- style: '',
- caption: false,
- hspace: '',
- vspace: '',
- border: '',
- borderStyle: '',
- isDecorative: false
- };
- };
- var getStyleValue = function (normalizeCss, data) {
- var image = domGlobals.document.createElement('img');
- updateAttrib(image, 'style', data.style);
- if (getHspace(image) || data.hspace !== '') {
- setHspace(image, data.hspace);
- }
- if (getVspace(image) || data.vspace !== '') {
- setVspace(image, data.vspace);
- }
- if (getBorder(image) || data.border !== '') {
- setBorder(image, data.border);
- }
- if (getBorderStyle(image) || data.borderStyle !== '') {
- setBorderStyle(image, data.borderStyle);
- }
- return normalizeCss(image.getAttribute('style'));
- };
- var create = function (normalizeCss, data) {
- var image = domGlobals.document.createElement('img');
- write(normalizeCss, __assign(__assign({}, data), { caption: false }), image);
- setAlt(image, data.alt, data.isDecorative);
- if (data.caption) {
- var figure = DOM.create('figure', { class: 'image' });
- figure.appendChild(image);
- figure.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
- figure.contentEditable = 'false';
- return figure;
- } else {
- return image;
- }
- };
- var read = function (normalizeCss, image) {
- return {
- src: getAttrib(image, 'src'),
- alt: getAlt(image),
- title: getAttrib(image, 'title'),
- width: getSize(image, 'width'),
- height: getSize(image, 'height'),
- class: getAttrib(image, 'class'),
- style: normalizeCss(getAttrib(image, 'style')),
- caption: hasCaption(image),
- hspace: getHspace(image),
- vspace: getVspace(image),
- border: getBorder(image),
- borderStyle: getStyle(image, 'borderStyle'),
- isDecorative: getIsDecorative(image)
- };
- };
- var updateProp = function (image, oldData, newData, name, set) {
- if (newData[name] !== oldData[name]) {
- set(image, name, newData[name]);
- }
- };
- var setAlt = function (image, alt, isDecorative) {
- if (isDecorative) {
- DOM.setAttrib(image, 'role', 'presentation');
- var sugarImage = Element.fromDom(image);
- set(sugarImage, 'alt', '');
- } else {
- if (isNull(alt)) {
- var sugarImage = Element.fromDom(image);
- remove(sugarImage, 'alt');
- } else {
- var sugarImage = Element.fromDom(image);
- set(sugarImage, 'alt', alt);
- }
- if (DOM.getAttrib(image, 'role') === 'presentation') {
- DOM.setAttrib(image, 'role', '');
- }
- }
- };
- var updateAlt = function (image, oldData, newData) {
- if (newData.alt !== oldData.alt || newData.isDecorative !== oldData.isDecorative) {
- setAlt(image, newData.alt, newData.isDecorative);
- }
- };
- var normalized = function (set, normalizeCss) {
- return function (image, name, value) {
- set(image, value);
- normalizeStyle(image, normalizeCss);
- };
- };
- var write = function (normalizeCss, newData, image) {
- var oldData = read(normalizeCss, image);
- updateProp(image, oldData, newData, 'caption', function (image, _name, _value) {
- return toggleCaption(image);
- });
- updateProp(image, oldData, newData, 'src', updateAttrib);
- updateProp(image, oldData, newData, 'title', updateAttrib);
- updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));
- updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));
- updateProp(image, oldData, newData, 'class', updateAttrib);
- updateProp(image, oldData, newData, 'style', normalized(function (image, value) {
- return updateAttrib(image, 'style', value);
- }, normalizeCss));
- updateProp(image, oldData, newData, 'hspace', normalized(setHspace, normalizeCss));
- updateProp(image, oldData, newData, 'vspace', normalized(setVspace, normalizeCss));
- updateProp(image, oldData, newData, 'border', normalized(setBorder, normalizeCss));
- updateProp(image, oldData, newData, 'borderStyle', normalized(setBorderStyle, normalizeCss));
- updateAlt(image, oldData, newData);
- };
- var normalizeCss = function (editor, cssText) {
- var css = editor.dom.styles.parse(cssText);
- var mergedCss = mergeMargins(css);
- var compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));
- return editor.dom.styles.serialize(compressed);
- };
- var getSelectedImage = function (editor) {
- var imgElm = editor.selection.getNode();
- var figureElm = editor.dom.getParent(imgElm, 'figure.image');
- if (figureElm) {
- return editor.dom.select('img', figureElm)[0];
- }
- if (imgElm && (imgElm.nodeName !== 'IMG' || isPlaceholderImage(imgElm))) {
- return null;
- }
- return imgElm;
- };
- var splitTextBlock = function (editor, figure) {
- var dom = editor.dom;
- var textBlock = dom.getParent(figure.parentNode, function (node) {
- return !!editor.schema.getTextBlockElements()[node.nodeName];
- }, editor.getBody());
- if (textBlock) {
- return dom.split(textBlock, figure);
- } else {
- return figure;
- }
- };
- var readImageDataFromSelection = function (editor) {
- var image = getSelectedImage(editor);
- return image ? read(function (css) {
- return normalizeCss(editor, css);
- }, image) : defaultData();
- };
- var insertImageAtCaret = function (editor, data) {
- var elm = create(function (css) {
- return normalizeCss(editor, css);
- }, data);
- editor.dom.setAttrib(elm, 'data-mce-id', '__mcenew');
- editor.focus();
- editor.selection.setContent(elm.outerHTML);
- var insertedElm = editor.dom.select('*[data-mce-id="__mcenew"]')[0];
- editor.dom.setAttrib(insertedElm, 'data-mce-id', null);
- if (isFigure(insertedElm)) {
- var figure = splitTextBlock(editor, insertedElm);
- editor.selection.select(figure);
- } else {
- editor.selection.select(insertedElm);
- }
- };
- var syncSrcAttr = function (editor, image) {
- editor.dom.setAttrib(image, 'src', image.getAttribute('src'));
- };
- var deleteImage = function (editor, image) {
- if (image) {
- var elm = editor.dom.is(image.parentNode, 'figure.image') ? image.parentNode : image;
- editor.dom.remove(elm);
- editor.focus();
- editor.nodeChanged();
- if (editor.dom.isEmpty(editor.getBody())) {
- editor.setContent('');
- editor.selection.setCursorLocation();
- }
- }
- };
- var writeImageDataToSelection = function (editor, data) {
- var image = getSelectedImage(editor);
- write(function (css) {
- return normalizeCss(editor, css);
- }, data, image);
- syncSrcAttr(editor, image);
- if (isFigure(image.parentNode)) {
- var figure = image.parentNode;
- splitTextBlock(editor, figure);
- editor.selection.select(image.parentNode);
- } else {
- editor.selection.select(image);
- waitLoadImage(editor, data, image);
- }
- };
- var insertOrUpdateImage = function (editor, partialData) {
- var image = getSelectedImage(editor);
- if (image) {
- var selectedImageData = read(function (css) {
- return normalizeCss(editor, css);
- }, image);
- var data = __assign(__assign({}, selectedImageData), partialData);
- if (data.src) {
- writeImageDataToSelection(editor, data);
- } else {
- deleteImage(editor, image);
- }
- } else if (partialData.src) {
- insertImageAtCaret(editor, __assign(__assign({}, defaultData()), partialData));
- }
- };
- var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');
- var getValue = function (item) {
- return isString(item.value) ? item.value : '';
- };
- var sanitizeList = function (list, extractValue) {
- var out = [];
- global$4.each(list, function (item) {
- var text = isString(item.text) ? item.text : isString(item.title) ? item.title : '';
- if (item.menu !== undefined) {
- var items = sanitizeList(item.menu, extractValue);
- out.push({
- text: text,
- items: items
- });
- } else {
- var value = extractValue(item);
- out.push({
- text: text,
- value: value
- });
- }
- });
- return out;
- };
- var sanitizer = function (extracter) {
- if (extracter === void 0) {
- extracter = getValue;
- }
- return function (list) {
- if (list) {
- return Option.from(list).map(function (list) {
- return sanitizeList(list, extracter);
- });
- } else {
- return Option.none();
- }
- };
- };
- var sanitize = function (list) {
- return sanitizer(getValue)(list);
- };
- var isGroup = function (item) {
- return Object.prototype.hasOwnProperty.call(item, 'items');
- };
- var findEntryDelegate = function (list, value) {
- return findMap(list, function (item) {
- if (isGroup(item)) {
- return findEntryDelegate(item.items, value);
- } else if (item.value === value) {
- return Option.some(item);
- } else {
- return Option.none();
- }
- });
- };
- var findEntry = function (optList, value) {
- return optList.bind(function (list) {
- return findEntryDelegate(list, value);
- });
- };
- var ListUtils = {
- sanitizer: sanitizer,
- sanitize: sanitize,
- findEntry: findEntry
- };
- var pathJoin = function (path1, path2) {
- if (path1) {
- return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
- }
- return path2;
- };
- function Uploader (settings) {
- var defaultHandler = function (blobInfo, success, failure, progress) {
- var xhr, formData;
- xhr = new domGlobals.XMLHttpRequest();
- xhr.open('POST', settings.url);
- xhr.withCredentials = settings.credentials;
- xhr.upload.onprogress = function (e) {
- progress(e.loaded / e.total * 100);
- };
- xhr.onerror = function () {
- failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
- };
- xhr.onload = function () {
- var json;
- if (xhr.status < 200 || xhr.status >= 300) {
- failure('HTTP Error: ' + xhr.status);
- return;
- }
- json = JSON.parse(xhr.responseText);
- if (!json || typeof json.location !== 'string') {
- failure('Invalid JSON: ' + xhr.responseText);
- return;
- }
- success(pathJoin(settings.basePath, json.location));
- };
- formData = new domGlobals.FormData();
- formData.append('file', blobInfo.blob(), blobInfo.filename());
- xhr.send(formData);
- };
- var uploadBlob = function (blobInfo, handler) {
- return new global$2(function (resolve, reject) {
- try {
- handler(blobInfo, resolve, reject, noop);
- } catch (ex) {
- reject(ex.message);
- }
- });
- };
- var isDefaultHandler = function (handler) {
- return handler === defaultHandler;
- };
- var upload = function (blobInfo) {
- return !settings.url && isDefaultHandler(settings.handler) ? global$2.reject('Upload url missing from the settings.') : uploadBlob(blobInfo, settings.handler);
- };
- settings = global$4.extend({
- credentials: false,
- handler: defaultHandler
- }, settings);
- return { upload: upload };
- }
- var makeTab = function (_info) {
- return {
- title: 'Advanced',
- name: 'advanced',
- items: [
- {
- type: 'input',
- label: 'Style',
- name: 'style'
- },
- {
- type: 'grid',
- columns: 2,
- items: [
- {
- type: 'input',
- label: 'Vertical space',
- name: 'vspace',
- inputMode: 'numeric'
- },
- {
- type: 'input',
- label: 'Horizontal space',
- name: 'hspace',
- inputMode: 'numeric'
- },
- {
- type: 'input',
- label: 'Border width',
- name: 'border',
- inputMode: 'numeric'
- },
- {
- type: 'selectbox',
- name: 'borderstyle',
- label: 'Border style',
- items: [
- {
- text: 'Select...',
- value: ''
- },
- {
- text: 'Solid',
- value: 'solid'
- },
- {
- text: 'Dotted',
- value: 'dotted'
- },
- {
- text: 'Dashed',
- value: 'dashed'
- },
- {
- text: 'Double',
- value: 'double'
- },
- {
- text: 'Groove',
- value: 'groove'
- },
- {
- text: 'Ridge',
- value: 'ridge'
- },
- {
- text: 'Inset',
- value: 'inset'
- },
- {
- text: 'Outset',
- value: 'outset'
- },
- {
- text: 'None',
- value: 'none'
- },
- {
- text: 'Hidden',
- value: 'hidden'
- }
- ]
- }
- ]
- }
- ]
- };
- };
- var AdvTab = { makeTab: makeTab };
- var collect = function (editor) {
- var urlListSanitizer = ListUtils.sanitizer(function (item) {
- return editor.convertURL(item.value || item.url, 'src');
- });
- var futureImageList = new global$2(function (completer) {
- createImageList(editor, function (imageList) {
- completer(urlListSanitizer(imageList).map(function (items) {
- return flatten([
- [{
- text: 'None',
- value: ''
- }],
- items
- ]);
- }));
- });
- });
- var classList = ListUtils.sanitize(getClassList(editor));
- var hasAdvTab$1 = hasAdvTab(editor);
- var hasUploadTab$1 = hasUploadTab(editor);
- var hasUploadUrl$1 = hasUploadUrl(editor);
- var hasUploadHandler$1 = hasUploadHandler(editor);
- var image = readImageDataFromSelection(editor);
- var hasDescription$1 = hasDescription(editor);
- var hasImageTitle$1 = hasImageTitle(editor);
- var hasDimensions$1 = hasDimensions(editor);
- var hasImageCaption$1 = hasImageCaption(editor);
- var hasAccessibilityOptions = showAccessibilityOptions(editor);
- var url = getUploadUrl(editor);
- var basePath = getUploadBasePath(editor);
- var credentials = getUploadCredentials(editor);
- var handler = getUploadHandler(editor);
- var automaticUploads = isAutomaticUploadsEnabled(editor);
- var prependURL = Option.some(getPrependUrl(editor)).filter(function (preUrl) {
- return isString(preUrl) && preUrl.length > 0;
- });
- return futureImageList.then(function (imageList) {
- return {
- image: image,
- imageList: imageList,
- classList: classList,
- hasAdvTab: hasAdvTab$1,
- hasUploadTab: hasUploadTab$1,
- hasUploadUrl: hasUploadUrl$1,
- hasUploadHandler: hasUploadHandler$1,
- hasDescription: hasDescription$1,
- hasImageTitle: hasImageTitle$1,
- hasDimensions: hasDimensions$1,
- hasImageCaption: hasImageCaption$1,
- url: url,
- basePath: basePath,
- credentials: credentials,
- handler: handler,
- prependURL: prependURL,
- hasAccessibilityOptions: hasAccessibilityOptions,
- automaticUploads: automaticUploads
- };
- });
- };
- var makeItems = function (info) {
- var imageUrl = {
- name: 'src',
- type: 'urlinput',
- filetype: 'image',
- label: 'Source'
- };
- var imageList = info.imageList.map(function (items) {
- return {
- name: 'images',
- type: 'selectbox',
- label: 'Image list',
- items: items
- };
- });
- var imageDescription = {
- name: 'alt',
- type: 'input',
- label: 'Alternative description',
- disabled: info.hasAccessibilityOptions && info.image.isDecorative
- };
- var imageTitle = {
- name: 'title',
- type: 'input',
- label: 'Image title'
- };
- var imageDimensions = {
- name: 'dimensions',
- type: 'sizeinput'
- };
- var isDecorative = {
- type: 'label',
- label: 'Accessibility',
- items: [{
- name: 'isDecorative',
- type: 'checkbox',
- label: 'Image is decorative'
- }]
- };
- var classList = info.classList.map(function (items) {
- return {
- name: 'classes',
- type: 'selectbox',
- label: 'Class',
- items: items
- };
- });
- var caption = {
- type: 'label',
- label: 'Caption',
- items: [{
- type: 'checkbox',
- name: 'caption',
- label: 'Show caption'
- }]
- };
- return flatten([
- [imageUrl],
- imageList.toArray(),
- info.hasAccessibilityOptions && info.hasDescription ? [isDecorative] : [],
- info.hasDescription ? [imageDescription] : [],
- info.hasImageTitle ? [imageTitle] : [],
- info.hasDimensions ? [imageDimensions] : [],
- [{
- type: 'grid',
- columns: 2,
- items: flatten([
- classList.toArray(),
- info.hasImageCaption ? [caption] : []
- ])
- }]
- ]);
- };
- var makeTab$1 = function (info) {
- return {
- title: 'General',
- name: 'general',
- items: makeItems(info)
- };
- };
- var MainTab = {
- makeTab: makeTab$1,
- makeItems: makeItems
- };
- var makeTab$2 = function (_info) {
- var items = [{
- type: 'dropzone',
- name: 'fileinput'
- }];
- return {
- title: 'Upload',
- name: 'upload',
- items: items
- };
- };
- var UploadTab = { makeTab: makeTab$2 };
- var createState = function (info) {
- return {
- prevImage: ListUtils.findEntry(info.imageList, info.image.src),
- prevAlt: info.image.alt,
- open: true
- };
- };
- var fromImageData = function (image) {
- return {
- src: {
- value: image.src,
- meta: {}
- },
- images: image.src,
- alt: image.alt,
- title: image.title,
- dimensions: {
- width: image.width,
- height: image.height
- },
- classes: image.class,
- caption: image.caption,
- style: image.style,
- vspace: image.vspace,
- border: image.border,
- hspace: image.hspace,
- borderstyle: image.borderStyle,
- fileinput: [],
- isDecorative: image.isDecorative
- };
- };
- var toImageData = function (data, removeEmptyAlt) {
- return {
- src: data.src.value,
- alt: data.alt.length === 0 && removeEmptyAlt ? null : data.alt,
- title: data.title,
- width: data.dimensions.width,
- height: data.dimensions.height,
- class: data.classes,
- style: data.style,
- caption: data.caption,
- hspace: data.hspace,
- vspace: data.vspace,
- border: data.border,
- borderStyle: data.borderstyle,
- isDecorative: data.isDecorative
- };
- };
- var addPrependUrl2 = function (info, srcURL) {
- if (!/^(?:[a-zA-Z]+:)?\/\//.test(srcURL)) {
- return info.prependURL.bind(function (prependUrl) {
- if (srcURL.substring(0, prependUrl.length) !== prependUrl) {
- return Option.some(prependUrl + srcURL);
- }
- return Option.none();
- });
- }
- return Option.none();
- };
- var addPrependUrl = function (info, api) {
- var data = api.getData();
- addPrependUrl2(info, data.src.value).each(function (srcURL) {
- api.setData({
- src: {
- value: srcURL,
- meta: data.src.meta
- }
- });
- });
- };
- var formFillFromMeta2 = function (info, data, meta) {
- if (info.hasDescription && isString(meta.alt)) {
- data.alt = meta.alt;
- }
- if (info.hasAccessibilityOptions) {
- data.isDecorative = meta.isDecorative || data.isDecorative || false;
- }
- if (info.hasImageTitle && isString(meta.title)) {
- data.title = meta.title;
- }
- if (info.hasDimensions) {
- if (isString(meta.width)) {
- data.dimensions.width = meta.width;
- }
- if (isString(meta.height)) {
- data.dimensions.height = meta.height;
- }
- }
- if (isString(meta.class)) {
- ListUtils.findEntry(info.classList, meta.class).each(function (entry) {
- data.classes = entry.value;
- });
- }
- if (info.hasImageCaption) {
- if (isBoolean(meta.caption)) {
- data.caption = meta.caption;
- }
- }
- if (info.hasAdvTab) {
- if (isString(meta.style)) {
- data.style = meta.style;
- }
- if (isString(meta.vspace)) {
- data.vspace = meta.vspace;
- }
- if (isString(meta.border)) {
- data.border = meta.border;
- }
- if (isString(meta.hspace)) {
- data.hspace = meta.hspace;
- }
- if (isString(meta.borderstyle)) {
- data.borderstyle = meta.borderstyle;
- }
- }
- };
- var formFillFromMeta = function (info, api) {
- var data = api.getData();
- var meta = data.src.meta;
- if (meta !== undefined) {
- var newData = deepMerge({}, data);
- formFillFromMeta2(info, newData, meta);
- api.setData(newData);
- }
- };
- var calculateImageSize = function (helpers, info, state, api) {
- var data = api.getData();
- var url = data.src.value;
- var meta = data.src.meta || {};
- if (!meta.width && !meta.height && info.hasDimensions) {
- helpers.imageSize(url).then(function (size) {
- if (state.open) {
- api.setData({ dimensions: size });
- }
- });
- }
- };
- var updateImagesDropdown = function (info, state, api) {
- var data = api.getData();
- var image = ListUtils.findEntry(info.imageList, data.src.value);
- state.prevImage = image;
- api.setData({
- images: image.map(function (entry) {
- return entry.value;
- }).getOr('')
- });
- };
- var changeSrc = function (helpers, info, state, api) {
- addPrependUrl(info, api);
- formFillFromMeta(info, api);
- calculateImageSize(helpers, info, state, api);
- updateImagesDropdown(info, state, api);
- };
- var changeImages = function (helpers, info, state, api) {
- var data = api.getData();
- var image = ListUtils.findEntry(info.imageList, data.images);
- image.each(function (img) {
- var updateAlt = data.alt === '' || state.prevImage.map(function (image) {
- return image.text === data.alt;
- }).getOr(false);
- if (updateAlt) {
- if (img.value === '') {
- api.setData({
- src: img,
- alt: state.prevAlt
- });
- } else {
- api.setData({
- src: img,
- alt: img.text
- });
- }
- } else {
- api.setData({ src: img });
- }
- });
- state.prevImage = image;
- changeSrc(helpers, info, state, api);
- };
- var calcVSpace = function (css) {
- var matchingTopBottom = css['margin-top'] && css['margin-bottom'] && css['margin-top'] === css['margin-bottom'];
- return matchingTopBottom ? removePixelSuffix(String(css['margin-top'])) : '';
- };
- var calcHSpace = function (css) {
- var matchingLeftRight = css['margin-right'] && css['margin-left'] && css['margin-right'] === css['margin-left'];
- return matchingLeftRight ? removePixelSuffix(String(css['margin-right'])) : '';
- };
- var calcBorderWidth = function (css) {
- return css['border-width'] ? removePixelSuffix(String(css['border-width'])) : '';
- };
- var calcBorderStyle = function (css) {
- return css['border-style'] ? String(css['border-style']) : '';
- };
- var calcStyle = function (parseStyle, serializeStyle, css) {
- return serializeStyle(parseStyle(serializeStyle(css)));
- };
- var changeStyle2 = function (parseStyle, serializeStyle, data) {
- var css = mergeMargins(parseStyle(data.style));
- var dataCopy = deepMerge({}, data);
- dataCopy.vspace = calcVSpace(css);
- dataCopy.hspace = calcHSpace(css);
- dataCopy.border = calcBorderWidth(css);
- dataCopy.borderstyle = calcBorderStyle(css);
- dataCopy.style = calcStyle(parseStyle, serializeStyle, css);
- return dataCopy;
- };
- var changeStyle = function (helpers, api) {
- var data = api.getData();
- var newData = changeStyle2(helpers.parseStyle, helpers.serializeStyle, data);
- api.setData(newData);
- };
- var changeAStyle = function (helpers, info, api) {
- var data = deepMerge(fromImageData(info.image), api.getData());
- var style = getStyleValue(helpers.normalizeCss, toImageData(data, false));
- api.setData({ style: style });
- };
- var changeFileInput = function (helpers, info, state, api) {
- var data = api.getData();
- api.block('Uploading image');
- head(data.fileinput).fold(function () {
- api.unblock();
- }, function (file) {
- var blobUri = domGlobals.URL.createObjectURL(file);
- var uploader = Uploader({
- url: info.url,
- basePath: info.basePath,
- credentials: info.credentials,
- handler: info.handler
- });
- var finalize = function () {
- api.unblock();
- domGlobals.URL.revokeObjectURL(blobUri);
- };
- var updateSrcAndSwitchTab = function (url) {
- api.setData({
- src: {
- value: url,
- meta: {}
- }
- });
- api.showTab('general');
- changeSrc(helpers, info, state, api);
- };
- blobToDataUri(file).then(function (dataUrl) {
- var blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
- if (info.automaticUploads) {
- uploader.upload(blobInfo).then(function (url) {
- updateSrcAndSwitchTab(url);
- finalize();
- }).catch(function (err) {
- finalize();
- helpers.alertErr(api, err);
- });
- } else {
- helpers.addToBlobCache(blobInfo);
- updateSrcAndSwitchTab(blobInfo.blobUri());
- api.unblock();
- }
- });
- });
- };
- var changeHandler = function (helpers, info, state) {
- return function (api, evt) {
- if (evt.name === 'src') {
- changeSrc(helpers, info, state, api);
- } else if (evt.name === 'images') {
- changeImages(helpers, info, state, api);
- } else if (evt.name === 'alt') {
- state.prevAlt = api.getData().alt;
- } else if (evt.name === 'style') {
- changeStyle(helpers, api);
- } else if (evt.name === 'vspace' || evt.name === 'hspace' || evt.name === 'border' || evt.name === 'borderstyle') {
- changeAStyle(helpers, info, api);
- } else if (evt.name === 'fileinput') {
- changeFileInput(helpers, info, state, api);
- } else if (evt.name === 'isDecorative') {
- if (api.getData().isDecorative) {
- api.disable('alt');
- } else {
- api.enable('alt');
- }
- }
- };
- };
- var closeHandler = function (state) {
- return function () {
- state.open = false;
- };
- };
- var makeDialogBody = function (info) {
- if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) {
- var tabPanel = {
- type: 'tabpanel',
- tabs: flatten([
- [MainTab.makeTab(info)],
- info.hasAdvTab ? [AdvTab.makeTab(info)] : [],
- info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info)] : []
- ])
- };
- return tabPanel;
- } else {
- var panel = {
- type: 'panel',
- items: MainTab.makeItems(info)
- };
- return panel;
- }
- };
- var makeDialog = function (helpers) {
- return function (info) {
- var state = createState(info);
- return {
- title: 'Insert/Edit Image',
- size: 'normal',
- body: makeDialogBody(info),
- buttons: [
- {
- type: 'cancel',
- name: 'cancel',
- text: 'Cancel'
- },
- {
- type: 'submit',
- name: 'save',
- text: 'Save',
- primary: true
- }
- ],
- initialData: fromImageData(info.image),
- onSubmit: helpers.onSubmit(info),
- onChange: changeHandler(helpers, info, state),
- onClose: closeHandler(state)
- };
- };
- };
- var submitHandler = function (editor) {
- return function (info) {
- return function (api) {
- var data = deepMerge(fromImageData(info.image), api.getData());
- editor.execCommand('mceUpdateImage', false, toImageData(data, info.hasAccessibilityOptions));
- editor.editorUpload.uploadImagesAuto();
- api.close();
- };
- };
- };
- var imageSize = function (editor) {
- return function (url) {
- return getImageSize(editor.documentBaseURI.toAbsolute(url)).then(function (dimensions) {
- return {
- width: String(dimensions.width),
- height: String(dimensions.height)
- };
- });
- };
- };
- var createBlobCache = function (editor) {
- return function (file, blobUri, dataUrl) {
- return editor.editorUpload.blobCache.create({
- blob: file,
- blobUri: blobUri,
- name: file.name ? file.name.replace(/\.[^\.]+$/, '') : null,
- base64: dataUrl.split(',')[1]
- });
- };
- };
- var addToBlobCache = function (editor) {
- return function (blobInfo) {
- editor.editorUpload.blobCache.add(blobInfo);
- };
- };
- var alertErr = function (editor) {
- return function (api, message) {
- editor.windowManager.alert(message, api.close);
- };
- };
- var normalizeCss$1 = function (editor) {
- return function (cssText) {
- return normalizeCss(editor, cssText);
- };
- };
- var parseStyle = function (editor) {
- return function (cssText) {
- return editor.dom.parseStyle(cssText);
- };
- };
- var serializeStyle = function (editor) {
- return function (stylesArg, name) {
- return editor.dom.serializeStyle(stylesArg, name);
- };
- };
- var Dialog = function (editor) {
- var helpers = {
- onSubmit: submitHandler(editor),
- imageSize: imageSize(editor),
- addToBlobCache: addToBlobCache(editor),
- createBlobCache: createBlobCache(editor),
- alertErr: alertErr(editor),
- normalizeCss: normalizeCss$1(editor),
- parseStyle: parseStyle(editor),
- serializeStyle: serializeStyle(editor)
- };
- var open = function () {
- return collect(editor).then(makeDialog(helpers)).then(function (spec) {
- return editor.windowManager.open(spec);
- });
- };
- var openLater = function () {
- open();
- };
- return {
- open: open,
- openLater: openLater
- };
- };
- var register = function (editor) {
- editor.addCommand('mceImage', Dialog(editor).openLater);
- editor.addCommand('mceUpdateImage', function (_ui, data) {
- editor.undoManager.transact(function () {
- return insertOrUpdateImage(editor, data);
- });
- });
- };
- var hasImageClass = function (node) {
- var className = node.attr('class');
- return className && /\bimage\b/.test(className);
- };
- var toggleContentEditableState = function (state) {
- return function (nodes) {
- var i = nodes.length;
- var toggleContentEditable = function (node) {
- node.attr('contenteditable', state ? 'true' : null);
- };
- while (i--) {
- var node = nodes[i];
- if (hasImageClass(node)) {
- node.attr('contenteditable', state ? 'false' : null);
- global$4.each(node.getAll('figcaption'), toggleContentEditable);
- }
- }
- };
- };
- var setup = function (editor) {
- editor.on('PreInit', function () {
- editor.parser.addNodeFilter('figure', toggleContentEditableState(true));
- editor.serializer.addNodeFilter('figure', toggleContentEditableState(false));
- });
- };
- var register$1 = function (editor) {
- editor.ui.registry.addToggleButton('image', {
- icon: 'image',
- tooltip: 'Insert/edit image',
- onAction: Dialog(editor).openLater,
- onSetup: function (buttonApi) {
- return editor.selection.selectorChangedWithUnbind('img:not([data-mce-object],[data-mce-placeholder]),figure.image', buttonApi.setActive).unbind;
- }
- });
- editor.ui.registry.addMenuItem('image', {
- icon: 'image',
- text: 'Image...',
- onAction: Dialog(editor).openLater
- });
- editor.ui.registry.addContextMenu('image', {
- update: function (element) {
- return isFigure(element) || isImage(element) && !isPlaceholderImage(element) ? ['image'] : [];
- }
- });
- };
- function Plugin () {
- global.add('image', function (editor) {
- setup(editor);
- register$1(editor);
- register(editor);
- });
- }
- Plugin();
- }(window));
|