tinymce
Version:
Web based JavaScript HTML WYSIWYG editor control.
1,526 lines (1,507 loc) • 77.5 kB
JavaScript
/**
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
* Licensed under the LGPL or a commercial license.
* For LGPL see License.txt in the project root for license information.
* For commercial licenses see https://www.tiny.cloud/
*
* Version: 5.1.0 (2019-10-17)
*/
(function (domGlobals) {
'use strict';
var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
var noop = function () {
};
var constant = function (value) {
return function () {
return value;
};
};
var identity = function (x) {
return x;
};
var die = function (msg) {
return function () {
throw new Error(msg);
};
};
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
};
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 isString = isType('string');
var isObject = isType('object');
var isArray = isType('array');
var isBoolean = isType('boolean');
var isFunction = isType('function');
var nativeSlice = Array.prototype.slice;
var nativePush = Array.prototype.push;
var each = function (xs, f) {
for (var i = 0, len = xs.length; i < len; i++) {
var x = xs[i];
f(x, i);
}
};
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 from$1 = isFunction(Array.from) ? Array.from : function (x) {
return nativeSlice.call(x);
};
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 exports$1 = {}, module = { exports: exports$1 };
(function (define, exports, module, require) {
(function (f) {
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = f();
} else if (typeof define === 'function' && define.amd) {
define([], f);
} else {
var g;
if (typeof window !== 'undefined') {
g = window;
} else if (typeof global !== 'undefined') {
g = global;
} else if (typeof self !== 'undefined') {
g = self;
} else {
g = this;
}
g.EphoxContactWrapper = f();
}
}(function () {
return function () {
function r(e, n, t) {
function o(i, f) {
if (!n[i]) {
if (!e[i]) {
var c = 'function' == typeof require && require;
if (!f && c)
return c(i, !0);
if (u)
return u(i, !0);
var a = new Error('Cannot find module \'' + i + '\'');
throw a.code = 'MODULE_NOT_FOUND', a;
}
var p = n[i] = { exports: {} };
e[i][0].call(p.exports, function (r) {
var n = e[i][1][r];
return o(n || r);
}, p, p.exports, r, e, n, t);
}
return n[i].exports;
}
for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
o(t[i]);
return o;
}
return r;
}()({
1: [
function (require, module, exports) {
var process = module.exports = {};
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout() {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
}());
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
return setTimeout(fun, 0);
}
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
return cachedSetTimeout(fun, 0);
} catch (e) {
try {
return cachedSetTimeout.call(null, fun, 0);
} catch (e) {
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
return clearTimeout(marker);
}
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
return cachedClearTimeout(marker);
} catch (e) {
try {
return cachedClearTimeout.call(null, marker);
} catch (e) {
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while (len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = '';
process.versions = {};
function noop() {
}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) {
return [];
};
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () {
return '/';
};
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function () {
return 0;
};
},
{}
],
2: [
function (require, module, exports) {
(function (setImmediate) {
(function (root) {
var setTimeoutFunc = setTimeout;
function noop() {
}
function bind(fn, thisArg) {
return function () {
fn.apply(thisArg, arguments);
};
}
function Promise(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 = 0;
this._handled = false;
this._value = undefined;
this._deferreds = [];
doResolve(fn, this);
}
function handle(self, deferred) {
while (self._state === 3) {
self = self._value;
}
if (self._state === 0) {
self._deferreds.push(deferred);
return;
}
self._handled = true;
Promise._immediateFn(function () {
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
if (cb === null) {
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
return;
}
var ret;
try {
ret = cb(self._value);
} catch (e) {
reject(deferred.promise, e);
return;
}
resolve(deferred.promise, ret);
});
}
function resolve(self, newValue) {
try {
if (newValue === self)
throw new TypeError('A promise cannot be resolved with itself.');
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
var then = newValue.then;
if (newValue instanceof Promise) {
self._state = 3;
self._value = newValue;
finale(self);
return;
} else if (typeof then === 'function') {
doResolve(bind(then, newValue), self);
return;
}
}
self._state = 1;
self._value = newValue;
finale(self);
} catch (e) {
reject(self, e);
}
}
function reject(self, newValue) {
self._state = 2;
self._value = newValue;
finale(self);
}
function finale(self) {
if (self._state === 2 && self._deferreds.length === 0) {
Promise._immediateFn(function () {
if (!self._handled) {
Promise._unhandledRejectionFn(self._value);
}
});
}
for (var i = 0, len = self._deferreds.length; i < len; i++) {
handle(self, self._deferreds[i]);
}
self._deferreds = null;
}
function Handler(onFulfilled, onRejected, promise) {
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
this.promise = promise;
}
function doResolve(fn, self) {
var done = false;
try {
fn(function (value) {
if (done)
return;
done = true;
resolve(self, value);
}, function (reason) {
if (done)
return;
done = true;
reject(self, reason);
});
} catch (ex) {
if (done)
return;
done = true;
reject(self, ex);
}
}
Promise.prototype['catch'] = function (onRejected) {
return this.then(null, onRejected);
};
Promise.prototype.then = function (onFulfilled, onRejected) {
var prom = new this.constructor(noop);
handle(this, new Handler(onFulfilled, onRejected, prom));
return prom;
};
Promise.all = function (arr) {
var args = Array.prototype.slice.call(arr);
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 (value) {
return new Promise(function (resolve, reject) {
reject(value);
});
};
Promise.race = function (values) {
return new Promise(function (resolve, reject) {
for (var i = 0, len = values.length; i < len; i++) {
values[i].then(resolve, reject);
}
});
};
Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
setImmediate(fn);
} : function (fn) {
setTimeoutFunc(fn, 0);
};
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
if (typeof console !== 'undefined' && console) {
console.warn('Possible Unhandled Promise Rejection:', err);
}
};
Promise._setImmediateFn = function _setImmediateFn(fn) {
Promise._immediateFn = fn;
};
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
Promise._unhandledRejectionFn = fn;
};
if (typeof module !== 'undefined' && module.exports) {
module.exports = Promise;
} else if (!root.Promise) {
root.Promise = Promise;
}
}(this));
}.call(this, require('timers').setImmediate));
},
{ 'timers': 3 }
],
3: [
function (require, module, exports) {
(function (setImmediate, clearImmediate) {
var nextTick = require('process/browser.js').nextTick;
var apply = Function.prototype.apply;
var slice = Array.prototype.slice;
var immediateIds = {};
var nextImmediateId = 0;
exports.setTimeout = function () {
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
};
exports.setInterval = function () {
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
};
exports.clearTimeout = exports.clearInterval = function (timeout) {
timeout.close();
};
function Timeout(id, clearFn) {
this._id = id;
this._clearFn = clearFn;
}
Timeout.prototype.unref = Timeout.prototype.ref = function () {
};
Timeout.prototype.close = function () {
this._clearFn.call(window, this._id);
};
exports.enroll = function (item, msecs) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = msecs;
};
exports.unenroll = function (item) {
clearTimeout(item._idleTimeoutId);
item._idleTimeout = -1;
};
exports._unrefActive = exports.active = function (item) {
clearTimeout(item._idleTimeoutId);
var msecs = item._idleTimeout;
if (msecs >= 0) {
item._idleTimeoutId = setTimeout(function onTimeout() {
if (item._onTimeout)
item._onTimeout();
}, msecs);
}
};
exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
var id = nextImmediateId++;
var args = arguments.length < 2 ? false : slice.call(arguments, 1);
immediateIds[id] = true;
nextTick(function onNextTick() {
if (immediateIds[id]) {
if (args) {
fn.apply(null, args);
} else {
fn.call(null);
}
exports.clearImmediate(id);
}
});
return id;
};
exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
delete immediateIds[id];
};
}.call(this, require('timers').setImmediate, require('timers').clearImmediate));
},
{
'process/browser.js': 1,
'timers': 3
}
],
4: [
function (require, module, exports) {
var promisePolyfill = require('promise-polyfill');
var Global = function () {
if (typeof window !== 'undefined') {
return window;
} else {
return Function('return this;')();
}
}();
module.exports = { boltExport: Global.Promise || promisePolyfill };
},
{ 'promise-polyfill': 2 }
]
}, {}, [4])(4);
}));
}(undefined, exports$1, module, undefined));
var Promise = module.exports.boltExport;
var nu = function (baseFn) {
var data = Option.none();
var callbacks = [];
var map = function (f) {
return nu(function (nCallback) {
get(function (data) {
nCallback(f(data));
});
});
};
var get = function (nCallback) {
if (isReady()) {
call(nCallback);
} else {
callbacks.push(nCallback);
}
};
var set = function (x) {
data = Option.some(x);
run(callbacks);
callbacks = [];
};
var isReady = function () {
return data.isSome();
};
var run = function (cbs) {
each(cbs, call);
};
var call = function (cb) {
data.each(function (x) {
domGlobals.setTimeout(function () {
cb(x);
}, 0);
});
};
baseFn(set);
return {
get: get,
map: map,
isReady: isReady
};
};
var pure = function (a) {
return nu(function (callback) {
callback(a);
});
};
var LazyValue = {
nu: nu,
pure: pure
};
var errorReporter = function (err) {
domGlobals.setTimeout(function () {
throw err;
}, 0);
};
var make = function (run) {
var get = function (callback) {
run().then(callback, errorReporter);
};
var map = function (fab) {
return make(function () {
return run().then(fab);
});
};
var bind = function (aFutureB) {
return make(function () {
return run().then(function (v) {
return aFutureB(v).toPromise();
});
});
};
var anonBind = function (futureB) {
return make(function () {
return run().then(function () {
return futureB.toPromise();
});
});
};
var toLazy = function () {
return LazyValue.nu(get);
};
var toCached = function () {
var cache = null;
return make(function () {
if (cache === null) {
cache = run();
}
return cache;
});
};
var toPromise = run;
return {
map: map,
bind: bind,
anonBind: anonBind,
toLazy: toLazy,
toCached: toCached,
toPromise: toPromise,
get: get
};
};
var nu$1 = function (baseFn) {
return make(function () {
return new Promise(baseFn);
});
};
var pure$1 = function (a) {
return make(function () {
return Promise.resolve(a);
});
};
var Future = {
nu: nu$1,
pure: pure$1
};
var value = function (o) {
var is = function (v) {
return o === v;
};
var or = function (opt) {
return value(o);
};
var orThunk = function (f) {
return value(o);
};
var map = function (f) {
return value(f(o));
};
var mapError = function (f) {
return value(o);
};
var each = function (f) {
f(o);
};
var bind = function (f) {
return f(o);
};
var fold = function (_, onValue) {
return onValue(o);
};
var exists = function (f) {
return f(o);
};
var forall = function (f) {
return f(o);
};
var toOption = function () {
return Option.some(o);
};
return {
is: is,
isValue: always,
isError: never,
getOr: constant(o),
getOrThunk: constant(o),
getOrDie: constant(o),
or: or,
orThunk: orThunk,
fold: fold,
map: map,
mapError: mapError,
each: each,
bind: bind,
exists: exists,
forall: forall,
toOption: toOption
};
};
var error = function (message) {
var getOrThunk = function (f) {
return f();
};
var getOrDie = function () {
return die(String(message))();
};
var or = function (opt) {
return opt;
};
var orThunk = function (f) {
return f();
};
var map = function (f) {
return error(message);
};
var mapError = function (f) {
return error(f(message));
};
var bind = function (f) {
return error(message);
};
var fold = function (onError, _) {
return onError(message);
};
return {
is: never,
isValue: never,
isError: always,
getOr: identity,
getOrThunk: getOrThunk,
getOrDie: getOrDie,
or: or,
orThunk: orThunk,
fold: fold,
map: map,
mapError: mapError,
each: noop,
bind: bind,
exists: never,
forall: always,
toOption: Option.none
};
};
var fromOption = function (opt, err) {
return opt.fold(function () {
return error(err);
}, value);
};
var Result = {
value: value,
error: error,
fromOption: fromOption
};
var wrap = function (delegate) {
var toCached = function () {
return wrap(delegate.toCached());
};
var bindFuture = function (f) {
return wrap(delegate.bind(function (resA) {
return resA.fold(function (err) {
return Future.pure(Result.error(err));
}, function (a) {
return f(a);
});
}));
};
var bindResult = function (f) {
return wrap(delegate.map(function (resA) {
return resA.bind(f);
}));
};
var mapResult = function (f) {
return wrap(delegate.map(function (resA) {
return resA.map(f);
}));
};
var mapError = function (f) {
return wrap(delegate.map(function (resA) {
return resA.mapError(f);
}));
};
var foldResult = function (whenError, whenValue) {
return delegate.map(function (res) {
return res.fold(whenError, whenValue);
});
};
var withTimeout = function (timeout, errorThunk) {
return wrap(Future.nu(function (callback) {
var timedOut = false;
var timer = domGlobals.setTimeout(function () {
timedOut = true;
callback(Result.error(errorThunk()));
}, timeout);
delegate.get(function (result) {
if (!timedOut) {
domGlobals.clearTimeout(timer);
callback(result);
}
});
}));
};
return __assign(__assign({}, delegate), {
toCached: toCached,
bindFuture: bindFuture,
bindResult: bindResult,
mapResult: mapResult,
mapError: mapError,
foldResult: foldResult,
withTimeout: withTimeout
});
};
var nu$2 = function (worker) {
return wrap(Future.nu(worker));
};
var value$1 = function (value) {
return wrap(Future.pure(Result.value(value)));
};
var error$1 = function (error) {
return wrap(Future.pure(Result.error(error)));
};
var fromResult = function (result) {
return wrap(Future.pure(result));
};
var fromFuture = function (future) {
return wrap(future.map(Result.value));
};
var fromPromise = function (promise) {
return nu$2(function (completer) {
promise.then(function (value) {
completer(Result.value(value));
}, function (error) {
completer(Result.error(error));
});
});
};
var FutureResult = {
nu: nu$2,
wrap: wrap,
pure: value$1,
value: value$1,
error: error$1,
fromResult: fromResult,
fromFuture: fromFuture,
fromPromise: fromPromise
};
var hasOwnProperty = Object.prototype.hasOwnProperty;
var shallow = function (old, nu) {
return nu;
};
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 merge = baseMerge(shallow);
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: 'Image description'
};
var imageTitle = {
name: 'title',
type: 'input',
label: 'Image title'
};
var imageDimensions = {
name: 'dimensions',
type: 'sizeinput'
};
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.hasDescription ? [imageDescription] : [],
info.hasImageTitle ? [imageTitle] : [],
info.hasDimensions ? [imageDimensions] : [],
[{
type: 'grid',
columns: 2,
items: flatten([
classList.toArray(),
info.hasImageCaption ? [caption] : []
])
}]
]);
};
var makeTab = function (info) {
return {
title: 'General',
name: 'general',
items: makeItems(info)
};
};
var MainTab = {
makeTab: makeTab,
makeItems: makeItems
};
var global$2 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
var global$4 = 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 Settings = {
hasDimensions: hasDimensions,
hasUploadTab: hasUploadTab,
hasAdvTab: hasAdvTab,
getPrependUrl: getPrependUrl,
getClassList: getClassList,
hasDescription: hasDescription,
hasImageTitle: hasImageTitle,
hasImageCaption: hasImageCaption,
getImageList: getImageList,
hasUploadUrl: hasUploadUrl,
hasUploadHandler: hasUploadHandler,
getUploadUrl: getUploadUrl,
getUploadHandler: getUploadHandler,
getUploadBasePath: getUploadBasePath,
getUploadCredentials: getUploadCredentials
};
var parseIntAndGetMax = function (val1, val2) {
return Math.max(parseInt(val1, 10), parseInt(val2, 10));
};
var getImageSize = function (url, 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(Result.value(dimensions));
};
img.onerror = function () {
done(Result.error('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 = Settings.getImageList(editor);
if (typeof imageList === 'string') {
global$4.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 && Settings.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$3(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 Utils = {
getImageSize: getImageSize,
removePixelSuffix: removePixelSuffix,
addPixelSuffix: addPixelSuffix,
mergeMargins: mergeMargins,
createImageList: createImageList,
waitLoadImage: waitLoadImage,
blobToDataUri: blobToDataUri,
isPlaceholderImage: isPlaceholderImage
};
var DOM = global$2.DOM;
var getHspace = function (image) {
if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {
return Utils.removePixelSuffix(image.style.marginLeft);
} else {
return '';
}
};
var getVspace = function (image) {
if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {
return Utils.removePixelSuffix(image.style.marginTop);
} else {
return '';
}
};
var getBorder = function (image) {
if (image.style.borderWidth) {
return Utils.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 setAttrib = function (image, name, value) {
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] = Utils.addPixelSuffix(value);
normalizeStyle(image, normalizeCss);
} else {
setAttrib(image, name, value);
}
};
};
var getSize = function (image, name) {
if (image.style[name]) {
return Utils.removePixelSuffix(image.style[name]);
} else {
return getAttrib(image, name);
}
};
var setHspace = function (image, value) {
var pxValue = Utils.addPixelSuffix(value);
image.style.marginLeft = pxValue;
image.style.marginRight = pxValue;
};
var setVspace = function (image, value) {
var pxValue = Utils.addPixelSuffix(value);
image.style.marginTop = pxValue;
image.style.marginBottom = pxValue;
};
var setBorder = function (image, value) {
var pxValue = Utils.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 defaultData = function () {
return {
src: '',
alt: '',
title: '',
width: '',
height: '',
class: '',
style: '',
caption: false,
hspace: '',
vspace: '',
border: '',
borderStyle: ''
};
};
var getStyleValue = function (normalizeCss, data) {
var image = domGlobals.document.createElement('img');
setAttrib(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, merge(data, { caption: false }), image);
setAttrib(image, 'alt', data.alt);
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: getAttrib(image, 'alt'),
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')
};
};
var updateProp = function (image, oldData, newData, name, set) {
if (newData[name] !== oldData[name]) {
set(image, name, newData[name]);
}
};
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', setAttrib);
updateProp(image, oldData, newData, 'alt', setAttrib);
updateProp(image, oldData, newData, 'title', setAttrib);
updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));
updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));
updateProp(image, oldData, newData, 'class', setAttrib);
updateProp(image, oldData, newData, 'style', normalized(function (image, value) {
return setAttrib(image, 'style', value);
}, normalizeC