plugin.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.1.0 (2019-10-17)
  8. */
  9. (function (domGlobals) {
  10. 'use strict';
  11. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var noop = function () {
  13. };
  14. var constant = function (value) {
  15. return function () {
  16. return value;
  17. };
  18. };
  19. var identity = function (x) {
  20. return x;
  21. };
  22. var die = function (msg) {
  23. return function () {
  24. throw new Error(msg);
  25. };
  26. };
  27. var never = constant(false);
  28. var always = constant(true);
  29. var none = function () {
  30. return NONE;
  31. };
  32. var NONE = function () {
  33. var eq = function (o) {
  34. return o.isNone();
  35. };
  36. var call = function (thunk) {
  37. return thunk();
  38. };
  39. var id = function (n) {
  40. return n;
  41. };
  42. var me = {
  43. fold: function (n, s) {
  44. return n();
  45. },
  46. is: never,
  47. isSome: never,
  48. isNone: always,
  49. getOr: id,
  50. getOrThunk: call,
  51. getOrDie: function (msg) {
  52. throw new Error(msg || 'error: getOrDie called on none.');
  53. },
  54. getOrNull: constant(null),
  55. getOrUndefined: constant(undefined),
  56. or: id,
  57. orThunk: call,
  58. map: none,
  59. each: noop,
  60. bind: none,
  61. exists: never,
  62. forall: always,
  63. filter: none,
  64. equals: eq,
  65. equals_: eq,
  66. toArray: function () {
  67. return [];
  68. },
  69. toString: constant('none()')
  70. };
  71. if (Object.freeze) {
  72. Object.freeze(me);
  73. }
  74. return me;
  75. }();
  76. var some = function (a) {
  77. var constant_a = constant(a);
  78. var self = function () {
  79. return me;
  80. };
  81. var bind = function (f) {
  82. return f(a);
  83. };
  84. var me = {
  85. fold: function (n, s) {
  86. return s(a);
  87. },
  88. is: function (v) {
  89. return a === v;
  90. },
  91. isSome: always,
  92. isNone: never,
  93. getOr: constant_a,
  94. getOrThunk: constant_a,
  95. getOrDie: constant_a,
  96. getOrNull: constant_a,
  97. getOrUndefined: constant_a,
  98. or: self,
  99. orThunk: self,
  100. map: function (f) {
  101. return some(f(a));
  102. },
  103. each: function (f) {
  104. f(a);
  105. },
  106. bind: bind,
  107. exists: bind,
  108. forall: bind,
  109. filter: function (f) {
  110. return f(a) ? me : NONE;
  111. },
  112. toArray: function () {
  113. return [a];
  114. },
  115. toString: function () {
  116. return 'some(' + a + ')';
  117. },
  118. equals: function (o) {
  119. return o.is(a);
  120. },
  121. equals_: function (o, elementEq) {
  122. return o.fold(never, function (b) {
  123. return elementEq(a, b);
  124. });
  125. }
  126. };
  127. return me;
  128. };
  129. var from = function (value) {
  130. return value === null || value === undefined ? NONE : some(value);
  131. };
  132. var Option = {
  133. some: some,
  134. none: none,
  135. from: from
  136. };
  137. var typeOf = function (x) {
  138. if (x === null) {
  139. return 'null';
  140. }
  141. var t = typeof x;
  142. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  143. return 'array';
  144. }
  145. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  146. return 'string';
  147. }
  148. return t;
  149. };
  150. var isType = function (type) {
  151. return function (value) {
  152. return typeOf(value) === type;
  153. };
  154. };
  155. var isString = isType('string');
  156. var isObject = isType('object');
  157. var isArray = isType('array');
  158. var isBoolean = isType('boolean');
  159. var isFunction = isType('function');
  160. var nativeSlice = Array.prototype.slice;
  161. var nativePush = Array.prototype.push;
  162. var each = function (xs, f) {
  163. for (var i = 0, len = xs.length; i < len; i++) {
  164. var x = xs[i];
  165. f(x, i);
  166. }
  167. };
  168. var flatten = function (xs) {
  169. var r = [];
  170. for (var i = 0, len = xs.length; i < len; ++i) {
  171. if (!isArray(xs[i])) {
  172. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  173. }
  174. nativePush.apply(r, xs[i]);
  175. }
  176. return r;
  177. };
  178. var head = function (xs) {
  179. return xs.length === 0 ? Option.none() : Option.some(xs[0]);
  180. };
  181. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  182. return nativeSlice.call(x);
  183. };
  184. var __assign = function () {
  185. __assign = Object.assign || function __assign(t) {
  186. for (var s, i = 1, n = arguments.length; i < n; i++) {
  187. s = arguments[i];
  188. for (var p in s)
  189. if (Object.prototype.hasOwnProperty.call(s, p))
  190. t[p] = s[p];
  191. }
  192. return t;
  193. };
  194. return __assign.apply(this, arguments);
  195. };
  196. var exports$1 = {}, module = { exports: exports$1 };
  197. (function (define, exports, module, require) {
  198. (function (f) {
  199. if (typeof exports === 'object' && typeof module !== 'undefined') {
  200. module.exports = f();
  201. } else if (typeof define === 'function' && define.amd) {
  202. define([], f);
  203. } else {
  204. var g;
  205. if (typeof window !== 'undefined') {
  206. g = window;
  207. } else if (typeof global !== 'undefined') {
  208. g = global;
  209. } else if (typeof self !== 'undefined') {
  210. g = self;
  211. } else {
  212. g = this;
  213. }
  214. g.EphoxContactWrapper = f();
  215. }
  216. }(function () {
  217. return function () {
  218. function r(e, n, t) {
  219. function o(i, f) {
  220. if (!n[i]) {
  221. if (!e[i]) {
  222. var c = 'function' == typeof require && require;
  223. if (!f && c)
  224. return c(i, !0);
  225. if (u)
  226. return u(i, !0);
  227. var a = new Error('Cannot find module \'' + i + '\'');
  228. throw a.code = 'MODULE_NOT_FOUND', a;
  229. }
  230. var p = n[i] = { exports: {} };
  231. e[i][0].call(p.exports, function (r) {
  232. var n = e[i][1][r];
  233. return o(n || r);
  234. }, p, p.exports, r, e, n, t);
  235. }
  236. return n[i].exports;
  237. }
  238. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  239. o(t[i]);
  240. return o;
  241. }
  242. return r;
  243. }()({
  244. 1: [
  245. function (require, module, exports) {
  246. var process = module.exports = {};
  247. var cachedSetTimeout;
  248. var cachedClearTimeout;
  249. function defaultSetTimout() {
  250. throw new Error('setTimeout has not been defined');
  251. }
  252. function defaultClearTimeout() {
  253. throw new Error('clearTimeout has not been defined');
  254. }
  255. (function () {
  256. try {
  257. if (typeof setTimeout === 'function') {
  258. cachedSetTimeout = setTimeout;
  259. } else {
  260. cachedSetTimeout = defaultSetTimout;
  261. }
  262. } catch (e) {
  263. cachedSetTimeout = defaultSetTimout;
  264. }
  265. try {
  266. if (typeof clearTimeout === 'function') {
  267. cachedClearTimeout = clearTimeout;
  268. } else {
  269. cachedClearTimeout = defaultClearTimeout;
  270. }
  271. } catch (e) {
  272. cachedClearTimeout = defaultClearTimeout;
  273. }
  274. }());
  275. function runTimeout(fun) {
  276. if (cachedSetTimeout === setTimeout) {
  277. return setTimeout(fun, 0);
  278. }
  279. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  280. cachedSetTimeout = setTimeout;
  281. return setTimeout(fun, 0);
  282. }
  283. try {
  284. return cachedSetTimeout(fun, 0);
  285. } catch (e) {
  286. try {
  287. return cachedSetTimeout.call(null, fun, 0);
  288. } catch (e) {
  289. return cachedSetTimeout.call(this, fun, 0);
  290. }
  291. }
  292. }
  293. function runClearTimeout(marker) {
  294. if (cachedClearTimeout === clearTimeout) {
  295. return clearTimeout(marker);
  296. }
  297. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  298. cachedClearTimeout = clearTimeout;
  299. return clearTimeout(marker);
  300. }
  301. try {
  302. return cachedClearTimeout(marker);
  303. } catch (e) {
  304. try {
  305. return cachedClearTimeout.call(null, marker);
  306. } catch (e) {
  307. return cachedClearTimeout.call(this, marker);
  308. }
  309. }
  310. }
  311. var queue = [];
  312. var draining = false;
  313. var currentQueue;
  314. var queueIndex = -1;
  315. function cleanUpNextTick() {
  316. if (!draining || !currentQueue) {
  317. return;
  318. }
  319. draining = false;
  320. if (currentQueue.length) {
  321. queue = currentQueue.concat(queue);
  322. } else {
  323. queueIndex = -1;
  324. }
  325. if (queue.length) {
  326. drainQueue();
  327. }
  328. }
  329. function drainQueue() {
  330. if (draining) {
  331. return;
  332. }
  333. var timeout = runTimeout(cleanUpNextTick);
  334. draining = true;
  335. var len = queue.length;
  336. while (len) {
  337. currentQueue = queue;
  338. queue = [];
  339. while (++queueIndex < len) {
  340. if (currentQueue) {
  341. currentQueue[queueIndex].run();
  342. }
  343. }
  344. queueIndex = -1;
  345. len = queue.length;
  346. }
  347. currentQueue = null;
  348. draining = false;
  349. runClearTimeout(timeout);
  350. }
  351. process.nextTick = function (fun) {
  352. var args = new Array(arguments.length - 1);
  353. if (arguments.length > 1) {
  354. for (var i = 1; i < arguments.length; i++) {
  355. args[i - 1] = arguments[i];
  356. }
  357. }
  358. queue.push(new Item(fun, args));
  359. if (queue.length === 1 && !draining) {
  360. runTimeout(drainQueue);
  361. }
  362. };
  363. function Item(fun, array) {
  364. this.fun = fun;
  365. this.array = array;
  366. }
  367. Item.prototype.run = function () {
  368. this.fun.apply(null, this.array);
  369. };
  370. process.title = 'browser';
  371. process.browser = true;
  372. process.env = {};
  373. process.argv = [];
  374. process.version = '';
  375. process.versions = {};
  376. function noop() {
  377. }
  378. process.on = noop;
  379. process.addListener = noop;
  380. process.once = noop;
  381. process.off = noop;
  382. process.removeListener = noop;
  383. process.removeAllListeners = noop;
  384. process.emit = noop;
  385. process.prependListener = noop;
  386. process.prependOnceListener = noop;
  387. process.listeners = function (name) {
  388. return [];
  389. };
  390. process.binding = function (name) {
  391. throw new Error('process.binding is not supported');
  392. };
  393. process.cwd = function () {
  394. return '/';
  395. };
  396. process.chdir = function (dir) {
  397. throw new Error('process.chdir is not supported');
  398. };
  399. process.umask = function () {
  400. return 0;
  401. };
  402. },
  403. {}
  404. ],
  405. 2: [
  406. function (require, module, exports) {
  407. (function (setImmediate) {
  408. (function (root) {
  409. var setTimeoutFunc = setTimeout;
  410. function noop() {
  411. }
  412. function bind(fn, thisArg) {
  413. return function () {
  414. fn.apply(thisArg, arguments);
  415. };
  416. }
  417. function Promise(fn) {
  418. if (typeof this !== 'object')
  419. throw new TypeError('Promises must be constructed via new');
  420. if (typeof fn !== 'function')
  421. throw new TypeError('not a function');
  422. this._state = 0;
  423. this._handled = false;
  424. this._value = undefined;
  425. this._deferreds = [];
  426. doResolve(fn, this);
  427. }
  428. function handle(self, deferred) {
  429. while (self._state === 3) {
  430. self = self._value;
  431. }
  432. if (self._state === 0) {
  433. self._deferreds.push(deferred);
  434. return;
  435. }
  436. self._handled = true;
  437. Promise._immediateFn(function () {
  438. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  439. if (cb === null) {
  440. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  441. return;
  442. }
  443. var ret;
  444. try {
  445. ret = cb(self._value);
  446. } catch (e) {
  447. reject(deferred.promise, e);
  448. return;
  449. }
  450. resolve(deferred.promise, ret);
  451. });
  452. }
  453. function resolve(self, newValue) {
  454. try {
  455. if (newValue === self)
  456. throw new TypeError('A promise cannot be resolved with itself.');
  457. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  458. var then = newValue.then;
  459. if (newValue instanceof Promise) {
  460. self._state = 3;
  461. self._value = newValue;
  462. finale(self);
  463. return;
  464. } else if (typeof then === 'function') {
  465. doResolve(bind(then, newValue), self);
  466. return;
  467. }
  468. }
  469. self._state = 1;
  470. self._value = newValue;
  471. finale(self);
  472. } catch (e) {
  473. reject(self, e);
  474. }
  475. }
  476. function reject(self, newValue) {
  477. self._state = 2;
  478. self._value = newValue;
  479. finale(self);
  480. }
  481. function finale(self) {
  482. if (self._state === 2 && self._deferreds.length === 0) {
  483. Promise._immediateFn(function () {
  484. if (!self._handled) {
  485. Promise._unhandledRejectionFn(self._value);
  486. }
  487. });
  488. }
  489. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  490. handle(self, self._deferreds[i]);
  491. }
  492. self._deferreds = null;
  493. }
  494. function Handler(onFulfilled, onRejected, promise) {
  495. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  496. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  497. this.promise = promise;
  498. }
  499. function doResolve(fn, self) {
  500. var done = false;
  501. try {
  502. fn(function (value) {
  503. if (done)
  504. return;
  505. done = true;
  506. resolve(self, value);
  507. }, function (reason) {
  508. if (done)
  509. return;
  510. done = true;
  511. reject(self, reason);
  512. });
  513. } catch (ex) {
  514. if (done)
  515. return;
  516. done = true;
  517. reject(self, ex);
  518. }
  519. }
  520. Promise.prototype['catch'] = function (onRejected) {
  521. return this.then(null, onRejected);
  522. };
  523. Promise.prototype.then = function (onFulfilled, onRejected) {
  524. var prom = new this.constructor(noop);
  525. handle(this, new Handler(onFulfilled, onRejected, prom));
  526. return prom;
  527. };
  528. Promise.all = function (arr) {
  529. var args = Array.prototype.slice.call(arr);
  530. return new Promise(function (resolve, reject) {
  531. if (args.length === 0)
  532. return resolve([]);
  533. var remaining = args.length;
  534. function res(i, val) {
  535. try {
  536. if (val && (typeof val === 'object' || typeof val === 'function')) {
  537. var then = val.then;
  538. if (typeof then === 'function') {
  539. then.call(val, function (val) {
  540. res(i, val);
  541. }, reject);
  542. return;
  543. }
  544. }
  545. args[i] = val;
  546. if (--remaining === 0) {
  547. resolve(args);
  548. }
  549. } catch (ex) {
  550. reject(ex);
  551. }
  552. }
  553. for (var i = 0; i < args.length; i++) {
  554. res(i, args[i]);
  555. }
  556. });
  557. };
  558. Promise.resolve = function (value) {
  559. if (value && typeof value === 'object' && value.constructor === Promise) {
  560. return value;
  561. }
  562. return new Promise(function (resolve) {
  563. resolve(value);
  564. });
  565. };
  566. Promise.reject = function (value) {
  567. return new Promise(function (resolve, reject) {
  568. reject(value);
  569. });
  570. };
  571. Promise.race = function (values) {
  572. return new Promise(function (resolve, reject) {
  573. for (var i = 0, len = values.length; i < len; i++) {
  574. values[i].then(resolve, reject);
  575. }
  576. });
  577. };
  578. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  579. setImmediate(fn);
  580. } : function (fn) {
  581. setTimeoutFunc(fn, 0);
  582. };
  583. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  584. if (typeof console !== 'undefined' && console) {
  585. console.warn('Possible Unhandled Promise Rejection:', err);
  586. }
  587. };
  588. Promise._setImmediateFn = function _setImmediateFn(fn) {
  589. Promise._immediateFn = fn;
  590. };
  591. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  592. Promise._unhandledRejectionFn = fn;
  593. };
  594. if (typeof module !== 'undefined' && module.exports) {
  595. module.exports = Promise;
  596. } else if (!root.Promise) {
  597. root.Promise = Promise;
  598. }
  599. }(this));
  600. }.call(this, require('timers').setImmediate));
  601. },
  602. { 'timers': 3 }
  603. ],
  604. 3: [
  605. function (require, module, exports) {
  606. (function (setImmediate, clearImmediate) {
  607. var nextTick = require('process/browser.js').nextTick;
  608. var apply = Function.prototype.apply;
  609. var slice = Array.prototype.slice;
  610. var immediateIds = {};
  611. var nextImmediateId = 0;
  612. exports.setTimeout = function () {
  613. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  614. };
  615. exports.setInterval = function () {
  616. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  617. };
  618. exports.clearTimeout = exports.clearInterval = function (timeout) {
  619. timeout.close();
  620. };
  621. function Timeout(id, clearFn) {
  622. this._id = id;
  623. this._clearFn = clearFn;
  624. }
  625. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  626. };
  627. Timeout.prototype.close = function () {
  628. this._clearFn.call(window, this._id);
  629. };
  630. exports.enroll = function (item, msecs) {
  631. clearTimeout(item._idleTimeoutId);
  632. item._idleTimeout = msecs;
  633. };
  634. exports.unenroll = function (item) {
  635. clearTimeout(item._idleTimeoutId);
  636. item._idleTimeout = -1;
  637. };
  638. exports._unrefActive = exports.active = function (item) {
  639. clearTimeout(item._idleTimeoutId);
  640. var msecs = item._idleTimeout;
  641. if (msecs >= 0) {
  642. item._idleTimeoutId = setTimeout(function onTimeout() {
  643. if (item._onTimeout)
  644. item._onTimeout();
  645. }, msecs);
  646. }
  647. };
  648. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  649. var id = nextImmediateId++;
  650. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  651. immediateIds[id] = true;
  652. nextTick(function onNextTick() {
  653. if (immediateIds[id]) {
  654. if (args) {
  655. fn.apply(null, args);
  656. } else {
  657. fn.call(null);
  658. }
  659. exports.clearImmediate(id);
  660. }
  661. });
  662. return id;
  663. };
  664. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  665. delete immediateIds[id];
  666. };
  667. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  668. },
  669. {
  670. 'process/browser.js': 1,
  671. 'timers': 3
  672. }
  673. ],
  674. 4: [
  675. function (require, module, exports) {
  676. var promisePolyfill = require('promise-polyfill');
  677. var Global = function () {
  678. if (typeof window !== 'undefined') {
  679. return window;
  680. } else {
  681. return Function('return this;')();
  682. }
  683. }();
  684. module.exports = { boltExport: Global.Promise || promisePolyfill };
  685. },
  686. { 'promise-polyfill': 2 }
  687. ]
  688. }, {}, [4])(4);
  689. }));
  690. }(undefined, exports$1, module, undefined));
  691. var Promise = module.exports.boltExport;
  692. var nu = function (baseFn) {
  693. var data = Option.none();
  694. var callbacks = [];
  695. var map = function (f) {
  696. return nu(function (nCallback) {
  697. get(function (data) {
  698. nCallback(f(data));
  699. });
  700. });
  701. };
  702. var get = function (nCallback) {
  703. if (isReady()) {
  704. call(nCallback);
  705. } else {
  706. callbacks.push(nCallback);
  707. }
  708. };
  709. var set = function (x) {
  710. data = Option.some(x);
  711. run(callbacks);
  712. callbacks = [];
  713. };
  714. var isReady = function () {
  715. return data.isSome();
  716. };
  717. var run = function (cbs) {
  718. each(cbs, call);
  719. };
  720. var call = function (cb) {
  721. data.each(function (x) {
  722. domGlobals.setTimeout(function () {
  723. cb(x);
  724. }, 0);
  725. });
  726. };
  727. baseFn(set);
  728. return {
  729. get: get,
  730. map: map,
  731. isReady: isReady
  732. };
  733. };
  734. var pure = function (a) {
  735. return nu(function (callback) {
  736. callback(a);
  737. });
  738. };
  739. var LazyValue = {
  740. nu: nu,
  741. pure: pure
  742. };
  743. var errorReporter = function (err) {
  744. domGlobals.setTimeout(function () {
  745. throw err;
  746. }, 0);
  747. };
  748. var make = function (run) {
  749. var get = function (callback) {
  750. run().then(callback, errorReporter);
  751. };
  752. var map = function (fab) {
  753. return make(function () {
  754. return run().then(fab);
  755. });
  756. };
  757. var bind = function (aFutureB) {
  758. return make(function () {
  759. return run().then(function (v) {
  760. return aFutureB(v).toPromise();
  761. });
  762. });
  763. };
  764. var anonBind = function (futureB) {
  765. return make(function () {
  766. return run().then(function () {
  767. return futureB.toPromise();
  768. });
  769. });
  770. };
  771. var toLazy = function () {
  772. return LazyValue.nu(get);
  773. };
  774. var toCached = function () {
  775. var cache = null;
  776. return make(function () {
  777. if (cache === null) {
  778. cache = run();
  779. }
  780. return cache;
  781. });
  782. };
  783. var toPromise = run;
  784. return {
  785. map: map,
  786. bind: bind,
  787. anonBind: anonBind,
  788. toLazy: toLazy,
  789. toCached: toCached,
  790. toPromise: toPromise,
  791. get: get
  792. };
  793. };
  794. var nu$1 = function (baseFn) {
  795. return make(function () {
  796. return new Promise(baseFn);
  797. });
  798. };
  799. var pure$1 = function (a) {
  800. return make(function () {
  801. return Promise.resolve(a);
  802. });
  803. };
  804. var Future = {
  805. nu: nu$1,
  806. pure: pure$1
  807. };
  808. var value = function (o) {
  809. var is = function (v) {
  810. return o === v;
  811. };
  812. var or = function (opt) {
  813. return value(o);
  814. };
  815. var orThunk = function (f) {
  816. return value(o);
  817. };
  818. var map = function (f) {
  819. return value(f(o));
  820. };
  821. var mapError = function (f) {
  822. return value(o);
  823. };
  824. var each = function (f) {
  825. f(o);
  826. };
  827. var bind = function (f) {
  828. return f(o);
  829. };
  830. var fold = function (_, onValue) {
  831. return onValue(o);
  832. };
  833. var exists = function (f) {
  834. return f(o);
  835. };
  836. var forall = function (f) {
  837. return f(o);
  838. };
  839. var toOption = function () {
  840. return Option.some(o);
  841. };
  842. return {
  843. is: is,
  844. isValue: always,
  845. isError: never,
  846. getOr: constant(o),
  847. getOrThunk: constant(o),
  848. getOrDie: constant(o),
  849. or: or,
  850. orThunk: orThunk,
  851. fold: fold,
  852. map: map,
  853. mapError: mapError,
  854. each: each,
  855. bind: bind,
  856. exists: exists,
  857. forall: forall,
  858. toOption: toOption
  859. };
  860. };
  861. var error = function (message) {
  862. var getOrThunk = function (f) {
  863. return f();
  864. };
  865. var getOrDie = function () {
  866. return die(String(message))();
  867. };
  868. var or = function (opt) {
  869. return opt;
  870. };
  871. var orThunk = function (f) {
  872. return f();
  873. };
  874. var map = function (f) {
  875. return error(message);
  876. };
  877. var mapError = function (f) {
  878. return error(f(message));
  879. };
  880. var bind = function (f) {
  881. return error(message);
  882. };
  883. var fold = function (onError, _) {
  884. return onError(message);
  885. };
  886. return {
  887. is: never,
  888. isValue: never,
  889. isError: always,
  890. getOr: identity,
  891. getOrThunk: getOrThunk,
  892. getOrDie: getOrDie,
  893. or: or,
  894. orThunk: orThunk,
  895. fold: fold,
  896. map: map,
  897. mapError: mapError,
  898. each: noop,
  899. bind: bind,
  900. exists: never,
  901. forall: always,
  902. toOption: Option.none
  903. };
  904. };
  905. var fromOption = function (opt, err) {
  906. return opt.fold(function () {
  907. return error(err);
  908. }, value);
  909. };
  910. var Result = {
  911. value: value,
  912. error: error,
  913. fromOption: fromOption
  914. };
  915. var wrap = function (delegate) {
  916. var toCached = function () {
  917. return wrap(delegate.toCached());
  918. };
  919. var bindFuture = function (f) {
  920. return wrap(delegate.bind(function (resA) {
  921. return resA.fold(function (err) {
  922. return Future.pure(Result.error(err));
  923. }, function (a) {
  924. return f(a);
  925. });
  926. }));
  927. };
  928. var bindResult = function (f) {
  929. return wrap(delegate.map(function (resA) {
  930. return resA.bind(f);
  931. }));
  932. };
  933. var mapResult = function (f) {
  934. return wrap(delegate.map(function (resA) {
  935. return resA.map(f);
  936. }));
  937. };
  938. var mapError = function (f) {
  939. return wrap(delegate.map(function (resA) {
  940. return resA.mapError(f);
  941. }));
  942. };
  943. var foldResult = function (whenError, whenValue) {
  944. return delegate.map(function (res) {
  945. return res.fold(whenError, whenValue);
  946. });
  947. };
  948. var withTimeout = function (timeout, errorThunk) {
  949. return wrap(Future.nu(function (callback) {
  950. var timedOut = false;
  951. var timer = domGlobals.setTimeout(function () {
  952. timedOut = true;
  953. callback(Result.error(errorThunk()));
  954. }, timeout);
  955. delegate.get(function (result) {
  956. if (!timedOut) {
  957. domGlobals.clearTimeout(timer);
  958. callback(result);
  959. }
  960. });
  961. }));
  962. };
  963. return __assign(__assign({}, delegate), {
  964. toCached: toCached,
  965. bindFuture: bindFuture,
  966. bindResult: bindResult,
  967. mapResult: mapResult,
  968. mapError: mapError,
  969. foldResult: foldResult,
  970. withTimeout: withTimeout
  971. });
  972. };
  973. var nu$2 = function (worker) {
  974. return wrap(Future.nu(worker));
  975. };
  976. var value$1 = function (value) {
  977. return wrap(Future.pure(Result.value(value)));
  978. };
  979. var error$1 = function (error) {
  980. return wrap(Future.pure(Result.error(error)));
  981. };
  982. var fromResult = function (result) {
  983. return wrap(Future.pure(result));
  984. };
  985. var fromFuture = function (future) {
  986. return wrap(future.map(Result.value));
  987. };
  988. var fromPromise = function (promise) {
  989. return nu$2(function (completer) {
  990. promise.then(function (value) {
  991. completer(Result.value(value));
  992. }, function (error) {
  993. completer(Result.error(error));
  994. });
  995. });
  996. };
  997. var FutureResult = {
  998. nu: nu$2,
  999. wrap: wrap,
  1000. pure: value$1,
  1001. value: value$1,
  1002. error: error$1,
  1003. fromResult: fromResult,
  1004. fromFuture: fromFuture,
  1005. fromPromise: fromPromise
  1006. };
  1007. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1008. var shallow = function (old, nu) {
  1009. return nu;
  1010. };
  1011. var deep = function (old, nu) {
  1012. var bothObjects = isObject(old) && isObject(nu);
  1013. return bothObjects ? deepMerge(old, nu) : nu;
  1014. };
  1015. var baseMerge = function (merger) {
  1016. return function () {
  1017. var objects = new Array(arguments.length);
  1018. for (var i = 0; i < objects.length; i++) {
  1019. objects[i] = arguments[i];
  1020. }
  1021. if (objects.length === 0) {
  1022. throw new Error('Can\'t merge zero objects');
  1023. }
  1024. var ret = {};
  1025. for (var j = 0; j < objects.length; j++) {
  1026. var curObject = objects[j];
  1027. for (var key in curObject) {
  1028. if (hasOwnProperty.call(curObject, key)) {
  1029. ret[key] = merger(ret[key], curObject[key]);
  1030. }
  1031. }
  1032. }
  1033. return ret;
  1034. };
  1035. };
  1036. var deepMerge = baseMerge(deep);
  1037. var merge = baseMerge(shallow);
  1038. var makeItems = function (info) {
  1039. var imageUrl = {
  1040. name: 'src',
  1041. type: 'urlinput',
  1042. filetype: 'image',
  1043. label: 'Source'
  1044. };
  1045. var imageList = info.imageList.map(function (items) {
  1046. return {
  1047. name: 'images',
  1048. type: 'selectbox',
  1049. label: 'Image list',
  1050. items: items
  1051. };
  1052. });
  1053. var imageDescription = {
  1054. name: 'alt',
  1055. type: 'input',
  1056. label: 'Image description'
  1057. };
  1058. var imageTitle = {
  1059. name: 'title',
  1060. type: 'input',
  1061. label: 'Image title'
  1062. };
  1063. var imageDimensions = {
  1064. name: 'dimensions',
  1065. type: 'sizeinput'
  1066. };
  1067. var classList = info.classList.map(function (items) {
  1068. return {
  1069. name: 'classes',
  1070. type: 'selectbox',
  1071. label: 'Class',
  1072. items: items
  1073. };
  1074. });
  1075. var caption = {
  1076. type: 'label',
  1077. label: 'Caption',
  1078. items: [{
  1079. type: 'checkbox',
  1080. name: 'caption',
  1081. label: 'Show caption'
  1082. }]
  1083. };
  1084. return flatten([
  1085. [imageUrl],
  1086. imageList.toArray(),
  1087. info.hasDescription ? [imageDescription] : [],
  1088. info.hasImageTitle ? [imageTitle] : [],
  1089. info.hasDimensions ? [imageDimensions] : [],
  1090. [{
  1091. type: 'grid',
  1092. columns: 2,
  1093. items: flatten([
  1094. classList.toArray(),
  1095. info.hasImageCaption ? [caption] : []
  1096. ])
  1097. }]
  1098. ]);
  1099. };
  1100. var makeTab = function (info) {
  1101. return {
  1102. title: 'General',
  1103. name: 'general',
  1104. items: makeItems(info)
  1105. };
  1106. };
  1107. var MainTab = {
  1108. makeTab: makeTab,
  1109. makeItems: makeItems
  1110. };
  1111. var global$2 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  1112. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
  1113. var global$4 = tinymce.util.Tools.resolve('tinymce.util.XHR');
  1114. var hasDimensions = function (editor) {
  1115. return editor.getParam('image_dimensions', true, 'boolean');
  1116. };
  1117. var hasAdvTab = function (editor) {
  1118. return editor.getParam('image_advtab', false, 'boolean');
  1119. };
  1120. var hasUploadTab = function (editor) {
  1121. return editor.getParam('image_uploadtab', true, 'boolean');
  1122. };
  1123. var getPrependUrl = function (editor) {
  1124. return editor.getParam('image_prepend_url', '', 'string');
  1125. };
  1126. var getClassList = function (editor) {
  1127. return editor.getParam('image_class_list');
  1128. };
  1129. var hasDescription = function (editor) {
  1130. return editor.getParam('image_description', true, 'boolean');
  1131. };
  1132. var hasImageTitle = function (editor) {
  1133. return editor.getParam('image_title', false, 'boolean');
  1134. };
  1135. var hasImageCaption = function (editor) {
  1136. return editor.getParam('image_caption', false, 'boolean');
  1137. };
  1138. var getImageList = function (editor) {
  1139. return editor.getParam('image_list', false);
  1140. };
  1141. var hasUploadUrl = function (editor) {
  1142. return !!getUploadUrl(editor);
  1143. };
  1144. var hasUploadHandler = function (editor) {
  1145. return !!getUploadHandler(editor);
  1146. };
  1147. var getUploadUrl = function (editor) {
  1148. return editor.getParam('images_upload_url', '', 'string');
  1149. };
  1150. var getUploadHandler = function (editor) {
  1151. return editor.getParam('images_upload_handler', undefined, 'function');
  1152. };
  1153. var getUploadBasePath = function (editor) {
  1154. return editor.getParam('images_upload_base_path', undefined, 'string');
  1155. };
  1156. var getUploadCredentials = function (editor) {
  1157. return editor.getParam('images_upload_credentials', false, 'boolean');
  1158. };
  1159. var Settings = {
  1160. hasDimensions: hasDimensions,
  1161. hasUploadTab: hasUploadTab,
  1162. hasAdvTab: hasAdvTab,
  1163. getPrependUrl: getPrependUrl,
  1164. getClassList: getClassList,
  1165. hasDescription: hasDescription,
  1166. hasImageTitle: hasImageTitle,
  1167. hasImageCaption: hasImageCaption,
  1168. getImageList: getImageList,
  1169. hasUploadUrl: hasUploadUrl,
  1170. hasUploadHandler: hasUploadHandler,
  1171. getUploadUrl: getUploadUrl,
  1172. getUploadHandler: getUploadHandler,
  1173. getUploadBasePath: getUploadBasePath,
  1174. getUploadCredentials: getUploadCredentials
  1175. };
  1176. var parseIntAndGetMax = function (val1, val2) {
  1177. return Math.max(parseInt(val1, 10), parseInt(val2, 10));
  1178. };
  1179. var getImageSize = function (url, callback) {
  1180. var img = domGlobals.document.createElement('img');
  1181. var done = function (dimensions) {
  1182. if (img.parentNode) {
  1183. img.parentNode.removeChild(img);
  1184. }
  1185. callback(dimensions);
  1186. };
  1187. img.onload = function () {
  1188. var width = parseIntAndGetMax(img.width, img.clientWidth);
  1189. var height = parseIntAndGetMax(img.height, img.clientHeight);
  1190. var dimensions = {
  1191. width: width,
  1192. height: height
  1193. };
  1194. done(Result.value(dimensions));
  1195. };
  1196. img.onerror = function () {
  1197. done(Result.error('Failed to get image dimensions for: ' + url));
  1198. };
  1199. var style = img.style;
  1200. style.visibility = 'hidden';
  1201. style.position = 'fixed';
  1202. style.bottom = style.left = '0px';
  1203. style.width = style.height = 'auto';
  1204. domGlobals.document.body.appendChild(img);
  1205. img.src = url;
  1206. };
  1207. var removePixelSuffix = function (value) {
  1208. if (value) {
  1209. value = value.replace(/px$/, '');
  1210. }
  1211. return value;
  1212. };
  1213. var addPixelSuffix = function (value) {
  1214. if (value.length > 0 && /^[0-9]+$/.test(value)) {
  1215. value += 'px';
  1216. }
  1217. return value;
  1218. };
  1219. var mergeMargins = function (css) {
  1220. if (css.margin) {
  1221. var splitMargin = String(css.margin).split(' ');
  1222. switch (splitMargin.length) {
  1223. case 1:
  1224. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1225. css['margin-right'] = css['margin-right'] || splitMargin[0];
  1226. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  1227. css['margin-left'] = css['margin-left'] || splitMargin[0];
  1228. break;
  1229. case 2:
  1230. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1231. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1232. css['margin-bottom'] = css['margin-bottom'] || splitMargin[0];
  1233. css['margin-left'] = css['margin-left'] || splitMargin[1];
  1234. break;
  1235. case 3:
  1236. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1237. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1238. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  1239. css['margin-left'] = css['margin-left'] || splitMargin[1];
  1240. break;
  1241. case 4:
  1242. css['margin-top'] = css['margin-top'] || splitMargin[0];
  1243. css['margin-right'] = css['margin-right'] || splitMargin[1];
  1244. css['margin-bottom'] = css['margin-bottom'] || splitMargin[2];
  1245. css['margin-left'] = css['margin-left'] || splitMargin[3];
  1246. }
  1247. delete css.margin;
  1248. }
  1249. return css;
  1250. };
  1251. var createImageList = function (editor, callback) {
  1252. var imageList = Settings.getImageList(editor);
  1253. if (typeof imageList === 'string') {
  1254. global$4.send({
  1255. url: imageList,
  1256. success: function (text) {
  1257. callback(JSON.parse(text));
  1258. }
  1259. });
  1260. } else if (typeof imageList === 'function') {
  1261. imageList(callback);
  1262. } else {
  1263. callback(imageList);
  1264. }
  1265. };
  1266. var waitLoadImage = function (editor, data, imgElm) {
  1267. var selectImage = function () {
  1268. imgElm.onload = imgElm.onerror = null;
  1269. if (editor.selection) {
  1270. editor.selection.select(imgElm);
  1271. editor.nodeChanged();
  1272. }
  1273. };
  1274. imgElm.onload = function () {
  1275. if (!data.width && !data.height && Settings.hasDimensions(editor)) {
  1276. editor.dom.setAttribs(imgElm, {
  1277. width: String(imgElm.clientWidth),
  1278. height: String(imgElm.clientHeight)
  1279. });
  1280. }
  1281. selectImage();
  1282. };
  1283. imgElm.onerror = selectImage;
  1284. };
  1285. var blobToDataUri = function (blob) {
  1286. return new global$3(function (resolve, reject) {
  1287. var reader = new domGlobals.FileReader();
  1288. reader.onload = function () {
  1289. resolve(reader.result);
  1290. };
  1291. reader.onerror = function () {
  1292. reject(reader.error.message);
  1293. };
  1294. reader.readAsDataURL(blob);
  1295. });
  1296. };
  1297. var isPlaceholderImage = function (imgElm) {
  1298. return imgElm.nodeName === 'IMG' && (imgElm.hasAttribute('data-mce-object') || imgElm.hasAttribute('data-mce-placeholder'));
  1299. };
  1300. var Utils = {
  1301. getImageSize: getImageSize,
  1302. removePixelSuffix: removePixelSuffix,
  1303. addPixelSuffix: addPixelSuffix,
  1304. mergeMargins: mergeMargins,
  1305. createImageList: createImageList,
  1306. waitLoadImage: waitLoadImage,
  1307. blobToDataUri: blobToDataUri,
  1308. isPlaceholderImage: isPlaceholderImage
  1309. };
  1310. var DOM = global$2.DOM;
  1311. var getHspace = function (image) {
  1312. if (image.style.marginLeft && image.style.marginRight && image.style.marginLeft === image.style.marginRight) {
  1313. return Utils.removePixelSuffix(image.style.marginLeft);
  1314. } else {
  1315. return '';
  1316. }
  1317. };
  1318. var getVspace = function (image) {
  1319. if (image.style.marginTop && image.style.marginBottom && image.style.marginTop === image.style.marginBottom) {
  1320. return Utils.removePixelSuffix(image.style.marginTop);
  1321. } else {
  1322. return '';
  1323. }
  1324. };
  1325. var getBorder = function (image) {
  1326. if (image.style.borderWidth) {
  1327. return Utils.removePixelSuffix(image.style.borderWidth);
  1328. } else {
  1329. return '';
  1330. }
  1331. };
  1332. var getAttrib = function (image, name) {
  1333. if (image.hasAttribute(name)) {
  1334. return image.getAttribute(name);
  1335. } else {
  1336. return '';
  1337. }
  1338. };
  1339. var getStyle = function (image, name) {
  1340. return image.style[name] ? image.style[name] : '';
  1341. };
  1342. var hasCaption = function (image) {
  1343. return image.parentNode !== null && image.parentNode.nodeName === 'FIGURE';
  1344. };
  1345. var setAttrib = function (image, name, value) {
  1346. image.setAttribute(name, value);
  1347. };
  1348. var wrapInFigure = function (image) {
  1349. var figureElm = DOM.create('figure', { class: 'image' });
  1350. DOM.insertAfter(figureElm, image);
  1351. figureElm.appendChild(image);
  1352. figureElm.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  1353. figureElm.contentEditable = 'false';
  1354. };
  1355. var removeFigure = function (image) {
  1356. var figureElm = image.parentNode;
  1357. DOM.insertAfter(image, figureElm);
  1358. DOM.remove(figureElm);
  1359. };
  1360. var toggleCaption = function (image) {
  1361. if (hasCaption(image)) {
  1362. removeFigure(image);
  1363. } else {
  1364. wrapInFigure(image);
  1365. }
  1366. };
  1367. var normalizeStyle = function (image, normalizeCss) {
  1368. var attrValue = image.getAttribute('style');
  1369. var value = normalizeCss(attrValue !== null ? attrValue : '');
  1370. if (value.length > 0) {
  1371. image.setAttribute('style', value);
  1372. image.setAttribute('data-mce-style', value);
  1373. } else {
  1374. image.removeAttribute('style');
  1375. }
  1376. };
  1377. var setSize = function (name, normalizeCss) {
  1378. return function (image, name, value) {
  1379. if (image.style[name]) {
  1380. image.style[name] = Utils.addPixelSuffix(value);
  1381. normalizeStyle(image, normalizeCss);
  1382. } else {
  1383. setAttrib(image, name, value);
  1384. }
  1385. };
  1386. };
  1387. var getSize = function (image, name) {
  1388. if (image.style[name]) {
  1389. return Utils.removePixelSuffix(image.style[name]);
  1390. } else {
  1391. return getAttrib(image, name);
  1392. }
  1393. };
  1394. var setHspace = function (image, value) {
  1395. var pxValue = Utils.addPixelSuffix(value);
  1396. image.style.marginLeft = pxValue;
  1397. image.style.marginRight = pxValue;
  1398. };
  1399. var setVspace = function (image, value) {
  1400. var pxValue = Utils.addPixelSuffix(value);
  1401. image.style.marginTop = pxValue;
  1402. image.style.marginBottom = pxValue;
  1403. };
  1404. var setBorder = function (image, value) {
  1405. var pxValue = Utils.addPixelSuffix(value);
  1406. image.style.borderWidth = pxValue;
  1407. };
  1408. var setBorderStyle = function (image, value) {
  1409. image.style.borderStyle = value;
  1410. };
  1411. var getBorderStyle = function (image) {
  1412. return getStyle(image, 'borderStyle');
  1413. };
  1414. var isFigure = function (elm) {
  1415. return elm.nodeName === 'FIGURE';
  1416. };
  1417. var isImage = function (elm) {
  1418. return elm.nodeName === 'IMG';
  1419. };
  1420. var defaultData = function () {
  1421. return {
  1422. src: '',
  1423. alt: '',
  1424. title: '',
  1425. width: '',
  1426. height: '',
  1427. class: '',
  1428. style: '',
  1429. caption: false,
  1430. hspace: '',
  1431. vspace: '',
  1432. border: '',
  1433. borderStyle: ''
  1434. };
  1435. };
  1436. var getStyleValue = function (normalizeCss, data) {
  1437. var image = domGlobals.document.createElement('img');
  1438. setAttrib(image, 'style', data.style);
  1439. if (getHspace(image) || data.hspace !== '') {
  1440. setHspace(image, data.hspace);
  1441. }
  1442. if (getVspace(image) || data.vspace !== '') {
  1443. setVspace(image, data.vspace);
  1444. }
  1445. if (getBorder(image) || data.border !== '') {
  1446. setBorder(image, data.border);
  1447. }
  1448. if (getBorderStyle(image) || data.borderStyle !== '') {
  1449. setBorderStyle(image, data.borderStyle);
  1450. }
  1451. return normalizeCss(image.getAttribute('style'));
  1452. };
  1453. var create = function (normalizeCss, data) {
  1454. var image = domGlobals.document.createElement('img');
  1455. write(normalizeCss, merge(data, { caption: false }), image);
  1456. setAttrib(image, 'alt', data.alt);
  1457. if (data.caption) {
  1458. var figure = DOM.create('figure', { class: 'image' });
  1459. figure.appendChild(image);
  1460. figure.appendChild(DOM.create('figcaption', { contentEditable: 'true' }, 'Caption'));
  1461. figure.contentEditable = 'false';
  1462. return figure;
  1463. } else {
  1464. return image;
  1465. }
  1466. };
  1467. var read = function (normalizeCss, image) {
  1468. return {
  1469. src: getAttrib(image, 'src'),
  1470. alt: getAttrib(image, 'alt'),
  1471. title: getAttrib(image, 'title'),
  1472. width: getSize(image, 'width'),
  1473. height: getSize(image, 'height'),
  1474. class: getAttrib(image, 'class'),
  1475. style: normalizeCss(getAttrib(image, 'style')),
  1476. caption: hasCaption(image),
  1477. hspace: getHspace(image),
  1478. vspace: getVspace(image),
  1479. border: getBorder(image),
  1480. borderStyle: getStyle(image, 'borderStyle')
  1481. };
  1482. };
  1483. var updateProp = function (image, oldData, newData, name, set) {
  1484. if (newData[name] !== oldData[name]) {
  1485. set(image, name, newData[name]);
  1486. }
  1487. };
  1488. var normalized = function (set, normalizeCss) {
  1489. return function (image, name, value) {
  1490. set(image, value);
  1491. normalizeStyle(image, normalizeCss);
  1492. };
  1493. };
  1494. var write = function (normalizeCss, newData, image) {
  1495. var oldData = read(normalizeCss, image);
  1496. updateProp(image, oldData, newData, 'caption', function (image, _name, _value) {
  1497. return toggleCaption(image);
  1498. });
  1499. updateProp(image, oldData, newData, 'src', setAttrib);
  1500. updateProp(image, oldData, newData, 'alt', setAttrib);
  1501. updateProp(image, oldData, newData, 'title', setAttrib);
  1502. updateProp(image, oldData, newData, 'width', setSize('width', normalizeCss));
  1503. updateProp(image, oldData, newData, 'height', setSize('height', normalizeCss));
  1504. updateProp(image, oldData, newData, 'class', setAttrib);
  1505. updateProp(image, oldData, newData, 'style', normalized(function (image, value) {
  1506. return setAttrib(image, 'style', value);
  1507. }, normalizeCss));
  1508. updateProp(image, oldData, newData, 'hspace', normalized(setHspace, normalizeCss));
  1509. updateProp(image, oldData, newData, 'vspace', normalized(setVspace, normalizeCss));
  1510. updateProp(image, oldData, newData, 'border', normalized(setBorder, normalizeCss));
  1511. updateProp(image, oldData, newData, 'borderStyle', normalized(setBorderStyle, normalizeCss));
  1512. };
  1513. var normalizeCss = function (editor, cssText) {
  1514. var css = editor.dom.styles.parse(cssText);
  1515. var mergedCss = Utils.mergeMargins(css);
  1516. var compressed = editor.dom.styles.parse(editor.dom.styles.serialize(mergedCss));
  1517. return editor.dom.styles.serialize(compressed);
  1518. };
  1519. var getSelectedImage = function (editor) {
  1520. var imgElm = editor.selection.getNode();
  1521. var figureElm = editor.dom.getParent(imgElm, 'figure.image');
  1522. if (figureElm) {
  1523. return editor.dom.select('img', figureElm)[0];
  1524. }
  1525. if (imgElm && (imgElm.nodeName !== 'IMG' || Utils.isPlaceholderImage(imgElm))) {
  1526. return null;
  1527. }
  1528. return imgElm;
  1529. };
  1530. var splitTextBlock = function (editor, figure) {
  1531. var dom = editor.dom;
  1532. var textBlock = dom.getParent(figure.parentNode, function (node) {
  1533. return editor.schema.getTextBlockElements()[node.nodeName];
  1534. }, editor.getBody());
  1535. if (textBlock) {
  1536. return dom.split(textBlock, figure);
  1537. } else {
  1538. return figure;
  1539. }
  1540. };
  1541. var readImageDataFromSelection = function (editor) {
  1542. var image = getSelectedImage(editor);
  1543. return image ? read(function (css) {
  1544. return normalizeCss(editor, css);
  1545. }, image) : defaultData();
  1546. };
  1547. var insertImageAtCaret = function (editor, data) {
  1548. var elm = create(function (css) {
  1549. return normalizeCss(editor, css);
  1550. }, data);
  1551. editor.dom.setAttrib(elm, 'data-mce-id', '__mcenew');
  1552. editor.focus();
  1553. editor.selection.setContent(elm.outerHTML);
  1554. var insertedElm = editor.dom.select('*[data-mce-id="__mcenew"]')[0];
  1555. editor.dom.setAttrib(insertedElm, 'data-mce-id', null);
  1556. if (isFigure(insertedElm)) {
  1557. var figure = splitTextBlock(editor, insertedElm);
  1558. editor.selection.select(figure);
  1559. } else {
  1560. editor.selection.select(insertedElm);
  1561. }
  1562. };
  1563. var syncSrcAttr = function (editor, image) {
  1564. editor.dom.setAttrib(image, 'src', image.getAttribute('src'));
  1565. };
  1566. var deleteImage = function (editor, image) {
  1567. if (image) {
  1568. var elm = editor.dom.is(image.parentNode, 'figure.image') ? image.parentNode : image;
  1569. editor.dom.remove(elm);
  1570. editor.focus();
  1571. editor.nodeChanged();
  1572. if (editor.dom.isEmpty(editor.getBody())) {
  1573. editor.setContent('');
  1574. editor.selection.setCursorLocation();
  1575. }
  1576. }
  1577. };
  1578. var writeImageDataToSelection = function (editor, data) {
  1579. var image = getSelectedImage(editor);
  1580. write(function (css) {
  1581. return normalizeCss(editor, css);
  1582. }, data, image);
  1583. syncSrcAttr(editor, image);
  1584. if (isFigure(image.parentNode)) {
  1585. var figure = image.parentNode;
  1586. splitTextBlock(editor, figure);
  1587. editor.selection.select(image.parentNode);
  1588. } else {
  1589. editor.selection.select(image);
  1590. Utils.waitLoadImage(editor, data, image);
  1591. }
  1592. };
  1593. var insertOrUpdateImage = function (editor, data) {
  1594. var image = getSelectedImage(editor);
  1595. if (image) {
  1596. if (data.src) {
  1597. writeImageDataToSelection(editor, data);
  1598. } else {
  1599. deleteImage(editor, image);
  1600. }
  1601. } else if (data.src) {
  1602. insertImageAtCaret(editor, data);
  1603. }
  1604. };
  1605. var findMap = function (arr, f) {
  1606. for (var i = 0; i < arr.length; i++) {
  1607. var r = f(arr[i], i);
  1608. if (r.isSome()) {
  1609. return r;
  1610. }
  1611. }
  1612. return Option.none();
  1613. };
  1614. var global$5 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  1615. var getValue = function (item) {
  1616. return isString(item.value) ? item.value : '';
  1617. };
  1618. var sanitizeList = function (list, extractValue) {
  1619. var out = [];
  1620. global$5.each(list, function (item) {
  1621. var text = isString(item.text) ? item.text : isString(item.title) ? item.title : '';
  1622. if (item.menu !== undefined) {
  1623. var items = sanitizeList(item.menu, extractValue);
  1624. out.push({
  1625. text: text,
  1626. items: items
  1627. });
  1628. } else {
  1629. var value = extractValue(item);
  1630. out.push({
  1631. text: text,
  1632. value: value
  1633. });
  1634. }
  1635. });
  1636. return out;
  1637. };
  1638. var sanitizer = function (extracter) {
  1639. if (extracter === void 0) {
  1640. extracter = getValue;
  1641. }
  1642. return function (list) {
  1643. if (list) {
  1644. return Option.from(list).map(function (list) {
  1645. return sanitizeList(list, extracter);
  1646. });
  1647. } else {
  1648. return Option.none();
  1649. }
  1650. };
  1651. };
  1652. var sanitize = function (list) {
  1653. return sanitizer(getValue)(list);
  1654. };
  1655. var isGroup = function (item) {
  1656. return Object.prototype.hasOwnProperty.call(item, 'items');
  1657. };
  1658. var findEntryDelegate = function (list, value) {
  1659. return findMap(list, function (item) {
  1660. if (isGroup(item)) {
  1661. return findEntryDelegate(item.items, value);
  1662. } else if (item.value === value) {
  1663. return Option.some(item);
  1664. } else {
  1665. return Option.none();
  1666. }
  1667. });
  1668. };
  1669. var findEntry = function (optList, value) {
  1670. return optList.bind(function (list) {
  1671. return findEntryDelegate(list, value);
  1672. });
  1673. };
  1674. var ListUtils = {
  1675. sanitizer: sanitizer,
  1676. sanitize: sanitize,
  1677. findEntry: findEntry
  1678. };
  1679. var pathJoin = function (path1, path2) {
  1680. if (path1) {
  1681. return path1.replace(/\/$/, '') + '/' + path2.replace(/^\//, '');
  1682. }
  1683. return path2;
  1684. };
  1685. function Uploader (settings) {
  1686. var defaultHandler = function (blobInfo, success, failure, progress) {
  1687. var xhr, formData;
  1688. xhr = new domGlobals.XMLHttpRequest();
  1689. xhr.open('POST', settings.url);
  1690. xhr.withCredentials = settings.credentials;
  1691. xhr.upload.onprogress = function (e) {
  1692. progress(e.loaded / e.total * 100);
  1693. };
  1694. xhr.onerror = function () {
  1695. failure('Image upload failed due to a XHR Transport error. Code: ' + xhr.status);
  1696. };
  1697. xhr.onload = function () {
  1698. var json;
  1699. if (xhr.status < 200 || xhr.status >= 300) {
  1700. failure('HTTP Error: ' + xhr.status);
  1701. return;
  1702. }
  1703. json = JSON.parse(xhr.responseText);
  1704. if (!json || typeof json.location !== 'string') {
  1705. failure('Invalid JSON: ' + xhr.responseText);
  1706. return;
  1707. }
  1708. success(pathJoin(settings.basePath, json.location));
  1709. };
  1710. formData = new domGlobals.FormData();
  1711. formData.append('file', blobInfo.blob(), blobInfo.filename());
  1712. xhr.send(formData);
  1713. };
  1714. var uploadBlob = function (blobInfo, handler) {
  1715. return new global$3(function (resolve, reject) {
  1716. try {
  1717. handler(blobInfo, resolve, reject, noop);
  1718. } catch (ex) {
  1719. reject(ex.message);
  1720. }
  1721. });
  1722. };
  1723. var isDefaultHandler = function (handler) {
  1724. return handler === defaultHandler;
  1725. };
  1726. var upload = function (blobInfo) {
  1727. return !settings.url && isDefaultHandler(settings.handler) ? global$3.reject('Upload url missing from the settings.') : uploadBlob(blobInfo, settings.handler);
  1728. };
  1729. settings = global$5.extend({
  1730. credentials: false,
  1731. handler: defaultHandler
  1732. }, settings);
  1733. return { upload: upload };
  1734. }
  1735. var makeTab$1 = function (info) {
  1736. return {
  1737. title: 'Advanced',
  1738. name: 'advanced',
  1739. items: [
  1740. {
  1741. type: 'input',
  1742. label: 'Style',
  1743. name: 'style'
  1744. },
  1745. {
  1746. type: 'grid',
  1747. columns: 2,
  1748. items: [
  1749. {
  1750. type: 'input',
  1751. label: 'Vertical space',
  1752. name: 'vspace',
  1753. inputMode: 'numeric'
  1754. },
  1755. {
  1756. type: 'input',
  1757. label: 'Horizontal space',
  1758. name: 'hspace',
  1759. inputMode: 'numeric'
  1760. },
  1761. {
  1762. type: 'input',
  1763. label: 'Border width',
  1764. name: 'border',
  1765. inputMode: 'numeric'
  1766. },
  1767. {
  1768. type: 'selectbox',
  1769. name: 'borderstyle',
  1770. label: 'Border style',
  1771. items: [
  1772. {
  1773. text: 'Select...',
  1774. value: ''
  1775. },
  1776. {
  1777. text: 'Solid',
  1778. value: 'solid'
  1779. },
  1780. {
  1781. text: 'Dotted',
  1782. value: 'dotted'
  1783. },
  1784. {
  1785. text: 'Dashed',
  1786. value: 'dashed'
  1787. },
  1788. {
  1789. text: 'Double',
  1790. value: 'double'
  1791. },
  1792. {
  1793. text: 'Groove',
  1794. value: 'groove'
  1795. },
  1796. {
  1797. text: 'Ridge',
  1798. value: 'ridge'
  1799. },
  1800. {
  1801. text: 'Inset',
  1802. value: 'inset'
  1803. },
  1804. {
  1805. text: 'Outset',
  1806. value: 'outset'
  1807. },
  1808. {
  1809. text: 'None',
  1810. value: 'none'
  1811. },
  1812. {
  1813. text: 'Hidden',
  1814. value: 'hidden'
  1815. }
  1816. ]
  1817. }
  1818. ]
  1819. }
  1820. ]
  1821. };
  1822. };
  1823. var AdvTab = { makeTab: makeTab$1 };
  1824. var collect = function (editor) {
  1825. var urlListSanitizer = ListUtils.sanitizer(function (item) {
  1826. return editor.convertURL(item.value || item.url, 'src');
  1827. });
  1828. var futureImageList = Future.nu(function (completer) {
  1829. Utils.createImageList(editor, function (imageList) {
  1830. completer(urlListSanitizer(imageList).map(function (items) {
  1831. return flatten([
  1832. [{
  1833. text: 'None',
  1834. value: ''
  1835. }],
  1836. items
  1837. ]);
  1838. }));
  1839. });
  1840. });
  1841. var classList = ListUtils.sanitize(Settings.getClassList(editor));
  1842. var hasAdvTab = Settings.hasAdvTab(editor);
  1843. var hasUploadTab = Settings.hasUploadTab(editor);
  1844. var hasUploadUrl = Settings.hasUploadUrl(editor);
  1845. var hasUploadHandler = Settings.hasUploadHandler(editor);
  1846. var image = readImageDataFromSelection(editor);
  1847. var hasDescription = Settings.hasDescription(editor);
  1848. var hasImageTitle = Settings.hasImageTitle(editor);
  1849. var hasDimensions = Settings.hasDimensions(editor);
  1850. var hasImageCaption = Settings.hasImageCaption(editor);
  1851. var url = Settings.getUploadUrl(editor);
  1852. var basePath = Settings.getUploadBasePath(editor);
  1853. var credentials = Settings.getUploadCredentials(editor);
  1854. var handler = Settings.getUploadHandler(editor);
  1855. var prependURL = Option.some(Settings.getPrependUrl(editor)).filter(function (preUrl) {
  1856. return isString(preUrl) && preUrl.length > 0;
  1857. });
  1858. return futureImageList.map(function (imageList) {
  1859. return {
  1860. image: image,
  1861. imageList: imageList,
  1862. classList: classList,
  1863. hasAdvTab: hasAdvTab,
  1864. hasUploadTab: hasUploadTab,
  1865. hasUploadUrl: hasUploadUrl,
  1866. hasUploadHandler: hasUploadHandler,
  1867. hasDescription: hasDescription,
  1868. hasImageTitle: hasImageTitle,
  1869. hasDimensions: hasDimensions,
  1870. hasImageCaption: hasImageCaption,
  1871. url: url,
  1872. basePath: basePath,
  1873. credentials: credentials,
  1874. handler: handler,
  1875. prependURL: prependURL
  1876. };
  1877. });
  1878. };
  1879. var makeTab$2 = function (info) {
  1880. var items = [{
  1881. type: 'dropzone',
  1882. name: 'fileinput'
  1883. }];
  1884. return {
  1885. title: 'Upload',
  1886. name: 'upload',
  1887. items: items
  1888. };
  1889. };
  1890. var UploadTab = { makeTab: makeTab$2 };
  1891. var createState = function (info) {
  1892. return {
  1893. prevImage: ListUtils.findEntry(info.imageList, info.image.src),
  1894. prevAlt: info.image.alt,
  1895. open: true
  1896. };
  1897. };
  1898. var fromImageData = function (image) {
  1899. return {
  1900. src: {
  1901. value: image.src,
  1902. meta: {}
  1903. },
  1904. images: image.src,
  1905. alt: image.alt,
  1906. title: image.title,
  1907. dimensions: {
  1908. width: image.width,
  1909. height: image.height
  1910. },
  1911. classes: image.class,
  1912. caption: image.caption,
  1913. style: image.style,
  1914. vspace: image.vspace,
  1915. border: image.border,
  1916. hspace: image.hspace,
  1917. borderstyle: image.borderStyle,
  1918. fileinput: []
  1919. };
  1920. };
  1921. var toImageData = function (data) {
  1922. return {
  1923. src: data.src.value,
  1924. alt: data.alt,
  1925. title: data.title,
  1926. width: data.dimensions.width,
  1927. height: data.dimensions.height,
  1928. class: data.classes,
  1929. style: data.style,
  1930. caption: data.caption,
  1931. hspace: data.hspace,
  1932. vspace: data.vspace,
  1933. border: data.border,
  1934. borderStyle: data.borderstyle
  1935. };
  1936. };
  1937. var addPrependUrl2 = function (info, srcURL) {
  1938. if (!/^(?:[a-zA-Z]+:)?\/\//.test(srcURL)) {
  1939. return info.prependURL.bind(function (prependUrl) {
  1940. if (srcURL.substring(0, prependUrl.length) !== prependUrl) {
  1941. return Option.some(prependUrl + srcURL);
  1942. }
  1943. return Option.none();
  1944. });
  1945. }
  1946. return Option.none();
  1947. };
  1948. var addPrependUrl = function (info, api) {
  1949. var data = api.getData();
  1950. addPrependUrl2(info, data.src.value).each(function (srcURL) {
  1951. api.setData({
  1952. src: {
  1953. value: srcURL,
  1954. meta: data.src.meta
  1955. }
  1956. });
  1957. });
  1958. };
  1959. var formFillFromMeta2 = function (info, data, meta) {
  1960. if (info.hasDescription && isString(meta.alt)) {
  1961. data.alt = meta.alt;
  1962. }
  1963. if (info.hasImageTitle && isString(meta.title)) {
  1964. data.title = meta.title;
  1965. }
  1966. if (info.hasDimensions) {
  1967. if (isString(meta.width)) {
  1968. data.dimensions.width = meta.width;
  1969. }
  1970. if (isString(meta.height)) {
  1971. data.dimensions.height = meta.height;
  1972. }
  1973. }
  1974. if (isString(meta.class)) {
  1975. ListUtils.findEntry(info.classList, meta.class).each(function (entry) {
  1976. data.classes = entry.value;
  1977. });
  1978. }
  1979. if (info.hasImageCaption) {
  1980. if (isBoolean(meta.caption)) {
  1981. data.caption = meta.caption;
  1982. }
  1983. }
  1984. if (info.hasAdvTab) {
  1985. if (isString(meta.vspace)) {
  1986. data.vspace = meta.vspace;
  1987. }
  1988. if (isString(meta.border)) {
  1989. data.border = meta.border;
  1990. }
  1991. if (isString(meta.hspace)) {
  1992. data.hspace = meta.hspace;
  1993. }
  1994. if (isString(meta.borderstyle)) {
  1995. data.borderstyle = meta.borderstyle;
  1996. }
  1997. }
  1998. };
  1999. var formFillFromMeta = function (info, api) {
  2000. var data = api.getData();
  2001. var meta = data.src.meta;
  2002. if (meta !== undefined) {
  2003. var newData = deepMerge({}, data);
  2004. formFillFromMeta2(info, newData, meta);
  2005. api.setData(newData);
  2006. }
  2007. };
  2008. var calculateImageSize = function (helpers, info, state, api) {
  2009. var data = api.getData();
  2010. var url = data.src.value;
  2011. var meta = data.src.meta || {};
  2012. if (!meta.width && !meta.height && info.hasDimensions) {
  2013. helpers.imageSize(url).get(function (result) {
  2014. result.each(function (size) {
  2015. if (state.open) {
  2016. api.setData({ dimensions: size });
  2017. }
  2018. });
  2019. });
  2020. }
  2021. };
  2022. var updateImagesDropdown = function (info, state, api) {
  2023. var data = api.getData();
  2024. var image = ListUtils.findEntry(info.imageList, data.src.value);
  2025. state.prevImage = image;
  2026. api.setData({
  2027. images: image.map(function (entry) {
  2028. return entry.value;
  2029. }).getOr('')
  2030. });
  2031. };
  2032. var changeSrc = function (helpers, info, state, api) {
  2033. addPrependUrl(info, api);
  2034. formFillFromMeta(info, api);
  2035. calculateImageSize(helpers, info, state, api);
  2036. updateImagesDropdown(info, state, api);
  2037. };
  2038. var changeImages = function (helpers, info, state, api) {
  2039. var data = api.getData();
  2040. var image = ListUtils.findEntry(info.imageList, data.images);
  2041. image.each(function (img) {
  2042. var updateAlt = data.alt === '' || state.prevImage.map(function (image) {
  2043. return image.text === data.alt;
  2044. }).getOr(false);
  2045. if (updateAlt) {
  2046. if (img.value === '') {
  2047. api.setData({
  2048. src: img,
  2049. alt: state.prevAlt
  2050. });
  2051. } else {
  2052. api.setData({
  2053. src: img,
  2054. alt: img.text
  2055. });
  2056. }
  2057. } else {
  2058. api.setData({ src: img });
  2059. }
  2060. });
  2061. state.prevImage = image;
  2062. changeSrc(helpers, info, state, api);
  2063. };
  2064. var calcVSpace = function (css) {
  2065. var matchingTopBottom = css['margin-top'] && css['margin-bottom'] && css['margin-top'] === css['margin-bottom'];
  2066. return matchingTopBottom ? Utils.removePixelSuffix(String(css['margin-top'])) : '';
  2067. };
  2068. var calcHSpace = function (css) {
  2069. var matchingLeftRight = css['margin-right'] && css['margin-left'] && css['margin-right'] === css['margin-left'];
  2070. return matchingLeftRight ? Utils.removePixelSuffix(String(css['margin-right'])) : '';
  2071. };
  2072. var calcBorderWidth = function (css) {
  2073. return css['border-width'] ? Utils.removePixelSuffix(String(css['border-width'])) : '';
  2074. };
  2075. var calcBorderStyle = function (css) {
  2076. return css['border-style'] ? String(css['border-style']) : '';
  2077. };
  2078. var calcStyle = function (parseStyle, serializeStyle, css) {
  2079. return serializeStyle(parseStyle(serializeStyle(css)));
  2080. };
  2081. var changeStyle2 = function (parseStyle, serializeStyle, data) {
  2082. var css = Utils.mergeMargins(parseStyle(data.style));
  2083. var dataCopy = deepMerge({}, data);
  2084. dataCopy.vspace = calcVSpace(css);
  2085. dataCopy.hspace = calcHSpace(css);
  2086. dataCopy.border = calcBorderWidth(css);
  2087. dataCopy.borderstyle = calcBorderStyle(css);
  2088. dataCopy.style = calcStyle(parseStyle, serializeStyle, css);
  2089. return dataCopy;
  2090. };
  2091. var changeStyle = function (helpers, api) {
  2092. var data = api.getData();
  2093. var newData = changeStyle2(helpers.parseStyle, helpers.serializeStyle, data);
  2094. api.setData(newData);
  2095. };
  2096. var changeAStyle = function (helpers, info, api) {
  2097. var data = deepMerge(fromImageData(info.image), api.getData());
  2098. var style = getStyleValue(helpers.normalizeCss, toImageData(data));
  2099. api.setData({ style: style });
  2100. };
  2101. var changeFileInput = function (helpers, info, state, api) {
  2102. var data = api.getData();
  2103. api.block('Uploading image');
  2104. head(data.fileinput).fold(function () {
  2105. api.unblock();
  2106. }, function (file) {
  2107. var blobUri = domGlobals.URL.createObjectURL(file);
  2108. var uploader = Uploader({
  2109. url: info.url,
  2110. basePath: info.basePath,
  2111. credentials: info.credentials,
  2112. handler: info.handler
  2113. });
  2114. var finalize = function () {
  2115. api.unblock();
  2116. domGlobals.URL.revokeObjectURL(blobUri);
  2117. };
  2118. Utils.blobToDataUri(file).then(function (dataUrl) {
  2119. var blobInfo = helpers.createBlobCache(file, blobUri, dataUrl);
  2120. uploader.upload(blobInfo).then(function (url) {
  2121. api.setData({
  2122. src: {
  2123. value: url,
  2124. meta: {}
  2125. }
  2126. });
  2127. api.showTab('general');
  2128. changeSrc(helpers, info, state, api);
  2129. finalize();
  2130. }).catch(function (err) {
  2131. finalize();
  2132. helpers.alertErr(api, err);
  2133. });
  2134. });
  2135. });
  2136. };
  2137. var changeHandler = function (helpers, info, state) {
  2138. return function (api, evt) {
  2139. if (evt.name === 'src') {
  2140. changeSrc(helpers, info, state, api);
  2141. } else if (evt.name === 'images') {
  2142. changeImages(helpers, info, state, api);
  2143. } else if (evt.name === 'alt') {
  2144. state.prevAlt = api.getData().alt;
  2145. } else if (evt.name === 'style') {
  2146. changeStyle(helpers, api);
  2147. } else if (evt.name === 'vspace' || evt.name === 'hspace' || evt.name === 'border' || evt.name === 'borderstyle') {
  2148. changeAStyle(helpers, info, api);
  2149. } else if (evt.name === 'fileinput') {
  2150. changeFileInput(helpers, info, state, api);
  2151. }
  2152. };
  2153. };
  2154. var closeHandler = function (state) {
  2155. return function () {
  2156. state.open = false;
  2157. };
  2158. };
  2159. var makeDialogBody = function (info) {
  2160. if (info.hasAdvTab || info.hasUploadUrl || info.hasUploadHandler) {
  2161. var tabPanel = {
  2162. type: 'tabpanel',
  2163. tabs: flatten([
  2164. [MainTab.makeTab(info)],
  2165. info.hasAdvTab ? [AdvTab.makeTab(info)] : [],
  2166. info.hasUploadTab && (info.hasUploadUrl || info.hasUploadHandler) ? [UploadTab.makeTab(info)] : []
  2167. ])
  2168. };
  2169. return tabPanel;
  2170. } else {
  2171. var panel = {
  2172. type: 'panel',
  2173. items: MainTab.makeItems(info)
  2174. };
  2175. return panel;
  2176. }
  2177. };
  2178. var makeDialog = function (helpers) {
  2179. return function (info) {
  2180. var state = createState(info);
  2181. return {
  2182. title: 'Insert/Edit Image',
  2183. size: 'normal',
  2184. body: makeDialogBody(info),
  2185. buttons: [
  2186. {
  2187. type: 'cancel',
  2188. name: 'cancel',
  2189. text: 'Cancel'
  2190. },
  2191. {
  2192. type: 'submit',
  2193. name: 'save',
  2194. text: 'Save',
  2195. primary: true
  2196. }
  2197. ],
  2198. initialData: fromImageData(info.image),
  2199. onSubmit: helpers.onSubmit(info),
  2200. onChange: changeHandler(helpers, info, state),
  2201. onClose: closeHandler(state)
  2202. };
  2203. };
  2204. };
  2205. var submitHandler = function (editor) {
  2206. return function (info) {
  2207. return function (api) {
  2208. var data = deepMerge(fromImageData(info.image), api.getData());
  2209. editor.undoManager.transact(function () {
  2210. insertOrUpdateImage(editor, toImageData(data));
  2211. });
  2212. editor.editorUpload.uploadImagesAuto();
  2213. api.close();
  2214. };
  2215. };
  2216. };
  2217. var imageSize = function (editor) {
  2218. return function (url) {
  2219. return FutureResult.nu(function (completer) {
  2220. Utils.getImageSize(editor.documentBaseURI.toAbsolute(url), function (data) {
  2221. var result = data.map(function (dimensions) {
  2222. return {
  2223. width: String(dimensions.width),
  2224. height: String(dimensions.height)
  2225. };
  2226. });
  2227. completer(result);
  2228. });
  2229. });
  2230. };
  2231. };
  2232. var createBlobCache = function (editor) {
  2233. return function (file, blobUri, dataUrl) {
  2234. return editor.editorUpload.blobCache.create({
  2235. blob: file,
  2236. blobUri: blobUri,
  2237. name: file.name ? file.name.replace(/\.[^\.]+$/, '') : null,
  2238. base64: dataUrl.split(',')[1]
  2239. });
  2240. };
  2241. };
  2242. var alertErr = function (editor) {
  2243. return function (api, message) {
  2244. editor.windowManager.alert(message, api.close);
  2245. };
  2246. };
  2247. var normalizeCss$1 = function (editor) {
  2248. return function (cssText) {
  2249. return normalizeCss(editor, cssText);
  2250. };
  2251. };
  2252. var parseStyle = function (editor) {
  2253. return function (cssText) {
  2254. return editor.dom.parseStyle(cssText);
  2255. };
  2256. };
  2257. var serializeStyle = function (editor) {
  2258. return function (stylesArg, name) {
  2259. return editor.dom.serializeStyle(stylesArg, name);
  2260. };
  2261. };
  2262. var Dialog = function (editor) {
  2263. var helpers = {
  2264. onSubmit: submitHandler(editor),
  2265. imageSize: imageSize(editor),
  2266. createBlobCache: createBlobCache(editor),
  2267. alertErr: alertErr(editor),
  2268. normalizeCss: normalizeCss$1(editor),
  2269. parseStyle: parseStyle(editor),
  2270. serializeStyle: serializeStyle(editor)
  2271. };
  2272. var open = function () {
  2273. return collect(editor).map(makeDialog(helpers)).get(function (spec) {
  2274. editor.windowManager.open(spec);
  2275. });
  2276. };
  2277. return { open: open };
  2278. };
  2279. var register = function (editor) {
  2280. editor.addCommand('mceImage', Dialog(editor).open);
  2281. };
  2282. var Commands = { register: register };
  2283. var hasImageClass = function (node) {
  2284. var className = node.attr('class');
  2285. return className && /\bimage\b/.test(className);
  2286. };
  2287. var toggleContentEditableState = function (state) {
  2288. return function (nodes) {
  2289. var i = nodes.length;
  2290. var toggleContentEditable = function (node) {
  2291. node.attr('contenteditable', state ? 'true' : null);
  2292. };
  2293. while (i--) {
  2294. var node = nodes[i];
  2295. if (hasImageClass(node)) {
  2296. node.attr('contenteditable', state ? 'false' : null);
  2297. global$5.each(node.getAll('figcaption'), toggleContentEditable);
  2298. }
  2299. }
  2300. };
  2301. };
  2302. var setup = function (editor) {
  2303. editor.on('PreInit', function () {
  2304. editor.parser.addNodeFilter('figure', toggleContentEditableState(true));
  2305. editor.serializer.addNodeFilter('figure', toggleContentEditableState(false));
  2306. });
  2307. };
  2308. var FilterContent = { setup: setup };
  2309. var register$1 = function (editor) {
  2310. editor.ui.registry.addToggleButton('image', {
  2311. icon: 'image',
  2312. tooltip: 'Insert/edit image',
  2313. onAction: Dialog(editor).open,
  2314. onSetup: function (buttonApi) {
  2315. return editor.selection.selectorChangedWithUnbind('img:not([data-mce-object],[data-mce-placeholder]),figure.image', buttonApi.setActive).unbind;
  2316. }
  2317. });
  2318. editor.ui.registry.addMenuItem('image', {
  2319. icon: 'image',
  2320. text: 'Image...',
  2321. onAction: Dialog(editor).open
  2322. });
  2323. editor.ui.registry.addContextMenu('image', {
  2324. update: function (element) {
  2325. return isFigure(element) || isImage(element) && !Utils.isPlaceholderImage(element) ? ['image'] : [];
  2326. }
  2327. });
  2328. };
  2329. var Buttons = { register: register$1 };
  2330. function Plugin () {
  2331. global$1.add('image', function (editor) {
  2332. FilterContent.setup(editor);
  2333. Buttons.register(editor);
  2334. Commands.register(editor);
  2335. });
  2336. }
  2337. Plugin();
  2338. }(window));