plugin.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388
  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.2.0 (2020-02-13)
  8. */
  9. (function () {
  10. 'use strict';
  11. var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
  12. var __assign = function () {
  13. __assign = Object.assign || function __assign(t) {
  14. for (var s, i = 1, n = arguments.length; i < n; i++) {
  15. s = arguments[i];
  16. for (var p in s)
  17. if (Object.prototype.hasOwnProperty.call(s, p))
  18. t[p] = s[p];
  19. }
  20. return t;
  21. };
  22. return __assign.apply(this, arguments);
  23. };
  24. var noop = function () {
  25. };
  26. var constant = function (value) {
  27. return function () {
  28. return value;
  29. };
  30. };
  31. var never = constant(false);
  32. var always = constant(true);
  33. var none = function () {
  34. return NONE;
  35. };
  36. var NONE = function () {
  37. var eq = function (o) {
  38. return o.isNone();
  39. };
  40. var call = function (thunk) {
  41. return thunk();
  42. };
  43. var id = function (n) {
  44. return n;
  45. };
  46. var me = {
  47. fold: function (n, s) {
  48. return n();
  49. },
  50. is: never,
  51. isSome: never,
  52. isNone: always,
  53. getOr: id,
  54. getOrThunk: call,
  55. getOrDie: function (msg) {
  56. throw new Error(msg || 'error: getOrDie called on none.');
  57. },
  58. getOrNull: constant(null),
  59. getOrUndefined: constant(undefined),
  60. or: id,
  61. orThunk: call,
  62. map: none,
  63. each: noop,
  64. bind: none,
  65. exists: never,
  66. forall: always,
  67. filter: none,
  68. equals: eq,
  69. equals_: eq,
  70. toArray: function () {
  71. return [];
  72. },
  73. toString: constant('none()')
  74. };
  75. if (Object.freeze) {
  76. Object.freeze(me);
  77. }
  78. return me;
  79. }();
  80. var some = function (a) {
  81. var constant_a = constant(a);
  82. var self = function () {
  83. return me;
  84. };
  85. var bind = function (f) {
  86. return f(a);
  87. };
  88. var me = {
  89. fold: function (n, s) {
  90. return s(a);
  91. },
  92. is: function (v) {
  93. return a === v;
  94. },
  95. isSome: always,
  96. isNone: never,
  97. getOr: constant_a,
  98. getOrThunk: constant_a,
  99. getOrDie: constant_a,
  100. getOrNull: constant_a,
  101. getOrUndefined: constant_a,
  102. or: self,
  103. orThunk: self,
  104. map: function (f) {
  105. return some(f(a));
  106. },
  107. each: function (f) {
  108. f(a);
  109. },
  110. bind: bind,
  111. exists: bind,
  112. forall: bind,
  113. filter: function (f) {
  114. return f(a) ? me : NONE;
  115. },
  116. toArray: function () {
  117. return [a];
  118. },
  119. toString: function () {
  120. return 'some(' + a + ')';
  121. },
  122. equals: function (o) {
  123. return o.is(a);
  124. },
  125. equals_: function (o, elementEq) {
  126. return o.fold(never, function (b) {
  127. return elementEq(a, b);
  128. });
  129. }
  130. };
  131. return me;
  132. };
  133. var from = function (value) {
  134. return value === null || value === undefined ? NONE : some(value);
  135. };
  136. var Option = {
  137. some: some,
  138. none: none,
  139. from: from
  140. };
  141. var typeOf = function (x) {
  142. if (x === null) {
  143. return 'null';
  144. }
  145. var t = typeof x;
  146. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  147. return 'array';
  148. }
  149. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  150. return 'string';
  151. }
  152. return t;
  153. };
  154. var isType = function (type) {
  155. return function (value) {
  156. return typeOf(value) === type;
  157. };
  158. };
  159. var isString = isType('string');
  160. var isObject = isType('object');
  161. var isArray = isType('array');
  162. var isFunction = isType('function');
  163. var nativeSlice = Array.prototype.slice;
  164. var nativePush = Array.prototype.push;
  165. var each = function (xs, f) {
  166. for (var i = 0, len = xs.length; i < len; i++) {
  167. var x = xs[i];
  168. f(x, i);
  169. }
  170. };
  171. var flatten = function (xs) {
  172. var r = [];
  173. for (var i = 0, len = xs.length; i < len; ++i) {
  174. if (!isArray(xs[i])) {
  175. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  176. }
  177. nativePush.apply(r, xs[i]);
  178. }
  179. return r;
  180. };
  181. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  182. return nativeSlice.call(x);
  183. };
  184. var Cell = function (initial) {
  185. var value = initial;
  186. var get = function () {
  187. return value;
  188. };
  189. var set = function (v) {
  190. value = v;
  191. };
  192. var clone = function () {
  193. return Cell(get());
  194. };
  195. return {
  196. get: get,
  197. set: set,
  198. clone: clone
  199. };
  200. };
  201. var hasOwnProperty = Object.hasOwnProperty;
  202. var get = function (obj, key) {
  203. return has(obj, key) ? Option.from(obj[key]) : Option.none();
  204. };
  205. var has = function (obj, key) {
  206. return hasOwnProperty.call(obj, key);
  207. };
  208. var getScripts = function (editor) {
  209. return editor.getParam('media_scripts');
  210. };
  211. var getAudioTemplateCallback = function (editor) {
  212. return editor.getParam('audio_template_callback');
  213. };
  214. var getVideoTemplateCallback = function (editor) {
  215. return editor.getParam('video_template_callback');
  216. };
  217. var hasLiveEmbeds = function (editor) {
  218. return editor.getParam('media_live_embeds', true);
  219. };
  220. var shouldFilterHtml = function (editor) {
  221. return editor.getParam('media_filter_html', true);
  222. };
  223. var getUrlResolver = function (editor) {
  224. return editor.getParam('media_url_resolver');
  225. };
  226. var hasAltSource = function (editor) {
  227. return editor.getParam('media_alt_source', true);
  228. };
  229. var hasPoster = function (editor) {
  230. return editor.getParam('media_poster', true);
  231. };
  232. var hasDimensions = function (editor) {
  233. return editor.getParam('media_dimensions', true);
  234. };
  235. var Settings = {
  236. getScripts: getScripts,
  237. getAudioTemplateCallback: getAudioTemplateCallback,
  238. getVideoTemplateCallback: getVideoTemplateCallback,
  239. hasLiveEmbeds: hasLiveEmbeds,
  240. shouldFilterHtml: shouldFilterHtml,
  241. getUrlResolver: getUrlResolver,
  242. hasAltSource: hasAltSource,
  243. hasPoster: hasPoster,
  244. hasDimensions: hasDimensions
  245. };
  246. var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  247. var global$2 = tinymce.util.Tools.resolve('tinymce.html.SaxParser');
  248. var global$3 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  249. var trimPx = function (value) {
  250. return value.replace(/px$/, '');
  251. };
  252. var addPx = function (value) {
  253. return /^[0-9.]+$/.test(value) ? value + 'px' : value;
  254. };
  255. var getSize = function (name) {
  256. return function (elm) {
  257. return elm ? trimPx(elm.style[name]) : '';
  258. };
  259. };
  260. var setSize = function (name) {
  261. return function (elm, value) {
  262. if (elm) {
  263. elm.style[name] = addPx(value);
  264. }
  265. };
  266. };
  267. var Size = {
  268. getMaxWidth: getSize('maxWidth'),
  269. getMaxHeight: getSize('maxHeight'),
  270. setMaxWidth: setSize('maxWidth'),
  271. setMaxHeight: setSize('maxHeight')
  272. };
  273. var getVideoScriptMatch = function (prefixes, src) {
  274. if (prefixes) {
  275. for (var i = 0; i < prefixes.length; i++) {
  276. if (src.indexOf(prefixes[i].filter) !== -1) {
  277. return prefixes[i];
  278. }
  279. }
  280. }
  281. };
  282. var DOM = global$3.DOM;
  283. var getEphoxEmbedIri = function (elm) {
  284. return DOM.getAttrib(elm, 'data-ephox-embed-iri');
  285. };
  286. var isEphoxEmbed = function (html) {
  287. var fragment = DOM.createFragment(html);
  288. return getEphoxEmbedIri(fragment.firstChild) !== '';
  289. };
  290. var htmlToDataSax = function (prefixes, html) {
  291. var data = {};
  292. global$2({
  293. validate: false,
  294. allow_conditional_comments: true,
  295. start: function (name, attrs) {
  296. if (!data.source && name === 'param') {
  297. data.source = attrs.map.movie;
  298. }
  299. if (name === 'iframe' || name === 'object' || name === 'embed' || name === 'video' || name === 'audio') {
  300. if (!data.type) {
  301. data.type = name;
  302. }
  303. data = global$1.extend(attrs.map, data);
  304. }
  305. if (name === 'script') {
  306. var videoScript = getVideoScriptMatch(prefixes, attrs.map.src);
  307. if (!videoScript) {
  308. return;
  309. }
  310. data = {
  311. type: 'script',
  312. source: attrs.map.src,
  313. width: String(videoScript.width),
  314. height: String(videoScript.height)
  315. };
  316. }
  317. if (name === 'source') {
  318. if (!data.source) {
  319. data.source = attrs.map.src;
  320. } else if (!data.altsource) {
  321. data.altsource = attrs.map.src;
  322. }
  323. }
  324. if (name === 'img' && !data.poster) {
  325. data.poster = attrs.map.src;
  326. }
  327. }
  328. }).parse(html);
  329. data.source = data.source || data.src || data.data;
  330. data.altsource = data.altsource || '';
  331. data.poster = data.poster || '';
  332. return data;
  333. };
  334. var ephoxEmbedHtmlToData = function (html) {
  335. var fragment = DOM.createFragment(html);
  336. var div = fragment.firstChild;
  337. return {
  338. type: 'ephox-embed-iri',
  339. source: getEphoxEmbedIri(div),
  340. altsource: '',
  341. poster: '',
  342. width: Size.getMaxWidth(div),
  343. height: Size.getMaxHeight(div)
  344. };
  345. };
  346. var htmlToData = function (prefixes, html) {
  347. return isEphoxEmbed(html) ? ephoxEmbedHtmlToData(html) : htmlToDataSax(prefixes, html);
  348. };
  349. var guess = function (url) {
  350. var mimes = {
  351. mp3: 'audio/mpeg',
  352. m4a: 'audio/x-m4a',
  353. wav: 'audio/wav',
  354. mp4: 'video/mp4',
  355. webm: 'video/webm',
  356. ogg: 'video/ogg',
  357. swf: 'application/x-shockwave-flash'
  358. };
  359. var fileEnd = url.toLowerCase().split('.').pop();
  360. var mime = mimes[fileEnd];
  361. return mime ? mime : '';
  362. };
  363. var Mime = { guess: guess };
  364. var global$4 = tinymce.util.Tools.resolve('tinymce.html.Writer');
  365. var global$5 = tinymce.util.Tools.resolve('tinymce.html.Schema');
  366. var DOM$1 = global$3.DOM;
  367. var setAttributes = function (attrs, updatedAttrs) {
  368. var name;
  369. var i;
  370. var value;
  371. var attr;
  372. for (name in updatedAttrs) {
  373. value = '' + updatedAttrs[name];
  374. if (attrs.map[name]) {
  375. i = attrs.length;
  376. while (i--) {
  377. attr = attrs[i];
  378. if (attr.name === name) {
  379. if (value) {
  380. attrs.map[name] = value;
  381. attr.value = value;
  382. } else {
  383. delete attrs.map[name];
  384. attrs.splice(i, 1);
  385. }
  386. }
  387. }
  388. } else if (value) {
  389. attrs.push({
  390. name: name,
  391. value: value
  392. });
  393. attrs.map[name] = value;
  394. }
  395. }
  396. };
  397. var normalizeHtml = function (html) {
  398. var writer = global$4();
  399. var parser = global$2(writer);
  400. parser.parse(html);
  401. return writer.getContent();
  402. };
  403. var sources = [
  404. 'source',
  405. 'altsource'
  406. ];
  407. var updateHtmlSax = function (html, data, updateAll) {
  408. var writer = global$4();
  409. var sourceCount = 0;
  410. var hasImage;
  411. global$2({
  412. validate: false,
  413. allow_conditional_comments: true,
  414. comment: function (text) {
  415. writer.comment(text);
  416. },
  417. cdata: function (text) {
  418. writer.cdata(text);
  419. },
  420. text: function (text, raw) {
  421. writer.text(text, raw);
  422. },
  423. start: function (name, attrs, empty) {
  424. switch (name) {
  425. case 'video':
  426. case 'object':
  427. case 'embed':
  428. case 'img':
  429. case 'iframe':
  430. if (data.height !== undefined && data.width !== undefined) {
  431. setAttributes(attrs, {
  432. width: data.width,
  433. height: data.height
  434. });
  435. }
  436. break;
  437. }
  438. if (updateAll) {
  439. switch (name) {
  440. case 'video':
  441. setAttributes(attrs, {
  442. poster: data.poster,
  443. src: ''
  444. });
  445. if (data.altsource) {
  446. setAttributes(attrs, { src: '' });
  447. }
  448. break;
  449. case 'iframe':
  450. setAttributes(attrs, { src: data.source });
  451. break;
  452. case 'source':
  453. if (sourceCount < 2) {
  454. setAttributes(attrs, {
  455. src: data[sources[sourceCount]],
  456. type: data[sources[sourceCount] + 'mime']
  457. });
  458. if (!data[sources[sourceCount]]) {
  459. return;
  460. }
  461. }
  462. sourceCount++;
  463. break;
  464. case 'img':
  465. if (!data.poster) {
  466. return;
  467. }
  468. hasImage = true;
  469. break;
  470. }
  471. }
  472. writer.start(name, attrs, empty);
  473. },
  474. end: function (name) {
  475. if (name === 'video' && updateAll) {
  476. for (var index = 0; index < 2; index++) {
  477. if (data[sources[index]]) {
  478. var attrs = [];
  479. attrs.map = {};
  480. if (sourceCount < index) {
  481. setAttributes(attrs, {
  482. src: data[sources[index]],
  483. type: data[sources[index] + 'mime']
  484. });
  485. writer.start('source', attrs, true);
  486. }
  487. }
  488. }
  489. }
  490. if (data.poster && name === 'object' && updateAll && !hasImage) {
  491. var imgAttrs = [];
  492. imgAttrs.map = {};
  493. setAttributes(imgAttrs, {
  494. src: data.poster,
  495. width: data.width,
  496. height: data.height
  497. });
  498. writer.start('img', imgAttrs, true);
  499. }
  500. writer.end(name);
  501. }
  502. }, global$5({})).parse(html);
  503. return writer.getContent();
  504. };
  505. var isEphoxEmbed$1 = function (html) {
  506. var fragment = DOM$1.createFragment(html);
  507. return DOM$1.getAttrib(fragment.firstChild, 'data-ephox-embed-iri') !== '';
  508. };
  509. var updateEphoxEmbed = function (html, data) {
  510. var fragment = DOM$1.createFragment(html);
  511. var div = fragment.firstChild;
  512. Size.setMaxWidth(div, data.width);
  513. Size.setMaxHeight(div, data.height);
  514. return normalizeHtml(div.outerHTML);
  515. };
  516. var updateHtml = function (html, data, updateAll) {
  517. return isEphoxEmbed$1(html) ? updateEphoxEmbed(html, data) : updateHtmlSax(html, data, updateAll);
  518. };
  519. var UpdateHtml = { updateHtml: updateHtml };
  520. var urlPatterns = [
  521. {
  522. regex: /youtu\.be\/([\w\-_\?&=.]+)/i,
  523. type: 'iframe',
  524. w: 560,
  525. h: 314,
  526. url: 'www.youtube.com/embed/$1',
  527. allowFullscreen: true
  528. },
  529. {
  530. regex: /youtube\.com(.+)v=([^&]+)(&([a-z0-9&=\-_]+))?/i,
  531. type: 'iframe',
  532. w: 560,
  533. h: 314,
  534. url: 'www.youtube.com/embed/$2?$4',
  535. allowFullscreen: true
  536. },
  537. {
  538. regex: /youtube.com\/embed\/([a-z0-9\?&=\-_]+)/i,
  539. type: 'iframe',
  540. w: 560,
  541. h: 314,
  542. url: 'www.youtube.com/embed/$1',
  543. allowFullscreen: true
  544. },
  545. {
  546. regex: /vimeo\.com\/([0-9]+)/,
  547. type: 'iframe',
  548. w: 425,
  549. h: 350,
  550. url: 'player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc',
  551. allowFullscreen: true
  552. },
  553. {
  554. regex: /vimeo\.com\/(.*)\/([0-9]+)/,
  555. type: 'iframe',
  556. w: 425,
  557. h: 350,
  558. url: 'player.vimeo.com/video/$2?title=0&amp;byline=0',
  559. allowFullscreen: true
  560. },
  561. {
  562. regex: /maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/,
  563. type: 'iframe',
  564. w: 425,
  565. h: 350,
  566. url: 'maps.google.com/maps/ms?msid=$2&output=embed"',
  567. allowFullscreen: false
  568. },
  569. {
  570. regex: /dailymotion\.com\/video\/([^_]+)/,
  571. type: 'iframe',
  572. w: 480,
  573. h: 270,
  574. url: 'www.dailymotion.com/embed/video/$1',
  575. allowFullscreen: true
  576. },
  577. {
  578. regex: /dai\.ly\/([^_]+)/,
  579. type: 'iframe',
  580. w: 480,
  581. h: 270,
  582. url: 'www.dailymotion.com/embed/video/$1',
  583. allowFullscreen: true
  584. }
  585. ];
  586. var getProtocol = function (url) {
  587. var protocolMatches = url.match(/^(https?:\/\/|www\.)(.+)$/i);
  588. if (protocolMatches && protocolMatches.length > 1) {
  589. return protocolMatches[1] === 'www.' ? 'https://' : protocolMatches[1];
  590. } else {
  591. return 'https://';
  592. }
  593. };
  594. var getUrl = function (pattern, url) {
  595. var protocol = getProtocol(url);
  596. var match = pattern.regex.exec(url);
  597. var newUrl = protocol + pattern.url;
  598. var _loop_1 = function (i) {
  599. newUrl = newUrl.replace('$' + i, function () {
  600. return match[i] ? match[i] : '';
  601. });
  602. };
  603. for (var i = 0; i < match.length; i++) {
  604. _loop_1(i);
  605. }
  606. return newUrl.replace(/\?$/, '');
  607. };
  608. var matchPattern = function (url) {
  609. var patterns = urlPatterns.filter(function (pattern) {
  610. return pattern.regex.test(url);
  611. });
  612. if (patterns.length > 0) {
  613. return global$1.extend({}, patterns[0], { url: getUrl(patterns[0], url) });
  614. } else {
  615. return null;
  616. }
  617. };
  618. var getIframeHtml = function (data) {
  619. var allowFullscreen = data.allowFullscreen ? ' allowFullscreen="1"' : '';
  620. return '<iframe src="' + data.source + '" width="' + data.width + '" height="' + data.height + '"' + allowFullscreen + '></iframe>';
  621. };
  622. var getFlashHtml = function (data) {
  623. var html = '<object data="' + data.source + '" width="' + data.width + '" height="' + data.height + '" type="application/x-shockwave-flash">';
  624. if (data.poster) {
  625. html += '<img src="' + data.poster + '" width="' + data.width + '" height="' + data.height + '" />';
  626. }
  627. html += '</object>';
  628. return html;
  629. };
  630. var getAudioHtml = function (data, audioTemplateCallback) {
  631. if (audioTemplateCallback) {
  632. return audioTemplateCallback(data);
  633. } else {
  634. return '<audio controls="controls" src="' + data.source + '">' + (data.altsource ? '\n<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</audio>';
  635. }
  636. };
  637. var getVideoHtml = function (data, videoTemplateCallback) {
  638. if (videoTemplateCallback) {
  639. return videoTemplateCallback(data);
  640. } else {
  641. return '<video width="' + data.width + '" height="' + data.height + '"' + (data.poster ? ' poster="' + data.poster + '"' : '') + ' controls="controls">\n' + '<source src="' + data.source + '"' + (data.sourcemime ? ' type="' + data.sourcemime + '"' : '') + ' />\n' + (data.altsource ? '<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</video>';
  642. }
  643. };
  644. var getScriptHtml = function (data) {
  645. return '<script src="' + data.source + '"></script>';
  646. };
  647. var dataToHtml = function (editor, dataIn) {
  648. var data = global$1.extend({}, dataIn);
  649. if (!data.source) {
  650. global$1.extend(data, htmlToData(Settings.getScripts(editor), data.embed));
  651. if (!data.source) {
  652. return '';
  653. }
  654. }
  655. if (!data.altsource) {
  656. data.altsource = '';
  657. }
  658. if (!data.poster) {
  659. data.poster = '';
  660. }
  661. data.source = editor.convertURL(data.source, 'source');
  662. data.altsource = editor.convertURL(data.altsource, 'source');
  663. data.sourcemime = Mime.guess(data.source);
  664. data.altsourcemime = Mime.guess(data.altsource);
  665. data.poster = editor.convertURL(data.poster, 'poster');
  666. var pattern = matchPattern(data.source);
  667. if (pattern) {
  668. data.source = pattern.url;
  669. data.type = pattern.type;
  670. data.allowFullscreen = pattern.allowFullscreen;
  671. data.width = data.width || String(pattern.w);
  672. data.height = data.height || String(pattern.h);
  673. }
  674. if (data.embed) {
  675. return UpdateHtml.updateHtml(data.embed, data, true);
  676. } else {
  677. var videoScript = getVideoScriptMatch(Settings.getScripts(editor), data.source);
  678. if (videoScript) {
  679. data.type = 'script';
  680. data.width = String(videoScript.width);
  681. data.height = String(videoScript.height);
  682. }
  683. var audioTemplateCallback = Settings.getAudioTemplateCallback(editor);
  684. var videoTemplateCallback = Settings.getVideoTemplateCallback(editor);
  685. data.width = data.width || '300';
  686. data.height = data.height || '150';
  687. global$1.each(data, function (value, key) {
  688. data[key] = editor.dom.encode('' + value);
  689. });
  690. if (data.type === 'iframe') {
  691. return getIframeHtml(data);
  692. } else if (data.sourcemime === 'application/x-shockwave-flash') {
  693. return getFlashHtml(data);
  694. } else if (data.sourcemime.indexOf('audio') !== -1) {
  695. return getAudioHtml(data, audioTemplateCallback);
  696. } else if (data.type === 'script') {
  697. return getScriptHtml(data);
  698. } else {
  699. return getVideoHtml(data, videoTemplateCallback);
  700. }
  701. }
  702. };
  703. var global$6 = tinymce.util.Tools.resolve('tinymce.util.Promise');
  704. var cache = {};
  705. var embedPromise = function (data, dataToHtml, handler) {
  706. return new global$6(function (res, rej) {
  707. var wrappedResolve = function (response) {
  708. if (response.html) {
  709. cache[data.source] = response;
  710. }
  711. return res({
  712. url: data.source,
  713. html: response.html ? response.html : dataToHtml(data)
  714. });
  715. };
  716. if (cache[data.source]) {
  717. wrappedResolve(cache[data.source]);
  718. } else {
  719. handler({ url: data.source }, wrappedResolve, rej);
  720. }
  721. });
  722. };
  723. var defaultPromise = function (data, dataToHtml) {
  724. return new global$6(function (res) {
  725. res({
  726. html: dataToHtml(data),
  727. url: data.source
  728. });
  729. });
  730. };
  731. var loadedData = function (editor) {
  732. return function (data) {
  733. return dataToHtml(editor, data);
  734. };
  735. };
  736. var getEmbedHtml = function (editor, data) {
  737. var embedHandler = Settings.getUrlResolver(editor);
  738. return embedHandler ? embedPromise(data, loadedData(editor), embedHandler) : defaultPromise(data, loadedData(editor));
  739. };
  740. var isCached = function (url) {
  741. return cache.hasOwnProperty(url);
  742. };
  743. var Service = {
  744. getEmbedHtml: getEmbedHtml,
  745. isCached: isCached
  746. };
  747. var extractMeta = function (sourceInput, data) {
  748. return get(data, sourceInput).bind(function (mainData) {
  749. return get(mainData, 'meta');
  750. });
  751. };
  752. var getValue = function (data, metaData, sourceInput) {
  753. return function (prop) {
  754. var _a;
  755. var getFromData = function () {
  756. return get(data, prop);
  757. };
  758. var getFromMetaData = function () {
  759. return get(metaData, prop);
  760. };
  761. var getNonEmptyValue = function (c) {
  762. return get(c, 'value').bind(function (v) {
  763. return v.length > 0 ? Option.some(v) : Option.none();
  764. });
  765. };
  766. var getFromValueFirst = function () {
  767. return getFromData().bind(function (child) {
  768. return isObject(child) ? getNonEmptyValue(child).orThunk(getFromMetaData) : getFromMetaData().orThunk(function () {
  769. return Option.from(child);
  770. });
  771. });
  772. };
  773. var getFromMetaFirst = function () {
  774. return getFromMetaData().orThunk(function () {
  775. return getFromData().bind(function (child) {
  776. return isObject(child) ? getNonEmptyValue(child) : Option.from(child);
  777. });
  778. });
  779. };
  780. return _a = {}, _a[prop] = (prop === sourceInput ? getFromValueFirst() : getFromMetaFirst()).getOr(''), _a;
  781. };
  782. };
  783. var getDimensions = function (data, metaData) {
  784. var dimensions = {};
  785. get(data, 'dimensions').each(function (dims) {
  786. each([
  787. 'width',
  788. 'height'
  789. ], function (prop) {
  790. get(metaData, prop).orThunk(function () {
  791. return get(dims, prop);
  792. }).each(function (value) {
  793. return dimensions[prop] = value;
  794. });
  795. });
  796. });
  797. return dimensions;
  798. };
  799. var unwrap = function (data, sourceInput) {
  800. var metaData = sourceInput ? extractMeta(sourceInput, data).getOr({}) : {};
  801. var get = getValue(data, metaData, sourceInput);
  802. return __assign(__assign(__assign(__assign(__assign({}, get('source')), get('altsource')), get('poster')), get('embed')), getDimensions(data, metaData));
  803. };
  804. var wrap = function (data) {
  805. var wrapped = __assign(__assign({}, data), {
  806. source: { value: get(data, 'source').getOr('') },
  807. altsource: { value: get(data, 'altsource').getOr('') },
  808. poster: { value: get(data, 'poster').getOr('') }
  809. });
  810. each([
  811. 'width',
  812. 'height'
  813. ], function (prop) {
  814. get(data, prop).each(function (value) {
  815. var dimensions = wrapped.dimensions || {};
  816. dimensions[prop] = value;
  817. wrapped.dimensions = dimensions;
  818. });
  819. });
  820. return wrapped;
  821. };
  822. var handleError = function (editor) {
  823. return function (error) {
  824. var errorMessage = error && error.msg ? 'Media embed handler error: ' + error.msg : 'Media embed handler threw unknown error.';
  825. editor.notificationManager.open({
  826. type: 'error',
  827. text: errorMessage
  828. });
  829. };
  830. };
  831. var snippetToData = function (editor, embedSnippet) {
  832. return htmlToData(Settings.getScripts(editor), embedSnippet);
  833. };
  834. var isMediaElement = function (element) {
  835. return element.getAttribute('data-mce-object') || element.getAttribute('data-ephox-embed-iri');
  836. };
  837. var getEditorData = function (editor) {
  838. var element = editor.selection.getNode();
  839. var snippet = isMediaElement(element) ? editor.serializer.serialize(element, { selection: true }) : '';
  840. return __assign({ embed: snippet }, htmlToData(Settings.getScripts(editor), snippet));
  841. };
  842. var addEmbedHtml = function (api, editor) {
  843. return function (response) {
  844. if (isString(response.url) && response.url.trim().length > 0) {
  845. var html = response.html;
  846. var snippetData = snippetToData(editor, html);
  847. var nuData = __assign(__assign({}, snippetData), {
  848. source: response.url,
  849. embed: html
  850. });
  851. api.setData(wrap(nuData));
  852. }
  853. };
  854. };
  855. var selectPlaceholder = function (editor, beforeObjects) {
  856. var afterObjects = editor.dom.select('img[data-mce-object]');
  857. for (var i = 0; i < beforeObjects.length; i++) {
  858. for (var y = afterObjects.length - 1; y >= 0; y--) {
  859. if (beforeObjects[i] === afterObjects[y]) {
  860. afterObjects.splice(y, 1);
  861. }
  862. }
  863. }
  864. editor.selection.select(afterObjects[0]);
  865. };
  866. var handleInsert = function (editor, html) {
  867. var beforeObjects = editor.dom.select('img[data-mce-object]');
  868. editor.insertContent(html);
  869. selectPlaceholder(editor, beforeObjects);
  870. editor.nodeChanged();
  871. };
  872. var submitForm = function (prevData, newData, editor) {
  873. newData.embed = UpdateHtml.updateHtml(newData.embed, newData);
  874. if (newData.embed && (prevData.source === newData.source || Service.isCached(newData.source))) {
  875. handleInsert(editor, newData.embed);
  876. } else {
  877. Service.getEmbedHtml(editor, newData).then(function (response) {
  878. handleInsert(editor, response.html);
  879. }).catch(handleError(editor));
  880. }
  881. };
  882. var showDialog = function (editor) {
  883. var editorData = getEditorData(editor);
  884. var currentData = Cell(editorData);
  885. var initialData = wrap(editorData);
  886. var handleSource = function (prevData, api) {
  887. var serviceData = unwrap(api.getData(), 'source');
  888. if (prevData.source !== serviceData.source) {
  889. addEmbedHtml(win, editor)({
  890. url: serviceData.source,
  891. html: ''
  892. });
  893. Service.getEmbedHtml(editor, serviceData).then(addEmbedHtml(win, editor)).catch(handleError(editor));
  894. }
  895. };
  896. var handleEmbed = function (api) {
  897. var data = unwrap(api.getData());
  898. var dataFromEmbed = snippetToData(editor, data.embed);
  899. api.setData(wrap(dataFromEmbed));
  900. };
  901. var handleUpdate = function (api, sourceInput) {
  902. var data = unwrap(api.getData(), sourceInput);
  903. var embed = dataToHtml(editor, data);
  904. api.setData(wrap(__assign(__assign({}, data), { embed: embed })));
  905. };
  906. var mediaInput = [{
  907. name: 'source',
  908. type: 'urlinput',
  909. filetype: 'media',
  910. label: 'Source'
  911. }];
  912. var sizeInput = !Settings.hasDimensions(editor) ? [] : [{
  913. type: 'sizeinput',
  914. name: 'dimensions',
  915. label: 'Constrain proportions',
  916. constrain: true
  917. }];
  918. var generalTab = {
  919. title: 'General',
  920. name: 'general',
  921. items: flatten([
  922. mediaInput,
  923. sizeInput
  924. ])
  925. };
  926. var embedTextarea = {
  927. type: 'textarea',
  928. name: 'embed',
  929. label: 'Paste your embed code below:'
  930. };
  931. var embedTab = {
  932. title: 'Embed',
  933. items: [embedTextarea]
  934. };
  935. var advancedFormItems = [];
  936. if (Settings.hasAltSource(editor)) {
  937. advancedFormItems.push({
  938. name: 'altsource',
  939. type: 'urlinput',
  940. filetype: 'media',
  941. label: 'Alternative source URL'
  942. });
  943. }
  944. if (Settings.hasPoster(editor)) {
  945. advancedFormItems.push({
  946. name: 'poster',
  947. type: 'urlinput',
  948. filetype: 'image',
  949. label: 'Media poster (Image URL)'
  950. });
  951. }
  952. var advancedTab = {
  953. title: 'Advanced',
  954. name: 'advanced',
  955. items: advancedFormItems
  956. };
  957. var tabs = [
  958. generalTab,
  959. embedTab
  960. ];
  961. if (advancedFormItems.length > 0) {
  962. tabs.push(advancedTab);
  963. }
  964. var body = {
  965. type: 'tabpanel',
  966. tabs: tabs
  967. };
  968. var win = editor.windowManager.open({
  969. title: 'Insert/Edit Media',
  970. size: 'normal',
  971. body: body,
  972. buttons: [
  973. {
  974. type: 'cancel',
  975. name: 'cancel',
  976. text: 'Cancel'
  977. },
  978. {
  979. type: 'submit',
  980. name: 'save',
  981. text: 'Save',
  982. primary: true
  983. }
  984. ],
  985. onSubmit: function (api) {
  986. var serviceData = unwrap(api.getData());
  987. submitForm(currentData.get(), serviceData, editor);
  988. api.close();
  989. },
  990. onChange: function (api, detail) {
  991. switch (detail.name) {
  992. case 'source':
  993. handleSource(currentData.get(), api);
  994. break;
  995. case 'embed':
  996. handleEmbed(api);
  997. break;
  998. case 'dimensions':
  999. case 'altsource':
  1000. case 'poster':
  1001. handleUpdate(api, detail.name);
  1002. break;
  1003. }
  1004. currentData.set(unwrap(api.getData()));
  1005. },
  1006. initialData: initialData
  1007. });
  1008. };
  1009. var Dialog = {
  1010. showDialog: showDialog,
  1011. unwrap: unwrap
  1012. };
  1013. var get$1 = function (editor) {
  1014. var showDialog = function () {
  1015. Dialog.showDialog(editor);
  1016. };
  1017. return { showDialog: showDialog };
  1018. };
  1019. var Api = { get: get$1 };
  1020. var register = function (editor) {
  1021. var showDialog = function () {
  1022. Dialog.showDialog(editor);
  1023. };
  1024. editor.addCommand('mceMedia', showDialog);
  1025. };
  1026. var Commands = { register: register };
  1027. var global$7 = tinymce.util.Tools.resolve('tinymce.html.Node');
  1028. var global$8 = tinymce.util.Tools.resolve('tinymce.Env');
  1029. var sanitize = function (editor, html) {
  1030. if (Settings.shouldFilterHtml(editor) === false) {
  1031. return html;
  1032. }
  1033. var writer = global$4();
  1034. var blocked;
  1035. global$2({
  1036. validate: false,
  1037. allow_conditional_comments: false,
  1038. comment: function (text) {
  1039. writer.comment(text);
  1040. },
  1041. cdata: function (text) {
  1042. writer.cdata(text);
  1043. },
  1044. text: function (text, raw) {
  1045. writer.text(text, raw);
  1046. },
  1047. start: function (name, attrs, empty) {
  1048. blocked = true;
  1049. if (name === 'script' || name === 'noscript') {
  1050. return;
  1051. }
  1052. for (var i = 0; i < attrs.length; i++) {
  1053. if (attrs[i].name.indexOf('on') === 0) {
  1054. return;
  1055. }
  1056. if (attrs[i].name === 'style') {
  1057. attrs[i].value = editor.dom.serializeStyle(editor.dom.parseStyle(attrs[i].value), name);
  1058. }
  1059. }
  1060. writer.start(name, attrs, empty);
  1061. blocked = false;
  1062. },
  1063. end: function (name) {
  1064. if (blocked) {
  1065. return;
  1066. }
  1067. writer.end(name);
  1068. }
  1069. }, global$5({})).parse(html);
  1070. return writer.getContent();
  1071. };
  1072. var Sanitize = { sanitize: sanitize };
  1073. var createPlaceholderNode = function (editor, node) {
  1074. var placeHolder;
  1075. var name = node.name;
  1076. placeHolder = new global$7('img', 1);
  1077. placeHolder.shortEnded = true;
  1078. retainAttributesAndInnerHtml(editor, node, placeHolder);
  1079. placeHolder.attr({
  1080. 'width': node.attr('width') || '300',
  1081. 'height': node.attr('height') || (name === 'audio' ? '30' : '150'),
  1082. 'style': node.attr('style'),
  1083. 'src': global$8.transparentSrc,
  1084. 'data-mce-object': name,
  1085. 'class': 'mce-object mce-object-' + name
  1086. });
  1087. return placeHolder;
  1088. };
  1089. var createPreviewIframeNode = function (editor, node) {
  1090. var previewWrapper;
  1091. var previewNode;
  1092. var shimNode;
  1093. var name = node.name;
  1094. previewWrapper = new global$7('span', 1);
  1095. previewWrapper.attr({
  1096. 'contentEditable': 'false',
  1097. 'style': node.attr('style'),
  1098. 'data-mce-object': name,
  1099. 'class': 'mce-preview-object mce-object-' + name
  1100. });
  1101. retainAttributesAndInnerHtml(editor, node, previewWrapper);
  1102. previewNode = new global$7(name, 1);
  1103. previewNode.attr({
  1104. src: node.attr('src'),
  1105. allowfullscreen: node.attr('allowfullscreen'),
  1106. style: node.attr('style'),
  1107. class: node.attr('class'),
  1108. width: node.attr('width'),
  1109. height: node.attr('height'),
  1110. frameborder: '0'
  1111. });
  1112. shimNode = new global$7('span', 1);
  1113. shimNode.attr('class', 'mce-shim');
  1114. previewWrapper.append(previewNode);
  1115. previewWrapper.append(shimNode);
  1116. return previewWrapper;
  1117. };
  1118. var retainAttributesAndInnerHtml = function (editor, sourceNode, targetNode) {
  1119. var attrName;
  1120. var attrValue;
  1121. var attribs;
  1122. var ai;
  1123. var innerHtml;
  1124. attribs = sourceNode.attributes;
  1125. ai = attribs.length;
  1126. while (ai--) {
  1127. attrName = attribs[ai].name;
  1128. attrValue = attribs[ai].value;
  1129. if (attrName !== 'width' && attrName !== 'height' && attrName !== 'style') {
  1130. if (attrName === 'data' || attrName === 'src') {
  1131. attrValue = editor.convertURL(attrValue, attrName);
  1132. }
  1133. targetNode.attr('data-mce-p-' + attrName, attrValue);
  1134. }
  1135. }
  1136. innerHtml = sourceNode.firstChild && sourceNode.firstChild.value;
  1137. if (innerHtml) {
  1138. targetNode.attr('data-mce-html', escape(Sanitize.sanitize(editor, innerHtml)));
  1139. targetNode.firstChild = null;
  1140. }
  1141. };
  1142. var isPageEmbedWrapper = function (node) {
  1143. var nodeClass = node.attr('class');
  1144. return nodeClass && /\btiny-pageembed\b/.test(nodeClass);
  1145. };
  1146. var isWithinEmbedWrapper = function (node) {
  1147. while (node = node.parent) {
  1148. if (node.attr('data-ephox-embed-iri') || isPageEmbedWrapper(node)) {
  1149. return true;
  1150. }
  1151. }
  1152. return false;
  1153. };
  1154. var placeHolderConverter = function (editor) {
  1155. return function (nodes) {
  1156. var i = nodes.length;
  1157. var node;
  1158. var videoScript;
  1159. while (i--) {
  1160. node = nodes[i];
  1161. if (!node.parent) {
  1162. continue;
  1163. }
  1164. if (node.parent.attr('data-mce-object')) {
  1165. continue;
  1166. }
  1167. if (node.name === 'script') {
  1168. videoScript = getVideoScriptMatch(Settings.getScripts(editor), node.attr('src'));
  1169. if (!videoScript) {
  1170. continue;
  1171. }
  1172. }
  1173. if (videoScript) {
  1174. if (videoScript.width) {
  1175. node.attr('width', videoScript.width.toString());
  1176. }
  1177. if (videoScript.height) {
  1178. node.attr('height', videoScript.height.toString());
  1179. }
  1180. }
  1181. if (node.name === 'iframe' && Settings.hasLiveEmbeds(editor) && global$8.ceFalse) {
  1182. if (!isWithinEmbedWrapper(node)) {
  1183. node.replace(createPreviewIframeNode(editor, node));
  1184. }
  1185. } else {
  1186. if (!isWithinEmbedWrapper(node)) {
  1187. node.replace(createPlaceholderNode(editor, node));
  1188. }
  1189. }
  1190. }
  1191. };
  1192. };
  1193. var Nodes = {
  1194. createPreviewIframeNode: createPreviewIframeNode,
  1195. createPlaceholderNode: createPlaceholderNode,
  1196. placeHolderConverter: placeHolderConverter
  1197. };
  1198. var setup = function (editor) {
  1199. editor.on('preInit', function () {
  1200. var specialElements = editor.schema.getSpecialElements();
  1201. global$1.each('video audio iframe object'.split(' '), function (name) {
  1202. specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi');
  1203. });
  1204. var boolAttrs = editor.schema.getBoolAttrs();
  1205. global$1.each('webkitallowfullscreen mozallowfullscreen allowfullscreen'.split(' '), function (name) {
  1206. boolAttrs[name] = {};
  1207. });
  1208. editor.parser.addNodeFilter('iframe,video,audio,object,embed,script', Nodes.placeHolderConverter(editor));
  1209. editor.serializer.addAttributeFilter('data-mce-object', function (nodes, name) {
  1210. var i = nodes.length;
  1211. var node;
  1212. var realElm;
  1213. var ai;
  1214. var attribs;
  1215. var innerHtml;
  1216. var innerNode;
  1217. var realElmName;
  1218. var className;
  1219. while (i--) {
  1220. node = nodes[i];
  1221. if (!node.parent) {
  1222. continue;
  1223. }
  1224. realElmName = node.attr(name);
  1225. realElm = new global$7(realElmName, 1);
  1226. if (realElmName !== 'audio' && realElmName !== 'script') {
  1227. className = node.attr('class');
  1228. if (className && className.indexOf('mce-preview-object') !== -1) {
  1229. realElm.attr({
  1230. width: node.firstChild.attr('width'),
  1231. height: node.firstChild.attr('height')
  1232. });
  1233. } else {
  1234. realElm.attr({
  1235. width: node.attr('width'),
  1236. height: node.attr('height')
  1237. });
  1238. }
  1239. }
  1240. realElm.attr({ style: node.attr('style') });
  1241. attribs = node.attributes;
  1242. ai = attribs.length;
  1243. while (ai--) {
  1244. var attrName = attribs[ai].name;
  1245. if (attrName.indexOf('data-mce-p-') === 0) {
  1246. realElm.attr(attrName.substr(11), attribs[ai].value);
  1247. }
  1248. }
  1249. if (realElmName === 'script') {
  1250. realElm.attr('type', 'text/javascript');
  1251. }
  1252. innerHtml = node.attr('data-mce-html');
  1253. if (innerHtml) {
  1254. innerNode = new global$7('#text', 3);
  1255. innerNode.raw = true;
  1256. innerNode.value = Sanitize.sanitize(editor, unescape(innerHtml));
  1257. realElm.append(innerNode);
  1258. }
  1259. node.replace(realElm);
  1260. }
  1261. });
  1262. });
  1263. editor.on('SetContent', function () {
  1264. editor.$('span.mce-preview-object').each(function (index, elm) {
  1265. var $elm = editor.$(elm);
  1266. if ($elm.find('span.mce-shim').length === 0) {
  1267. $elm.append('<span class="mce-shim"></span>');
  1268. }
  1269. });
  1270. });
  1271. };
  1272. var FilterContent = { setup: setup };
  1273. var setup$1 = function (editor) {
  1274. editor.on('ResolveName', function (e) {
  1275. var name;
  1276. if (e.target.nodeType === 1 && (name = e.target.getAttribute('data-mce-object'))) {
  1277. e.name = name;
  1278. }
  1279. });
  1280. };
  1281. var ResolveName = { setup: setup$1 };
  1282. var setup$2 = function (editor) {
  1283. editor.on('click keyup touchend', function () {
  1284. var selectedNode = editor.selection.getNode();
  1285. if (selectedNode && editor.dom.hasClass(selectedNode, 'mce-preview-object')) {
  1286. if (editor.dom.getAttrib(selectedNode, 'data-mce-selected')) {
  1287. selectedNode.setAttribute('data-mce-selected', '2');
  1288. }
  1289. }
  1290. });
  1291. editor.on('ObjectSelected', function (e) {
  1292. var objectType = e.target.getAttribute('data-mce-object');
  1293. if (objectType === 'audio' || objectType === 'script') {
  1294. e.preventDefault();
  1295. }
  1296. });
  1297. editor.on('ObjectResized', function (e) {
  1298. var target = e.target;
  1299. var html;
  1300. if (target.getAttribute('data-mce-object')) {
  1301. html = target.getAttribute('data-mce-html');
  1302. if (html) {
  1303. html = unescape(html);
  1304. target.setAttribute('data-mce-html', escape(UpdateHtml.updateHtml(html, {
  1305. width: String(e.width),
  1306. height: String(e.height)
  1307. })));
  1308. }
  1309. }
  1310. });
  1311. };
  1312. var Selection = { setup: setup$2 };
  1313. var stateSelectorAdapter = function (editor, selector) {
  1314. return function (buttonApi) {
  1315. return editor.selection.selectorChangedWithUnbind(selector.join(','), buttonApi.setActive).unbind;
  1316. };
  1317. };
  1318. var register$1 = function (editor) {
  1319. editor.ui.registry.addToggleButton('media', {
  1320. tooltip: 'Insert/edit media',
  1321. icon: 'embed',
  1322. onAction: function () {
  1323. editor.execCommand('mceMedia');
  1324. },
  1325. onSetup: stateSelectorAdapter(editor, [
  1326. 'img[data-mce-object]',
  1327. 'span[data-mce-object]',
  1328. 'div[data-ephox-embed-iri]'
  1329. ])
  1330. });
  1331. editor.ui.registry.addMenuItem('media', {
  1332. icon: 'embed',
  1333. text: 'Media...',
  1334. onAction: function () {
  1335. editor.execCommand('mceMedia');
  1336. }
  1337. });
  1338. };
  1339. var Buttons = { register: register$1 };
  1340. function Plugin () {
  1341. global.add('media', function (editor) {
  1342. Commands.register(editor);
  1343. Buttons.register(editor);
  1344. ResolveName.setup(editor);
  1345. FilterContent.setup(editor);
  1346. Selection.setup(editor);
  1347. return Api.get(editor);
  1348. });
  1349. }
  1350. Plugin();
  1351. }());