plugin.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379
  1. (function () {
  2. var paste = (function (domGlobals) {
  3. 'use strict';
  4. var Cell = function (initial) {
  5. var value = initial;
  6. var get = function () {
  7. return value;
  8. };
  9. var set = function (v) {
  10. value = v;
  11. };
  12. var clone = function () {
  13. return Cell(get());
  14. };
  15. return {
  16. get: get,
  17. set: set,
  18. clone: clone
  19. };
  20. };
  21. var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  22. var hasProPlugin = function (editor) {
  23. if (/(^|[ ,])powerpaste([, ]|$)/.test(editor.settings.plugins) && global$1.get('powerpaste')) {
  24. if (typeof domGlobals.window.console !== 'undefined' && domGlobals.window.console.log) {
  25. domGlobals.window.console.log('PowerPaste is incompatible with Paste plugin! Remove \'paste\' from the \'plugins\' option.');
  26. }
  27. return true;
  28. } else {
  29. return false;
  30. }
  31. };
  32. var DetectProPlugin = { hasProPlugin: hasProPlugin };
  33. var get = function (clipboard, quirks) {
  34. return {
  35. clipboard: clipboard,
  36. quirks: quirks
  37. };
  38. };
  39. var Api = { get: get };
  40. var firePastePreProcess = function (editor, html, internal, isWordHtml) {
  41. return editor.fire('PastePreProcess', {
  42. content: html,
  43. internal: internal,
  44. wordContent: isWordHtml
  45. });
  46. };
  47. var firePastePostProcess = function (editor, node, internal, isWordHtml) {
  48. return editor.fire('PastePostProcess', {
  49. node: node,
  50. internal: internal,
  51. wordContent: isWordHtml
  52. });
  53. };
  54. var firePastePlainTextToggle = function (editor, state) {
  55. return editor.fire('PastePlainTextToggle', { state: state });
  56. };
  57. var firePaste = function (editor, ieFake) {
  58. return editor.fire('paste', { ieFake: ieFake });
  59. };
  60. var Events = {
  61. firePastePreProcess: firePastePreProcess,
  62. firePastePostProcess: firePastePostProcess,
  63. firePastePlainTextToggle: firePastePlainTextToggle,
  64. firePaste: firePaste
  65. };
  66. var shouldPlainTextInform = function (editor) {
  67. return editor.getParam('paste_plaintext_inform', true);
  68. };
  69. var shouldBlockDrop = function (editor) {
  70. return editor.getParam('paste_block_drop', false);
  71. };
  72. var shouldPasteDataImages = function (editor) {
  73. return editor.getParam('paste_data_images', false);
  74. };
  75. var shouldFilterDrop = function (editor) {
  76. return editor.getParam('paste_filter_drop', true);
  77. };
  78. var getPreProcess = function (editor) {
  79. return editor.getParam('paste_preprocess');
  80. };
  81. var getPostProcess = function (editor) {
  82. return editor.getParam('paste_postprocess');
  83. };
  84. var getWebkitStyles = function (editor) {
  85. return editor.getParam('paste_webkit_styles');
  86. };
  87. var shouldRemoveWebKitStyles = function (editor) {
  88. return editor.getParam('paste_remove_styles_if_webkit', true);
  89. };
  90. var shouldMergeFormats = function (editor) {
  91. return editor.getParam('paste_merge_formats', true);
  92. };
  93. var isSmartPasteEnabled = function (editor) {
  94. return editor.getParam('smart_paste', true);
  95. };
  96. var isPasteAsTextEnabled = function (editor) {
  97. return editor.getParam('paste_as_text', false);
  98. };
  99. var getRetainStyleProps = function (editor) {
  100. return editor.getParam('paste_retain_style_properties');
  101. };
  102. var getWordValidElements = function (editor) {
  103. var defaultValidElements = '-strong/b,-em/i,-u,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' + '-p/div,-a[href|name],sub,sup,strike,br,del,table[width],tr,' + 'td[colspan|rowspan|width],th[colspan|rowspan|width],thead,tfoot,tbody';
  104. return editor.getParam('paste_word_valid_elements', defaultValidElements);
  105. };
  106. var shouldConvertWordFakeLists = function (editor) {
  107. return editor.getParam('paste_convert_word_fake_lists', true);
  108. };
  109. var shouldUseDefaultFilters = function (editor) {
  110. return editor.getParam('paste_enable_default_filters', true);
  111. };
  112. var Settings = {
  113. shouldPlainTextInform: shouldPlainTextInform,
  114. shouldBlockDrop: shouldBlockDrop,
  115. shouldPasteDataImages: shouldPasteDataImages,
  116. shouldFilterDrop: shouldFilterDrop,
  117. getPreProcess: getPreProcess,
  118. getPostProcess: getPostProcess,
  119. getWebkitStyles: getWebkitStyles,
  120. shouldRemoveWebKitStyles: shouldRemoveWebKitStyles,
  121. shouldMergeFormats: shouldMergeFormats,
  122. isSmartPasteEnabled: isSmartPasteEnabled,
  123. isPasteAsTextEnabled: isPasteAsTextEnabled,
  124. getRetainStyleProps: getRetainStyleProps,
  125. getWordValidElements: getWordValidElements,
  126. shouldConvertWordFakeLists: shouldConvertWordFakeLists,
  127. shouldUseDefaultFilters: shouldUseDefaultFilters
  128. };
  129. var shouldInformUserAboutPlainText = function (editor, userIsInformedState) {
  130. return userIsInformedState.get() === false && Settings.shouldPlainTextInform(editor);
  131. };
  132. var displayNotification = function (editor, message) {
  133. editor.notificationManager.open({
  134. text: editor.translate(message),
  135. type: 'info'
  136. });
  137. };
  138. var togglePlainTextPaste = function (editor, clipboard, userIsInformedState) {
  139. if (clipboard.pasteFormat.get() === 'text') {
  140. clipboard.pasteFormat.set('html');
  141. Events.firePastePlainTextToggle(editor, false);
  142. } else {
  143. clipboard.pasteFormat.set('text');
  144. Events.firePastePlainTextToggle(editor, true);
  145. if (shouldInformUserAboutPlainText(editor, userIsInformedState)) {
  146. displayNotification(editor, 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.');
  147. userIsInformedState.set(true);
  148. }
  149. }
  150. editor.focus();
  151. };
  152. var Actions = { togglePlainTextPaste: togglePlainTextPaste };
  153. var register = function (editor, clipboard, userIsInformedState) {
  154. editor.addCommand('mceTogglePlainTextPaste', function () {
  155. Actions.togglePlainTextPaste(editor, clipboard, userIsInformedState);
  156. });
  157. editor.addCommand('mceInsertClipboardContent', function (ui, value) {
  158. if (value.content) {
  159. clipboard.pasteHtml(value.content, value.internal);
  160. }
  161. if (value.text) {
  162. clipboard.pasteText(value.text);
  163. }
  164. });
  165. };
  166. var Commands = { register: register };
  167. var global$2 = tinymce.util.Tools.resolve('tinymce.Env');
  168. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Delay');
  169. var global$4 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  170. var global$5 = tinymce.util.Tools.resolve('tinymce.util.VK');
  171. var internalMimeType = 'x-tinymce/html';
  172. var internalMark = '<!-- ' + internalMimeType + ' -->';
  173. var mark = function (html) {
  174. return internalMark + html;
  175. };
  176. var unmark = function (html) {
  177. return html.replace(internalMark, '');
  178. };
  179. var isMarked = function (html) {
  180. return html.indexOf(internalMark) !== -1;
  181. };
  182. var InternalHtml = {
  183. mark: mark,
  184. unmark: unmark,
  185. isMarked: isMarked,
  186. internalHtmlMime: function () {
  187. return internalMimeType;
  188. }
  189. };
  190. var global$6 = tinymce.util.Tools.resolve('tinymce.html.Entities');
  191. var isPlainText = function (text) {
  192. return !/<(?:\/?(?!(?:div|p|br|span)>)\w+|(?:(?!(?:span style="white-space:\s?pre;?">)|br\s?\/>))\w+\s[^>]+)>/i.test(text);
  193. };
  194. var toBRs = function (text) {
  195. return text.replace(/\r?\n/g, '<br>');
  196. };
  197. var openContainer = function (rootTag, rootAttrs) {
  198. var key;
  199. var attrs = [];
  200. var tag = '<' + rootTag;
  201. if (typeof rootAttrs === 'object') {
  202. for (key in rootAttrs) {
  203. if (rootAttrs.hasOwnProperty(key)) {
  204. attrs.push(key + '="' + global$6.encodeAllRaw(rootAttrs[key]) + '"');
  205. }
  206. }
  207. if (attrs.length) {
  208. tag += ' ' + attrs.join(' ');
  209. }
  210. }
  211. return tag + '>';
  212. };
  213. var toBlockElements = function (text, rootTag, rootAttrs) {
  214. var blocks = text.split(/\n\n/);
  215. var tagOpen = openContainer(rootTag, rootAttrs);
  216. var tagClose = '</' + rootTag + '>';
  217. var paragraphs = global$4.map(blocks, function (p) {
  218. return p.split(/\n/).join('<br />');
  219. });
  220. var stitch = function (p) {
  221. return tagOpen + p + tagClose;
  222. };
  223. return paragraphs.length === 1 ? paragraphs[0] : global$4.map(paragraphs, stitch).join('');
  224. };
  225. var convert = function (text, rootTag, rootAttrs) {
  226. return rootTag ? toBlockElements(text, rootTag, rootAttrs) : toBRs(text);
  227. };
  228. var Newlines = {
  229. isPlainText: isPlainText,
  230. convert: convert,
  231. toBRs: toBRs,
  232. toBlockElements: toBlockElements
  233. };
  234. var global$7 = tinymce.util.Tools.resolve('tinymce.html.DomParser');
  235. var global$8 = tinymce.util.Tools.resolve('tinymce.html.Node');
  236. var global$9 = tinymce.util.Tools.resolve('tinymce.html.Schema');
  237. var global$a = tinymce.util.Tools.resolve('tinymce.html.Serializer');
  238. function filter(content, items) {
  239. global$4.each(items, function (v) {
  240. if (v.constructor === RegExp) {
  241. content = content.replace(v, '');
  242. } else {
  243. content = content.replace(v[0], v[1]);
  244. }
  245. });
  246. return content;
  247. }
  248. function innerText(html) {
  249. var schema = global$9();
  250. var domParser = global$7({}, schema);
  251. var text = '';
  252. var shortEndedElements = schema.getShortEndedElements();
  253. var ignoreElements = global$4.makeMap('script noscript style textarea video audio iframe object', ' ');
  254. var blockElements = schema.getBlockElements();
  255. function walk(node) {
  256. var name = node.name, currentNode = node;
  257. if (name === 'br') {
  258. text += '\n';
  259. return;
  260. }
  261. if (name === 'wbr') {
  262. return;
  263. }
  264. if (shortEndedElements[name]) {
  265. text += ' ';
  266. }
  267. if (ignoreElements[name]) {
  268. text += ' ';
  269. return;
  270. }
  271. if (node.type === 3) {
  272. text += node.value;
  273. }
  274. if (!node.shortEnded) {
  275. if (node = node.firstChild) {
  276. do {
  277. walk(node);
  278. } while (node = node.next);
  279. }
  280. }
  281. if (blockElements[name] && currentNode.next) {
  282. text += '\n';
  283. if (name === 'p') {
  284. text += '\n';
  285. }
  286. }
  287. }
  288. html = filter(html, [/<!\[[^\]]+\]>/g]);
  289. walk(domParser.parse(html));
  290. return text;
  291. }
  292. function trimHtml(html) {
  293. function trimSpaces(all, s1, s2) {
  294. if (!s1 && !s2) {
  295. return ' ';
  296. }
  297. return '\xA0';
  298. }
  299. html = filter(html, [
  300. /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
  301. /<!--StartFragment-->|<!--EndFragment-->/g,
  302. [
  303. /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
  304. trimSpaces
  305. ],
  306. /<br class="Apple-interchange-newline">/g,
  307. /<br>$/i
  308. ]);
  309. return html;
  310. }
  311. function createIdGenerator(prefix) {
  312. var count = 0;
  313. return function () {
  314. return prefix + count++;
  315. };
  316. }
  317. var isMsEdge = function () {
  318. return domGlobals.navigator.userAgent.indexOf(' Edge/') !== -1;
  319. };
  320. var Utils = {
  321. filter: filter,
  322. innerText: innerText,
  323. trimHtml: trimHtml,
  324. createIdGenerator: createIdGenerator,
  325. isMsEdge: isMsEdge
  326. };
  327. function isWordContent(content) {
  328. return /<font face="Times New Roman"|class="?Mso|style="[^"]*\bmso-|style='[^'']*\bmso-|w:WordDocument/i.test(content) || /class="OutlineElement/.test(content) || /id="?docs\-internal\-guid\-/.test(content);
  329. }
  330. function isNumericList(text) {
  331. var found, patterns;
  332. patterns = [
  333. /^[IVXLMCD]{1,2}\.[ \u00a0]/,
  334. /^[ivxlmcd]{1,2}\.[ \u00a0]/,
  335. /^[a-z]{1,2}[\.\)][ \u00a0]/,
  336. /^[A-Z]{1,2}[\.\)][ \u00a0]/,
  337. /^[0-9]+\.[ \u00a0]/,
  338. /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
  339. /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
  340. ];
  341. text = text.replace(/^[\u00a0 ]+/, '');
  342. global$4.each(patterns, function (pattern) {
  343. if (pattern.test(text)) {
  344. found = true;
  345. return false;
  346. }
  347. });
  348. return found;
  349. }
  350. function isBulletList(text) {
  351. return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
  352. }
  353. function convertFakeListsToProperLists(node) {
  354. var currentListNode, prevListNode, lastLevel = 1;
  355. function getText(node) {
  356. var txt = '';
  357. if (node.type === 3) {
  358. return node.value;
  359. }
  360. if (node = node.firstChild) {
  361. do {
  362. txt += getText(node);
  363. } while (node = node.next);
  364. }
  365. return txt;
  366. }
  367. function trimListStart(node, regExp) {
  368. if (node.type === 3) {
  369. if (regExp.test(node.value)) {
  370. node.value = node.value.replace(regExp, '');
  371. return false;
  372. }
  373. }
  374. if (node = node.firstChild) {
  375. do {
  376. if (!trimListStart(node, regExp)) {
  377. return false;
  378. }
  379. } while (node = node.next);
  380. }
  381. return true;
  382. }
  383. function removeIgnoredNodes(node) {
  384. if (node._listIgnore) {
  385. node.remove();
  386. return;
  387. }
  388. if (node = node.firstChild) {
  389. do {
  390. removeIgnoredNodes(node);
  391. } while (node = node.next);
  392. }
  393. }
  394. function convertParagraphToLi(paragraphNode, listName, start) {
  395. var level = paragraphNode._listLevel || lastLevel;
  396. if (level !== lastLevel) {
  397. if (level < lastLevel) {
  398. if (currentListNode) {
  399. currentListNode = currentListNode.parent.parent;
  400. }
  401. } else {
  402. prevListNode = currentListNode;
  403. currentListNode = null;
  404. }
  405. }
  406. if (!currentListNode || currentListNode.name !== listName) {
  407. prevListNode = prevListNode || currentListNode;
  408. currentListNode = new global$8(listName, 1);
  409. if (start > 1) {
  410. currentListNode.attr('start', '' + start);
  411. }
  412. paragraphNode.wrap(currentListNode);
  413. } else {
  414. currentListNode.append(paragraphNode);
  415. }
  416. paragraphNode.name = 'li';
  417. if (level > lastLevel && prevListNode) {
  418. prevListNode.lastChild.append(currentListNode);
  419. }
  420. lastLevel = level;
  421. removeIgnoredNodes(paragraphNode);
  422. trimListStart(paragraphNode, /^\u00a0+/);
  423. trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
  424. trimListStart(paragraphNode, /^\u00a0+/);
  425. }
  426. var elements = [];
  427. var child = node.firstChild;
  428. while (typeof child !== 'undefined' && child !== null) {
  429. elements.push(child);
  430. child = child.walk();
  431. if (child !== null) {
  432. while (typeof child !== 'undefined' && child.parent !== node) {
  433. child = child.walk();
  434. }
  435. }
  436. }
  437. for (var i = 0; i < elements.length; i++) {
  438. node = elements[i];
  439. if (node.name === 'p' && node.firstChild) {
  440. var nodeText = getText(node);
  441. if (isBulletList(nodeText)) {
  442. convertParagraphToLi(node, 'ul');
  443. continue;
  444. }
  445. if (isNumericList(nodeText)) {
  446. var matches = /([0-9]+)\./.exec(nodeText);
  447. var start = 1;
  448. if (matches) {
  449. start = parseInt(matches[1], 10);
  450. }
  451. convertParagraphToLi(node, 'ol', start);
  452. continue;
  453. }
  454. if (node._listLevel) {
  455. convertParagraphToLi(node, 'ul', 1);
  456. continue;
  457. }
  458. currentListNode = null;
  459. } else {
  460. prevListNode = currentListNode;
  461. currentListNode = null;
  462. }
  463. }
  464. }
  465. function filterStyles(editor, validStyles, node, styleValue) {
  466. var outputStyles = {}, matches;
  467. var styles = editor.dom.parseStyle(styleValue);
  468. global$4.each(styles, function (value, name) {
  469. switch (name) {
  470. case 'mso-list':
  471. matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
  472. if (matches) {
  473. node._listLevel = parseInt(matches[1], 10);
  474. }
  475. if (/Ignore/i.test(value) && node.firstChild) {
  476. node._listIgnore = true;
  477. node.firstChild._listIgnore = true;
  478. }
  479. break;
  480. case 'horiz-align':
  481. name = 'text-align';
  482. break;
  483. case 'vert-align':
  484. name = 'vertical-align';
  485. break;
  486. case 'font-color':
  487. case 'mso-foreground':
  488. name = 'color';
  489. break;
  490. case 'mso-background':
  491. case 'mso-highlight':
  492. name = 'background';
  493. break;
  494. case 'font-weight':
  495. case 'font-style':
  496. if (value !== 'normal') {
  497. outputStyles[name] = value;
  498. }
  499. return;
  500. case 'mso-element':
  501. if (/^(comment|comment-list)$/i.test(value)) {
  502. node.remove();
  503. return;
  504. }
  505. break;
  506. }
  507. if (name.indexOf('mso-comment') === 0) {
  508. node.remove();
  509. return;
  510. }
  511. if (name.indexOf('mso-') === 0) {
  512. return;
  513. }
  514. if (Settings.getRetainStyleProps(editor) === 'all' || validStyles && validStyles[name]) {
  515. outputStyles[name] = value;
  516. }
  517. });
  518. if (/(bold)/i.test(outputStyles['font-weight'])) {
  519. delete outputStyles['font-weight'];
  520. node.wrap(new global$8('b', 1));
  521. }
  522. if (/(italic)/i.test(outputStyles['font-style'])) {
  523. delete outputStyles['font-style'];
  524. node.wrap(new global$8('i', 1));
  525. }
  526. outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
  527. if (outputStyles) {
  528. return outputStyles;
  529. }
  530. return null;
  531. }
  532. var filterWordContent = function (editor, content) {
  533. var retainStyleProperties, validStyles;
  534. retainStyleProperties = Settings.getRetainStyleProps(editor);
  535. if (retainStyleProperties) {
  536. validStyles = global$4.makeMap(retainStyleProperties.split(/[, ]/));
  537. }
  538. content = Utils.filter(content, [
  539. /<br class="?Apple-interchange-newline"?>/gi,
  540. /<b[^>]+id="?docs-internal-[^>]*>/gi,
  541. /<!--[\s\S]+?-->/gi,
  542. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
  543. [
  544. /<(\/?)s>/gi,
  545. '<$1strike>'
  546. ],
  547. [
  548. /&nbsp;/gi,
  549. '\xA0'
  550. ],
  551. [
  552. /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
  553. function (str, spaces) {
  554. return spaces.length > 0 ? spaces.replace(/./, ' ').slice(Math.floor(spaces.length / 2)).split('').join('\xA0') : '';
  555. }
  556. ]
  557. ]);
  558. var validElements = Settings.getWordValidElements(editor);
  559. var schema = global$9({
  560. valid_elements: validElements,
  561. valid_children: '-li[p]'
  562. });
  563. global$4.each(schema.elements, function (rule) {
  564. if (!rule.attributes.class) {
  565. rule.attributes.class = {};
  566. rule.attributesOrder.push('class');
  567. }
  568. if (!rule.attributes.style) {
  569. rule.attributes.style = {};
  570. rule.attributesOrder.push('style');
  571. }
  572. });
  573. var domParser = global$7({}, schema);
  574. domParser.addAttributeFilter('style', function (nodes) {
  575. var i = nodes.length, node;
  576. while (i--) {
  577. node = nodes[i];
  578. node.attr('style', filterStyles(editor, validStyles, node, node.attr('style')));
  579. if (node.name === 'span' && node.parent && !node.attributes.length) {
  580. node.unwrap();
  581. }
  582. }
  583. });
  584. domParser.addAttributeFilter('class', function (nodes) {
  585. var i = nodes.length, node, className;
  586. while (i--) {
  587. node = nodes[i];
  588. className = node.attr('class');
  589. if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
  590. node.remove();
  591. }
  592. node.attr('class', null);
  593. }
  594. });
  595. domParser.addNodeFilter('del', function (nodes) {
  596. var i = nodes.length;
  597. while (i--) {
  598. nodes[i].remove();
  599. }
  600. });
  601. domParser.addNodeFilter('a', function (nodes) {
  602. var i = nodes.length, node, href, name;
  603. while (i--) {
  604. node = nodes[i];
  605. href = node.attr('href');
  606. name = node.attr('name');
  607. if (href && href.indexOf('#_msocom_') !== -1) {
  608. node.remove();
  609. continue;
  610. }
  611. if (href && href.indexOf('file://') === 0) {
  612. href = href.split('#')[1];
  613. if (href) {
  614. href = '#' + href;
  615. }
  616. }
  617. if (!href && !name) {
  618. node.unwrap();
  619. } else {
  620. if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
  621. node.unwrap();
  622. continue;
  623. }
  624. node.attr({
  625. href: href,
  626. name: name
  627. });
  628. }
  629. }
  630. });
  631. var rootNode = domParser.parse(content);
  632. if (Settings.shouldConvertWordFakeLists(editor)) {
  633. convertFakeListsToProperLists(rootNode);
  634. }
  635. content = global$a({ validate: editor.settings.validate }, schema).serialize(rootNode);
  636. return content;
  637. };
  638. var preProcess = function (editor, content) {
  639. return Settings.shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
  640. };
  641. var WordFilter = {
  642. preProcess: preProcess,
  643. isWordContent: isWordContent
  644. };
  645. var processResult = function (content, cancelled) {
  646. return {
  647. content: content,
  648. cancelled: cancelled
  649. };
  650. };
  651. var postProcessFilter = function (editor, html, internal, isWordHtml) {
  652. var tempBody = editor.dom.create('div', { style: 'display:none' }, html);
  653. var postProcessArgs = Events.firePastePostProcess(editor, tempBody, internal, isWordHtml);
  654. return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
  655. };
  656. var filterContent = function (editor, content, internal, isWordHtml) {
  657. var preProcessArgs = Events.firePastePreProcess(editor, content, internal, isWordHtml);
  658. if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) {
  659. return postProcessFilter(editor, preProcessArgs.content, internal, isWordHtml);
  660. } else {
  661. return processResult(preProcessArgs.content, preProcessArgs.isDefaultPrevented());
  662. }
  663. };
  664. var process = function (editor, html, internal) {
  665. var isWordHtml = WordFilter.isWordContent(html);
  666. var content = isWordHtml ? WordFilter.preProcess(editor, html) : html;
  667. return filterContent(editor, content, internal, isWordHtml);
  668. };
  669. var ProcessFilters = { process: process };
  670. var removeMeta = function (editor, html) {
  671. var body = editor.dom.create('body', {}, html);
  672. global$4.each(body.querySelectorAll('meta'), function (elm) {
  673. return elm.parentNode.removeChild(elm);
  674. });
  675. return body.innerHTML;
  676. };
  677. var pasteHtml = function (editor, html) {
  678. editor.insertContent(removeMeta(editor, html), {
  679. merge: Settings.shouldMergeFormats(editor),
  680. paste: true
  681. });
  682. return true;
  683. };
  684. var isAbsoluteUrl = function (url) {
  685. return /^https?:\/\/[\w\?\-\/+=.&%@~#]+$/i.test(url);
  686. };
  687. var isImageUrl = function (url) {
  688. return isAbsoluteUrl(url) && /.(gif|jpe?g|png)$/.test(url);
  689. };
  690. var createImage = function (editor, url, pasteHtmlFn) {
  691. editor.undoManager.extra(function () {
  692. pasteHtmlFn(editor, url);
  693. }, function () {
  694. editor.insertContent('<img src="' + url + '">');
  695. });
  696. return true;
  697. };
  698. var createLink = function (editor, url, pasteHtmlFn) {
  699. editor.undoManager.extra(function () {
  700. pasteHtmlFn(editor, url);
  701. }, function () {
  702. editor.execCommand('mceInsertLink', false, url);
  703. });
  704. return true;
  705. };
  706. var linkSelection = function (editor, html, pasteHtmlFn) {
  707. return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
  708. };
  709. var insertImage = function (editor, html, pasteHtmlFn) {
  710. return isImageUrl(html) ? createImage(editor, html, pasteHtmlFn) : false;
  711. };
  712. var smartInsertContent = function (editor, html) {
  713. global$4.each([
  714. linkSelection,
  715. insertImage,
  716. pasteHtml
  717. ], function (action) {
  718. return action(editor, html, pasteHtml) !== true;
  719. });
  720. };
  721. var insertContent = function (editor, html) {
  722. if (Settings.isSmartPasteEnabled(editor) === false) {
  723. pasteHtml(editor, html);
  724. } else {
  725. smartInsertContent(editor, html);
  726. }
  727. };
  728. var SmartPaste = {
  729. isImageUrl: isImageUrl,
  730. isAbsoluteUrl: isAbsoluteUrl,
  731. insertContent: insertContent
  732. };
  733. var constant = function (value) {
  734. return function () {
  735. return value;
  736. };
  737. };
  738. function curry(fn) {
  739. var initialArgs = [];
  740. for (var _i = 1; _i < arguments.length; _i++) {
  741. initialArgs[_i - 1] = arguments[_i];
  742. }
  743. return function () {
  744. var restArgs = [];
  745. for (var _i = 0; _i < arguments.length; _i++) {
  746. restArgs[_i] = arguments[_i];
  747. }
  748. var all = initialArgs.concat(restArgs);
  749. return fn.apply(null, all);
  750. };
  751. }
  752. var never = constant(false);
  753. var always = constant(true);
  754. var never$1 = never;
  755. var always$1 = always;
  756. var none = function () {
  757. return NONE;
  758. };
  759. var NONE = function () {
  760. var eq = function (o) {
  761. return o.isNone();
  762. };
  763. var call = function (thunk) {
  764. return thunk();
  765. };
  766. var id = function (n) {
  767. return n;
  768. };
  769. var noop = function () {
  770. };
  771. var nul = function () {
  772. return null;
  773. };
  774. var undef = function () {
  775. return undefined;
  776. };
  777. var me = {
  778. fold: function (n, s) {
  779. return n();
  780. },
  781. is: never$1,
  782. isSome: never$1,
  783. isNone: always$1,
  784. getOr: id,
  785. getOrThunk: call,
  786. getOrDie: function (msg) {
  787. throw new Error(msg || 'error: getOrDie called on none.');
  788. },
  789. getOrNull: nul,
  790. getOrUndefined: undef,
  791. or: id,
  792. orThunk: call,
  793. map: none,
  794. ap: none,
  795. each: noop,
  796. bind: none,
  797. flatten: none,
  798. exists: never$1,
  799. forall: always$1,
  800. filter: none,
  801. equals: eq,
  802. equals_: eq,
  803. toArray: function () {
  804. return [];
  805. },
  806. toString: constant('none()')
  807. };
  808. if (Object.freeze) {
  809. Object.freeze(me);
  810. }
  811. return me;
  812. }();
  813. var some = function (a) {
  814. var constant_a = function () {
  815. return a;
  816. };
  817. var self = function () {
  818. return me;
  819. };
  820. var map = function (f) {
  821. return some(f(a));
  822. };
  823. var bind = function (f) {
  824. return f(a);
  825. };
  826. var me = {
  827. fold: function (n, s) {
  828. return s(a);
  829. },
  830. is: function (v) {
  831. return a === v;
  832. },
  833. isSome: always$1,
  834. isNone: never$1,
  835. getOr: constant_a,
  836. getOrThunk: constant_a,
  837. getOrDie: constant_a,
  838. getOrNull: constant_a,
  839. getOrUndefined: constant_a,
  840. or: self,
  841. orThunk: self,
  842. map: map,
  843. ap: function (optfab) {
  844. return optfab.fold(none, function (fab) {
  845. return some(fab(a));
  846. });
  847. },
  848. each: function (f) {
  849. f(a);
  850. },
  851. bind: bind,
  852. flatten: constant_a,
  853. exists: bind,
  854. forall: bind,
  855. filter: function (f) {
  856. return f(a) ? me : NONE;
  857. },
  858. equals: function (o) {
  859. return o.is(a);
  860. },
  861. equals_: function (o, elementEq) {
  862. return o.fold(never$1, function (b) {
  863. return elementEq(a, b);
  864. });
  865. },
  866. toArray: function () {
  867. return [a];
  868. },
  869. toString: function () {
  870. return 'some(' + a + ')';
  871. }
  872. };
  873. return me;
  874. };
  875. var from = function (value) {
  876. return value === null || value === undefined ? NONE : some(value);
  877. };
  878. var Option = {
  879. some: some,
  880. none: none,
  881. from: from
  882. };
  883. var typeOf = function (x) {
  884. if (x === null) {
  885. return 'null';
  886. }
  887. var t = typeof x;
  888. if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  889. return 'array';
  890. }
  891. if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  892. return 'string';
  893. }
  894. return t;
  895. };
  896. var isType = function (type) {
  897. return function (value) {
  898. return typeOf(value) === type;
  899. };
  900. };
  901. var isFunction = isType('function');
  902. var slice = Array.prototype.slice;
  903. var map = function (xs, f) {
  904. var len = xs.length;
  905. var r = new Array(len);
  906. for (var i = 0; i < len; i++) {
  907. var x = xs[i];
  908. r[i] = f(x, i, xs);
  909. }
  910. return r;
  911. };
  912. var each = function (xs, f) {
  913. for (var i = 0, len = xs.length; i < len; i++) {
  914. var x = xs[i];
  915. f(x, i, xs);
  916. }
  917. };
  918. var filter$1 = function (xs, pred) {
  919. var r = [];
  920. for (var i = 0, len = xs.length; i < len; i++) {
  921. var x = xs[i];
  922. if (pred(x, i, xs)) {
  923. r.push(x);
  924. }
  925. }
  926. return r;
  927. };
  928. var from$1 = isFunction(Array.from) ? Array.from : function (x) {
  929. return slice.call(x);
  930. };
  931. var exports$1 = {}, module = { exports: exports$1 };
  932. (function (define, exports, module, require) {
  933. (function (f) {
  934. if (typeof exports === 'object' && typeof module !== 'undefined') {
  935. module.exports = f();
  936. } else if (typeof define === 'function' && define.amd) {
  937. define([], f);
  938. } else {
  939. var g;
  940. if (typeof window !== 'undefined') {
  941. g = window;
  942. } else if (typeof global !== 'undefined') {
  943. g = global;
  944. } else if (typeof self !== 'undefined') {
  945. g = self;
  946. } else {
  947. g = this;
  948. }
  949. g.EphoxContactWrapper = f();
  950. }
  951. }(function () {
  952. return function () {
  953. function r(e, n, t) {
  954. function o(i, f) {
  955. if (!n[i]) {
  956. if (!e[i]) {
  957. var c = 'function' == typeof require && require;
  958. if (!f && c)
  959. return c(i, !0);
  960. if (u)
  961. return u(i, !0);
  962. var a = new Error('Cannot find module \'' + i + '\'');
  963. throw a.code = 'MODULE_NOT_FOUND', a;
  964. }
  965. var p = n[i] = { exports: {} };
  966. e[i][0].call(p.exports, function (r) {
  967. var n = e[i][1][r];
  968. return o(n || r);
  969. }, p, p.exports, r, e, n, t);
  970. }
  971. return n[i].exports;
  972. }
  973. for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
  974. o(t[i]);
  975. return o;
  976. }
  977. return r;
  978. }()({
  979. 1: [
  980. function (require, module, exports) {
  981. var process = module.exports = {};
  982. var cachedSetTimeout;
  983. var cachedClearTimeout;
  984. function defaultSetTimout() {
  985. throw new Error('setTimeout has not been defined');
  986. }
  987. function defaultClearTimeout() {
  988. throw new Error('clearTimeout has not been defined');
  989. }
  990. (function () {
  991. try {
  992. if (typeof setTimeout === 'function') {
  993. cachedSetTimeout = setTimeout;
  994. } else {
  995. cachedSetTimeout = defaultSetTimout;
  996. }
  997. } catch (e) {
  998. cachedSetTimeout = defaultSetTimout;
  999. }
  1000. try {
  1001. if (typeof clearTimeout === 'function') {
  1002. cachedClearTimeout = clearTimeout;
  1003. } else {
  1004. cachedClearTimeout = defaultClearTimeout;
  1005. }
  1006. } catch (e) {
  1007. cachedClearTimeout = defaultClearTimeout;
  1008. }
  1009. }());
  1010. function runTimeout(fun) {
  1011. if (cachedSetTimeout === setTimeout) {
  1012. return setTimeout(fun, 0);
  1013. }
  1014. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1015. cachedSetTimeout = setTimeout;
  1016. return setTimeout(fun, 0);
  1017. }
  1018. try {
  1019. return cachedSetTimeout(fun, 0);
  1020. } catch (e) {
  1021. try {
  1022. return cachedSetTimeout.call(null, fun, 0);
  1023. } catch (e) {
  1024. return cachedSetTimeout.call(this, fun, 0);
  1025. }
  1026. }
  1027. }
  1028. function runClearTimeout(marker) {
  1029. if (cachedClearTimeout === clearTimeout) {
  1030. return clearTimeout(marker);
  1031. }
  1032. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1033. cachedClearTimeout = clearTimeout;
  1034. return clearTimeout(marker);
  1035. }
  1036. try {
  1037. return cachedClearTimeout(marker);
  1038. } catch (e) {
  1039. try {
  1040. return cachedClearTimeout.call(null, marker);
  1041. } catch (e) {
  1042. return cachedClearTimeout.call(this, marker);
  1043. }
  1044. }
  1045. }
  1046. var queue = [];
  1047. var draining = false;
  1048. var currentQueue;
  1049. var queueIndex = -1;
  1050. function cleanUpNextTick() {
  1051. if (!draining || !currentQueue) {
  1052. return;
  1053. }
  1054. draining = false;
  1055. if (currentQueue.length) {
  1056. queue = currentQueue.concat(queue);
  1057. } else {
  1058. queueIndex = -1;
  1059. }
  1060. if (queue.length) {
  1061. drainQueue();
  1062. }
  1063. }
  1064. function drainQueue() {
  1065. if (draining) {
  1066. return;
  1067. }
  1068. var timeout = runTimeout(cleanUpNextTick);
  1069. draining = true;
  1070. var len = queue.length;
  1071. while (len) {
  1072. currentQueue = queue;
  1073. queue = [];
  1074. while (++queueIndex < len) {
  1075. if (currentQueue) {
  1076. currentQueue[queueIndex].run();
  1077. }
  1078. }
  1079. queueIndex = -1;
  1080. len = queue.length;
  1081. }
  1082. currentQueue = null;
  1083. draining = false;
  1084. runClearTimeout(timeout);
  1085. }
  1086. process.nextTick = function (fun) {
  1087. var args = new Array(arguments.length - 1);
  1088. if (arguments.length > 1) {
  1089. for (var i = 1; i < arguments.length; i++) {
  1090. args[i - 1] = arguments[i];
  1091. }
  1092. }
  1093. queue.push(new Item(fun, args));
  1094. if (queue.length === 1 && !draining) {
  1095. runTimeout(drainQueue);
  1096. }
  1097. };
  1098. function Item(fun, array) {
  1099. this.fun = fun;
  1100. this.array = array;
  1101. }
  1102. Item.prototype.run = function () {
  1103. this.fun.apply(null, this.array);
  1104. };
  1105. process.title = 'browser';
  1106. process.browser = true;
  1107. process.env = {};
  1108. process.argv = [];
  1109. process.version = '';
  1110. process.versions = {};
  1111. function noop() {
  1112. }
  1113. process.on = noop;
  1114. process.addListener = noop;
  1115. process.once = noop;
  1116. process.off = noop;
  1117. process.removeListener = noop;
  1118. process.removeAllListeners = noop;
  1119. process.emit = noop;
  1120. process.prependListener = noop;
  1121. process.prependOnceListener = noop;
  1122. process.listeners = function (name) {
  1123. return [];
  1124. };
  1125. process.binding = function (name) {
  1126. throw new Error('process.binding is not supported');
  1127. };
  1128. process.cwd = function () {
  1129. return '/';
  1130. };
  1131. process.chdir = function (dir) {
  1132. throw new Error('process.chdir is not supported');
  1133. };
  1134. process.umask = function () {
  1135. return 0;
  1136. };
  1137. },
  1138. {}
  1139. ],
  1140. 2: [
  1141. function (require, module, exports) {
  1142. (function (setImmediate) {
  1143. (function (root) {
  1144. var setTimeoutFunc = setTimeout;
  1145. function noop() {
  1146. }
  1147. function bind(fn, thisArg) {
  1148. return function () {
  1149. fn.apply(thisArg, arguments);
  1150. };
  1151. }
  1152. function Promise(fn) {
  1153. if (typeof this !== 'object')
  1154. throw new TypeError('Promises must be constructed via new');
  1155. if (typeof fn !== 'function')
  1156. throw new TypeError('not a function');
  1157. this._state = 0;
  1158. this._handled = false;
  1159. this._value = undefined;
  1160. this._deferreds = [];
  1161. doResolve(fn, this);
  1162. }
  1163. function handle(self, deferred) {
  1164. while (self._state === 3) {
  1165. self = self._value;
  1166. }
  1167. if (self._state === 0) {
  1168. self._deferreds.push(deferred);
  1169. return;
  1170. }
  1171. self._handled = true;
  1172. Promise._immediateFn(function () {
  1173. var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  1174. if (cb === null) {
  1175. (self._state === 1 ? resolve : reject)(deferred.promise, self._value);
  1176. return;
  1177. }
  1178. var ret;
  1179. try {
  1180. ret = cb(self._value);
  1181. } catch (e) {
  1182. reject(deferred.promise, e);
  1183. return;
  1184. }
  1185. resolve(deferred.promise, ret);
  1186. });
  1187. }
  1188. function resolve(self, newValue) {
  1189. try {
  1190. if (newValue === self)
  1191. throw new TypeError('A promise cannot be resolved with itself.');
  1192. if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
  1193. var then = newValue.then;
  1194. if (newValue instanceof Promise) {
  1195. self._state = 3;
  1196. self._value = newValue;
  1197. finale(self);
  1198. return;
  1199. } else if (typeof then === 'function') {
  1200. doResolve(bind(then, newValue), self);
  1201. return;
  1202. }
  1203. }
  1204. self._state = 1;
  1205. self._value = newValue;
  1206. finale(self);
  1207. } catch (e) {
  1208. reject(self, e);
  1209. }
  1210. }
  1211. function reject(self, newValue) {
  1212. self._state = 2;
  1213. self._value = newValue;
  1214. finale(self);
  1215. }
  1216. function finale(self) {
  1217. if (self._state === 2 && self._deferreds.length === 0) {
  1218. Promise._immediateFn(function () {
  1219. if (!self._handled) {
  1220. Promise._unhandledRejectionFn(self._value);
  1221. }
  1222. });
  1223. }
  1224. for (var i = 0, len = self._deferreds.length; i < len; i++) {
  1225. handle(self, self._deferreds[i]);
  1226. }
  1227. self._deferreds = null;
  1228. }
  1229. function Handler(onFulfilled, onRejected, promise) {
  1230. this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
  1231. this.onRejected = typeof onRejected === 'function' ? onRejected : null;
  1232. this.promise = promise;
  1233. }
  1234. function doResolve(fn, self) {
  1235. var done = false;
  1236. try {
  1237. fn(function (value) {
  1238. if (done)
  1239. return;
  1240. done = true;
  1241. resolve(self, value);
  1242. }, function (reason) {
  1243. if (done)
  1244. return;
  1245. done = true;
  1246. reject(self, reason);
  1247. });
  1248. } catch (ex) {
  1249. if (done)
  1250. return;
  1251. done = true;
  1252. reject(self, ex);
  1253. }
  1254. }
  1255. Promise.prototype['catch'] = function (onRejected) {
  1256. return this.then(null, onRejected);
  1257. };
  1258. Promise.prototype.then = function (onFulfilled, onRejected) {
  1259. var prom = new this.constructor(noop);
  1260. handle(this, new Handler(onFulfilled, onRejected, prom));
  1261. return prom;
  1262. };
  1263. Promise.all = function (arr) {
  1264. var args = Array.prototype.slice.call(arr);
  1265. return new Promise(function (resolve, reject) {
  1266. if (args.length === 0)
  1267. return resolve([]);
  1268. var remaining = args.length;
  1269. function res(i, val) {
  1270. try {
  1271. if (val && (typeof val === 'object' || typeof val === 'function')) {
  1272. var then = val.then;
  1273. if (typeof then === 'function') {
  1274. then.call(val, function (val) {
  1275. res(i, val);
  1276. }, reject);
  1277. return;
  1278. }
  1279. }
  1280. args[i] = val;
  1281. if (--remaining === 0) {
  1282. resolve(args);
  1283. }
  1284. } catch (ex) {
  1285. reject(ex);
  1286. }
  1287. }
  1288. for (var i = 0; i < args.length; i++) {
  1289. res(i, args[i]);
  1290. }
  1291. });
  1292. };
  1293. Promise.resolve = function (value) {
  1294. if (value && typeof value === 'object' && value.constructor === Promise) {
  1295. return value;
  1296. }
  1297. return new Promise(function (resolve) {
  1298. resolve(value);
  1299. });
  1300. };
  1301. Promise.reject = function (value) {
  1302. return new Promise(function (resolve, reject) {
  1303. reject(value);
  1304. });
  1305. };
  1306. Promise.race = function (values) {
  1307. return new Promise(function (resolve, reject) {
  1308. for (var i = 0, len = values.length; i < len; i++) {
  1309. values[i].then(resolve, reject);
  1310. }
  1311. });
  1312. };
  1313. Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
  1314. setImmediate(fn);
  1315. } : function (fn) {
  1316. setTimeoutFunc(fn, 0);
  1317. };
  1318. Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  1319. if (typeof console !== 'undefined' && console) {
  1320. console.warn('Possible Unhandled Promise Rejection:', err);
  1321. }
  1322. };
  1323. Promise._setImmediateFn = function _setImmediateFn(fn) {
  1324. Promise._immediateFn = fn;
  1325. };
  1326. Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  1327. Promise._unhandledRejectionFn = fn;
  1328. };
  1329. if (typeof module !== 'undefined' && module.exports) {
  1330. module.exports = Promise;
  1331. } else if (!root.Promise) {
  1332. root.Promise = Promise;
  1333. }
  1334. }(this));
  1335. }.call(this, require('timers').setImmediate));
  1336. },
  1337. { 'timers': 3 }
  1338. ],
  1339. 3: [
  1340. function (require, module, exports) {
  1341. (function (setImmediate, clearImmediate) {
  1342. var nextTick = require('process/browser.js').nextTick;
  1343. var apply = Function.prototype.apply;
  1344. var slice = Array.prototype.slice;
  1345. var immediateIds = {};
  1346. var nextImmediateId = 0;
  1347. exports.setTimeout = function () {
  1348. return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
  1349. };
  1350. exports.setInterval = function () {
  1351. return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
  1352. };
  1353. exports.clearTimeout = exports.clearInterval = function (timeout) {
  1354. timeout.close();
  1355. };
  1356. function Timeout(id, clearFn) {
  1357. this._id = id;
  1358. this._clearFn = clearFn;
  1359. }
  1360. Timeout.prototype.unref = Timeout.prototype.ref = function () {
  1361. };
  1362. Timeout.prototype.close = function () {
  1363. this._clearFn.call(window, this._id);
  1364. };
  1365. exports.enroll = function (item, msecs) {
  1366. clearTimeout(item._idleTimeoutId);
  1367. item._idleTimeout = msecs;
  1368. };
  1369. exports.unenroll = function (item) {
  1370. clearTimeout(item._idleTimeoutId);
  1371. item._idleTimeout = -1;
  1372. };
  1373. exports._unrefActive = exports.active = function (item) {
  1374. clearTimeout(item._idleTimeoutId);
  1375. var msecs = item._idleTimeout;
  1376. if (msecs >= 0) {
  1377. item._idleTimeoutId = setTimeout(function onTimeout() {
  1378. if (item._onTimeout)
  1379. item._onTimeout();
  1380. }, msecs);
  1381. }
  1382. };
  1383. exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
  1384. var id = nextImmediateId++;
  1385. var args = arguments.length < 2 ? false : slice.call(arguments, 1);
  1386. immediateIds[id] = true;
  1387. nextTick(function onNextTick() {
  1388. if (immediateIds[id]) {
  1389. if (args) {
  1390. fn.apply(null, args);
  1391. } else {
  1392. fn.call(null);
  1393. }
  1394. exports.clearImmediate(id);
  1395. }
  1396. });
  1397. return id;
  1398. };
  1399. exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
  1400. delete immediateIds[id];
  1401. };
  1402. }.call(this, require('timers').setImmediate, require('timers').clearImmediate));
  1403. },
  1404. {
  1405. 'process/browser.js': 1,
  1406. 'timers': 3
  1407. }
  1408. ],
  1409. 4: [
  1410. function (require, module, exports) {
  1411. var promisePolyfill = require('promise-polyfill');
  1412. var Global = function () {
  1413. if (typeof window !== 'undefined') {
  1414. return window;
  1415. } else {
  1416. return Function('return this;')();
  1417. }
  1418. }();
  1419. module.exports = { boltExport: Global.Promise || promisePolyfill };
  1420. },
  1421. { 'promise-polyfill': 2 }
  1422. ]
  1423. }, {}, [4])(4);
  1424. }));
  1425. }(undefined, exports$1, module, undefined));
  1426. var Promise = module.exports.boltExport;
  1427. var nu = function (baseFn) {
  1428. var data = Option.none();
  1429. var callbacks = [];
  1430. var map = function (f) {
  1431. return nu(function (nCallback) {
  1432. get(function (data) {
  1433. nCallback(f(data));
  1434. });
  1435. });
  1436. };
  1437. var get = function (nCallback) {
  1438. if (isReady()) {
  1439. call(nCallback);
  1440. } else {
  1441. callbacks.push(nCallback);
  1442. }
  1443. };
  1444. var set = function (x) {
  1445. data = Option.some(x);
  1446. run(callbacks);
  1447. callbacks = [];
  1448. };
  1449. var isReady = function () {
  1450. return data.isSome();
  1451. };
  1452. var run = function (cbs) {
  1453. each(cbs, call);
  1454. };
  1455. var call = function (cb) {
  1456. data.each(function (x) {
  1457. domGlobals.setTimeout(function () {
  1458. cb(x);
  1459. }, 0);
  1460. });
  1461. };
  1462. baseFn(set);
  1463. return {
  1464. get: get,
  1465. map: map,
  1466. isReady: isReady
  1467. };
  1468. };
  1469. var pure = function (a) {
  1470. return nu(function (callback) {
  1471. callback(a);
  1472. });
  1473. };
  1474. var LazyValue = {
  1475. nu: nu,
  1476. pure: pure
  1477. };
  1478. var errorReporter = function (err) {
  1479. domGlobals.setTimeout(function () {
  1480. throw err;
  1481. }, 0);
  1482. };
  1483. var make = function (run) {
  1484. var get = function (callback) {
  1485. run().then(callback, errorReporter);
  1486. };
  1487. var map = function (fab) {
  1488. return make(function () {
  1489. return run().then(fab);
  1490. });
  1491. };
  1492. var bind = function (aFutureB) {
  1493. return make(function () {
  1494. return run().then(function (v) {
  1495. return aFutureB(v).toPromise();
  1496. });
  1497. });
  1498. };
  1499. var anonBind = function (futureB) {
  1500. return make(function () {
  1501. return run().then(function () {
  1502. return futureB.toPromise();
  1503. });
  1504. });
  1505. };
  1506. var toLazy = function () {
  1507. return LazyValue.nu(get);
  1508. };
  1509. var toCached = function () {
  1510. var cache = null;
  1511. return make(function () {
  1512. if (cache === null) {
  1513. cache = run();
  1514. }
  1515. return cache;
  1516. });
  1517. };
  1518. var toPromise = run;
  1519. return {
  1520. map: map,
  1521. bind: bind,
  1522. anonBind: anonBind,
  1523. toLazy: toLazy,
  1524. toCached: toCached,
  1525. toPromise: toPromise,
  1526. get: get
  1527. };
  1528. };
  1529. var nu$1 = function (baseFn) {
  1530. return make(function () {
  1531. return new Promise(baseFn);
  1532. });
  1533. };
  1534. var pure$1 = function (a) {
  1535. return make(function () {
  1536. return Promise.resolve(a);
  1537. });
  1538. };
  1539. var Future = {
  1540. nu: nu$1,
  1541. pure: pure$1
  1542. };
  1543. var par = function (asyncValues, nu) {
  1544. return nu(function (callback) {
  1545. var r = [];
  1546. var count = 0;
  1547. var cb = function (i) {
  1548. return function (value) {
  1549. r[i] = value;
  1550. count++;
  1551. if (count >= asyncValues.length) {
  1552. callback(r);
  1553. }
  1554. };
  1555. };
  1556. if (asyncValues.length === 0) {
  1557. callback([]);
  1558. } else {
  1559. each(asyncValues, function (asyncValue, i) {
  1560. asyncValue.get(cb(i));
  1561. });
  1562. }
  1563. });
  1564. };
  1565. var par$1 = function (futures) {
  1566. return par(futures, Future.nu);
  1567. };
  1568. var mapM = function (array, fn) {
  1569. var futures = map(array, fn);
  1570. return par$1(futures);
  1571. };
  1572. var value = function () {
  1573. var subject = Cell(Option.none());
  1574. var clear = function () {
  1575. subject.set(Option.none());
  1576. };
  1577. var set = function (s) {
  1578. subject.set(Option.some(s));
  1579. };
  1580. var on = function (f) {
  1581. subject.get().each(f);
  1582. };
  1583. var isSet = function () {
  1584. return subject.get().isSome();
  1585. };
  1586. return {
  1587. clear: clear,
  1588. set: set,
  1589. isSet: isSet,
  1590. on: on
  1591. };
  1592. };
  1593. var pasteHtml$1 = function (editor, html, internalFlag) {
  1594. var internal = internalFlag ? internalFlag : InternalHtml.isMarked(html);
  1595. var args = ProcessFilters.process(editor, InternalHtml.unmark(html), internal);
  1596. if (args.cancelled === false) {
  1597. SmartPaste.insertContent(editor, args.content);
  1598. }
  1599. };
  1600. var pasteText = function (editor, text) {
  1601. text = editor.dom.encode(text).replace(/\r\n/g, '\n');
  1602. text = Newlines.convert(text, editor.settings.forced_root_block, editor.settings.forced_root_block_attrs);
  1603. pasteHtml$1(editor, text, false);
  1604. };
  1605. var getDataTransferItems = function (dataTransfer) {
  1606. var items = {};
  1607. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  1608. if (dataTransfer) {
  1609. if (dataTransfer.getData) {
  1610. var legacyText = dataTransfer.getData('Text');
  1611. if (legacyText && legacyText.length > 0) {
  1612. if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
  1613. items['text/plain'] = legacyText;
  1614. }
  1615. }
  1616. }
  1617. if (dataTransfer.types) {
  1618. for (var i = 0; i < dataTransfer.types.length; i++) {
  1619. var contentType = dataTransfer.types[i];
  1620. try {
  1621. items[contentType] = dataTransfer.getData(contentType);
  1622. } catch (ex) {
  1623. items[contentType] = '';
  1624. }
  1625. }
  1626. }
  1627. }
  1628. return items;
  1629. };
  1630. var getClipboardContent = function (editor, clipboardEvent) {
  1631. var content = getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
  1632. return Utils.isMsEdge() ? global$4.extend(content, { 'text/html': '' }) : content;
  1633. };
  1634. var hasContentType = function (clipboardContent, mimeType) {
  1635. return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
  1636. };
  1637. var hasHtmlOrText = function (content) {
  1638. return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
  1639. };
  1640. var getBase64FromUri = function (uri) {
  1641. var idx;
  1642. idx = uri.indexOf(',');
  1643. if (idx !== -1) {
  1644. return uri.substr(idx + 1);
  1645. }
  1646. return null;
  1647. };
  1648. var isValidDataUriImage = function (settings, imgElm) {
  1649. return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
  1650. };
  1651. var extractFilename = function (editor, str) {
  1652. var m = str.match(/([\s\S]+?)\.(?:jpeg|jpg|png|gif)$/i);
  1653. return m ? editor.dom.encode(m[1]) : null;
  1654. };
  1655. var uniqueId = Utils.createIdGenerator('mceclip');
  1656. var pasteImage = function (editor, imageItem) {
  1657. var base64 = getBase64FromUri(imageItem.uri);
  1658. var id = uniqueId();
  1659. var name = editor.settings.images_reuse_filename && imageItem.blob.name ? extractFilename(editor, imageItem.blob.name) : id;
  1660. var img = new domGlobals.Image();
  1661. img.src = imageItem.uri;
  1662. if (isValidDataUriImage(editor.settings, img)) {
  1663. var blobCache = editor.editorUpload.blobCache;
  1664. var blobInfo = void 0, existingBlobInfo = void 0;
  1665. existingBlobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  1666. return cachedBlobInfo.base64() === base64;
  1667. });
  1668. if (!existingBlobInfo) {
  1669. blobInfo = blobCache.create(id, imageItem.blob, base64, name);
  1670. blobCache.add(blobInfo);
  1671. } else {
  1672. blobInfo = existingBlobInfo;
  1673. }
  1674. pasteHtml$1(editor, '<img src="' + blobInfo.blobUri() + '">', false);
  1675. } else {
  1676. pasteHtml$1(editor, '<img src="' + imageItem.uri + '">', false);
  1677. }
  1678. };
  1679. var isClipboardEvent = function (event) {
  1680. return event.type === 'paste';
  1681. };
  1682. var readBlobsAsDataUris = function (items) {
  1683. return mapM(items, function (item) {
  1684. return Future.nu(function (resolve) {
  1685. var blob = item.getAsFile ? item.getAsFile() : item;
  1686. var reader = new window.FileReader();
  1687. reader.onload = function () {
  1688. resolve({
  1689. blob: blob,
  1690. uri: reader.result
  1691. });
  1692. };
  1693. reader.readAsDataURL(blob);
  1694. });
  1695. });
  1696. };
  1697. var getImagesFromDataTransfer = function (dataTransfer) {
  1698. var items = dataTransfer.items ? map(from$1(dataTransfer.items), function (item) {
  1699. return item.getAsFile();
  1700. }) : [];
  1701. var files = dataTransfer.files ? from$1(dataTransfer.files) : [];
  1702. var images = filter$1(items.length > 0 ? items : files, function (file) {
  1703. return /^image\/(jpeg|png|gif|bmp)$/.test(file.type);
  1704. });
  1705. return images;
  1706. };
  1707. var pasteImageData = function (editor, e, rng) {
  1708. var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
  1709. if (editor.settings.paste_data_images && dataTransfer) {
  1710. var images = getImagesFromDataTransfer(dataTransfer);
  1711. if (images.length > 0) {
  1712. e.preventDefault();
  1713. readBlobsAsDataUris(images).get(function (blobResults) {
  1714. if (rng) {
  1715. editor.selection.setRng(rng);
  1716. }
  1717. each(blobResults, function (result) {
  1718. pasteImage(editor, result);
  1719. });
  1720. });
  1721. return true;
  1722. }
  1723. }
  1724. return false;
  1725. };
  1726. var isBrokenAndroidClipboardEvent = function (e) {
  1727. var clipboardData = e.clipboardData;
  1728. return domGlobals.navigator.userAgent.indexOf('Android') !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
  1729. };
  1730. var isKeyboardPasteEvent = function (e) {
  1731. return global$5.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
  1732. };
  1733. var registerEventHandlers = function (editor, pasteBin, pasteFormat) {
  1734. var keyboardPasteEvent = value();
  1735. var keyboardPastePlainTextState;
  1736. editor.on('keydown', function (e) {
  1737. function removePasteBinOnKeyUp(e) {
  1738. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1739. pasteBin.remove();
  1740. }
  1741. }
  1742. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  1743. keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
  1744. if (keyboardPastePlainTextState && global$2.webkit && domGlobals.navigator.userAgent.indexOf('Version/') !== -1) {
  1745. return;
  1746. }
  1747. e.stopImmediatePropagation();
  1748. keyboardPasteEvent.set(e);
  1749. window.setTimeout(function () {
  1750. keyboardPasteEvent.clear();
  1751. }, 100);
  1752. if (global$2.ie && keyboardPastePlainTextState) {
  1753. e.preventDefault();
  1754. Events.firePaste(editor, true);
  1755. return;
  1756. }
  1757. pasteBin.remove();
  1758. pasteBin.create();
  1759. editor.once('keyup', removePasteBinOnKeyUp);
  1760. editor.once('paste', function () {
  1761. editor.off('keyup', removePasteBinOnKeyUp);
  1762. });
  1763. }
  1764. });
  1765. function insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
  1766. var content, isPlainTextHtml;
  1767. if (hasContentType(clipboardContent, 'text/html')) {
  1768. content = clipboardContent['text/html'];
  1769. } else {
  1770. content = pasteBin.getHtml();
  1771. internal = internal ? internal : InternalHtml.isMarked(content);
  1772. if (pasteBin.isDefaultContent(content)) {
  1773. plainTextMode = true;
  1774. }
  1775. }
  1776. content = Utils.trimHtml(content);
  1777. pasteBin.remove();
  1778. isPlainTextHtml = internal === false && Newlines.isPlainText(content);
  1779. if (!content.length || isPlainTextHtml) {
  1780. plainTextMode = true;
  1781. }
  1782. if (plainTextMode) {
  1783. if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
  1784. content = clipboardContent['text/plain'];
  1785. } else {
  1786. content = Utils.innerText(content);
  1787. }
  1788. }
  1789. if (pasteBin.isDefaultContent(content)) {
  1790. if (!isKeyBoardPaste) {
  1791. editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
  1792. }
  1793. return;
  1794. }
  1795. if (plainTextMode) {
  1796. pasteText(editor, content);
  1797. } else {
  1798. pasteHtml$1(editor, content, internal);
  1799. }
  1800. }
  1801. var getLastRng = function () {
  1802. return pasteBin.getLastRng() || editor.selection.getRng();
  1803. };
  1804. editor.on('paste', function (e) {
  1805. var isKeyBoardPaste = keyboardPasteEvent.isSet();
  1806. var clipboardContent = getClipboardContent(editor, e);
  1807. var plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
  1808. var internal = hasContentType(clipboardContent, InternalHtml.internalHtmlMime());
  1809. keyboardPastePlainTextState = false;
  1810. if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
  1811. pasteBin.remove();
  1812. return;
  1813. }
  1814. if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
  1815. pasteBin.remove();
  1816. return;
  1817. }
  1818. if (!isKeyBoardPaste) {
  1819. e.preventDefault();
  1820. }
  1821. if (global$2.ie && (!isKeyBoardPaste || e.ieFake) && !hasContentType(clipboardContent, 'text/html')) {
  1822. pasteBin.create();
  1823. editor.dom.bind(pasteBin.getEl(), 'paste', function (e) {
  1824. e.stopPropagation();
  1825. });
  1826. editor.getDoc().execCommand('Paste', false, null);
  1827. clipboardContent['text/html'] = pasteBin.getHtml();
  1828. }
  1829. if (hasContentType(clipboardContent, 'text/html')) {
  1830. e.preventDefault();
  1831. if (!internal) {
  1832. internal = InternalHtml.isMarked(clipboardContent['text/html']);
  1833. }
  1834. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1835. } else {
  1836. global$3.setEditorTimeout(editor, function () {
  1837. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  1838. }, 0);
  1839. }
  1840. });
  1841. };
  1842. var registerEventsAndFilters = function (editor, pasteBin, pasteFormat) {
  1843. registerEventHandlers(editor, pasteBin, pasteFormat);
  1844. var src;
  1845. editor.parser.addNodeFilter('img', function (nodes, name, args) {
  1846. var isPasteInsert = function (args) {
  1847. return args.data && args.data.paste === true;
  1848. };
  1849. var remove = function (node) {
  1850. if (!node.attr('data-mce-object') && src !== global$2.transparentSrc) {
  1851. node.remove();
  1852. }
  1853. };
  1854. var isWebKitFakeUrl = function (src) {
  1855. return src.indexOf('webkit-fake-url') === 0;
  1856. };
  1857. var isDataUri = function (src) {
  1858. return src.indexOf('data:') === 0;
  1859. };
  1860. if (!editor.settings.paste_data_images && isPasteInsert(args)) {
  1861. var i = nodes.length;
  1862. while (i--) {
  1863. src = nodes[i].attributes.map.src;
  1864. if (!src) {
  1865. continue;
  1866. }
  1867. if (isWebKitFakeUrl(src)) {
  1868. remove(nodes[i]);
  1869. } else if (!editor.settings.allow_html_data_urls && isDataUri(src)) {
  1870. remove(nodes[i]);
  1871. }
  1872. }
  1873. }
  1874. });
  1875. };
  1876. var getPasteBinParent = function (editor) {
  1877. return global$2.ie && editor.inline ? domGlobals.document.body : editor.getBody();
  1878. };
  1879. var isExternalPasteBin = function (editor) {
  1880. return getPasteBinParent(editor) !== editor.getBody();
  1881. };
  1882. var delegatePasteEvents = function (editor, pasteBinElm, pasteBinDefaultContent) {
  1883. if (isExternalPasteBin(editor)) {
  1884. editor.dom.bind(pasteBinElm, 'paste keyup', function (e) {
  1885. if (!isDefault(editor, pasteBinDefaultContent)) {
  1886. editor.fire('paste');
  1887. }
  1888. });
  1889. }
  1890. };
  1891. var create = function (editor, lastRngCell, pasteBinDefaultContent) {
  1892. var dom = editor.dom, body = editor.getBody();
  1893. var pasteBinElm;
  1894. lastRngCell.set(editor.selection.getRng());
  1895. pasteBinElm = editor.dom.add(getPasteBinParent(editor), 'div', {
  1896. 'id': 'mcepastebin',
  1897. 'class': 'mce-pastebin',
  1898. 'contentEditable': true,
  1899. 'data-mce-bogus': 'all',
  1900. 'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
  1901. }, pasteBinDefaultContent);
  1902. if (global$2.ie || global$2.gecko) {
  1903. dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
  1904. }
  1905. dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function (e) {
  1906. e.stopPropagation();
  1907. });
  1908. delegatePasteEvents(editor, pasteBinElm, pasteBinDefaultContent);
  1909. pasteBinElm.focus();
  1910. editor.selection.select(pasteBinElm, true);
  1911. };
  1912. var remove = function (editor, lastRngCell) {
  1913. if (getEl(editor)) {
  1914. var pasteBinClone = void 0;
  1915. var lastRng = lastRngCell.get();
  1916. while (pasteBinClone = editor.dom.get('mcepastebin')) {
  1917. editor.dom.remove(pasteBinClone);
  1918. editor.dom.unbind(pasteBinClone);
  1919. }
  1920. if (lastRng) {
  1921. editor.selection.setRng(lastRng);
  1922. }
  1923. }
  1924. lastRngCell.set(null);
  1925. };
  1926. var getEl = function (editor) {
  1927. return editor.dom.get('mcepastebin');
  1928. };
  1929. var getHtml = function (editor) {
  1930. var pasteBinElm, pasteBinClones, i, dirtyWrappers, cleanWrapper;
  1931. var copyAndRemove = function (toElm, fromElm) {
  1932. toElm.appendChild(fromElm);
  1933. editor.dom.remove(fromElm, true);
  1934. };
  1935. pasteBinClones = global$4.grep(getPasteBinParent(editor).childNodes, function (elm) {
  1936. return elm.id === 'mcepastebin';
  1937. });
  1938. pasteBinElm = pasteBinClones.shift();
  1939. global$4.each(pasteBinClones, function (pasteBinClone) {
  1940. copyAndRemove(pasteBinElm, pasteBinClone);
  1941. });
  1942. dirtyWrappers = editor.dom.select('div[id=mcepastebin]', pasteBinElm);
  1943. for (i = dirtyWrappers.length - 1; i >= 0; i--) {
  1944. cleanWrapper = editor.dom.create('div');
  1945. pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
  1946. copyAndRemove(cleanWrapper, dirtyWrappers[i]);
  1947. }
  1948. return pasteBinElm ? pasteBinElm.innerHTML : '';
  1949. };
  1950. var getLastRng = function (lastRng) {
  1951. return lastRng.get();
  1952. };
  1953. var isDefaultContent = function (pasteBinDefaultContent, content) {
  1954. return content === pasteBinDefaultContent;
  1955. };
  1956. var isPasteBin = function (elm) {
  1957. return elm && elm.id === 'mcepastebin';
  1958. };
  1959. var isDefault = function (editor, pasteBinDefaultContent) {
  1960. var pasteBinElm = getEl(editor);
  1961. return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
  1962. };
  1963. var PasteBin = function (editor) {
  1964. var lastRng = Cell(null);
  1965. var pasteBinDefaultContent = '%MCEPASTEBIN%';
  1966. return {
  1967. create: function () {
  1968. return create(editor, lastRng, pasteBinDefaultContent);
  1969. },
  1970. remove: function () {
  1971. return remove(editor, lastRng);
  1972. },
  1973. getEl: function () {
  1974. return getEl(editor);
  1975. },
  1976. getHtml: function () {
  1977. return getHtml(editor);
  1978. },
  1979. getLastRng: function () {
  1980. return getLastRng(lastRng);
  1981. },
  1982. isDefault: function () {
  1983. return isDefault(editor, pasteBinDefaultContent);
  1984. },
  1985. isDefaultContent: function (content) {
  1986. return isDefaultContent(pasteBinDefaultContent, content);
  1987. }
  1988. };
  1989. };
  1990. var Clipboard = function (editor, pasteFormat) {
  1991. var pasteBin = PasteBin(editor);
  1992. editor.on('preInit', function () {
  1993. return registerEventsAndFilters(editor, pasteBin, pasteFormat);
  1994. });
  1995. return {
  1996. pasteFormat: pasteFormat,
  1997. pasteHtml: function (html, internalFlag) {
  1998. return pasteHtml$1(editor, html, internalFlag);
  1999. },
  2000. pasteText: function (text) {
  2001. return pasteText(editor, text);
  2002. },
  2003. pasteImageData: function (e, rng) {
  2004. return pasteImageData(editor, e, rng);
  2005. },
  2006. getDataTransferItems: getDataTransferItems,
  2007. hasHtmlOrText: hasHtmlOrText,
  2008. hasContentType: hasContentType
  2009. };
  2010. };
  2011. var noop = function () {
  2012. };
  2013. var hasWorkingClipboardApi = function (clipboardData) {
  2014. return global$2.iOS === false && clipboardData !== undefined && typeof clipboardData.setData === 'function' && Utils.isMsEdge() !== true;
  2015. };
  2016. var setHtml5Clipboard = function (clipboardData, html, text) {
  2017. if (hasWorkingClipboardApi(clipboardData)) {
  2018. try {
  2019. clipboardData.clearData();
  2020. clipboardData.setData('text/html', html);
  2021. clipboardData.setData('text/plain', text);
  2022. clipboardData.setData(InternalHtml.internalHtmlMime(), html);
  2023. return true;
  2024. } catch (e) {
  2025. return false;
  2026. }
  2027. } else {
  2028. return false;
  2029. }
  2030. };
  2031. var setClipboardData = function (evt, data, fallback, done) {
  2032. if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
  2033. evt.preventDefault();
  2034. done();
  2035. } else {
  2036. fallback(data.html, done);
  2037. }
  2038. };
  2039. var fallback = function (editor) {
  2040. return function (html, done) {
  2041. var markedHtml = InternalHtml.mark(html);
  2042. var outer = editor.dom.create('div', {
  2043. 'contenteditable': 'false',
  2044. 'data-mce-bogus': 'all'
  2045. });
  2046. var inner = editor.dom.create('div', { contenteditable: 'true' }, markedHtml);
  2047. editor.dom.setStyles(outer, {
  2048. position: 'fixed',
  2049. top: '0',
  2050. left: '-3000px',
  2051. width: '1000px',
  2052. overflow: 'hidden'
  2053. });
  2054. outer.appendChild(inner);
  2055. editor.dom.add(editor.getBody(), outer);
  2056. var range = editor.selection.getRng();
  2057. inner.focus();
  2058. var offscreenRange = editor.dom.createRng();
  2059. offscreenRange.selectNodeContents(inner);
  2060. editor.selection.setRng(offscreenRange);
  2061. setTimeout(function () {
  2062. editor.selection.setRng(range);
  2063. outer.parentNode.removeChild(outer);
  2064. done();
  2065. }, 0);
  2066. };
  2067. };
  2068. var getData = function (editor) {
  2069. return {
  2070. html: editor.selection.getContent({ contextual: true }),
  2071. text: editor.selection.getContent({ format: 'text' })
  2072. };
  2073. };
  2074. var isTableSelection = function (editor) {
  2075. return !!editor.dom.getParent(editor.selection.getStart(), 'td[data-mce-selected],th[data-mce-selected]', editor.getBody());
  2076. };
  2077. var hasSelectedContent = function (editor) {
  2078. return !editor.selection.isCollapsed() || isTableSelection(editor);
  2079. };
  2080. var cut = function (editor) {
  2081. return function (evt) {
  2082. if (hasSelectedContent(editor)) {
  2083. setClipboardData(evt, getData(editor), fallback(editor), function () {
  2084. setTimeout(function () {
  2085. editor.execCommand('Delete');
  2086. }, 0);
  2087. });
  2088. }
  2089. };
  2090. };
  2091. var copy = function (editor) {
  2092. return function (evt) {
  2093. if (hasSelectedContent(editor)) {
  2094. setClipboardData(evt, getData(editor), fallback(editor), noop);
  2095. }
  2096. };
  2097. };
  2098. var register$1 = function (editor) {
  2099. editor.on('cut', cut(editor));
  2100. editor.on('copy', copy(editor));
  2101. };
  2102. var CutCopy = { register: register$1 };
  2103. var global$b = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  2104. var getCaretRangeFromEvent = function (editor, e) {
  2105. return global$b.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
  2106. };
  2107. var isPlainTextFileUrl = function (content) {
  2108. var plainTextContent = content['text/plain'];
  2109. return plainTextContent ? plainTextContent.indexOf('file://') === 0 : false;
  2110. };
  2111. var setFocusedRange = function (editor, rng) {
  2112. editor.focus();
  2113. editor.selection.setRng(rng);
  2114. };
  2115. var setup = function (editor, clipboard, draggingInternallyState) {
  2116. if (Settings.shouldBlockDrop(editor)) {
  2117. editor.on('dragend dragover draggesture dragdrop drop drag', function (e) {
  2118. e.preventDefault();
  2119. e.stopPropagation();
  2120. });
  2121. }
  2122. if (!Settings.shouldPasteDataImages(editor)) {
  2123. editor.on('drop', function (e) {
  2124. var dataTransfer = e.dataTransfer;
  2125. if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
  2126. e.preventDefault();
  2127. }
  2128. });
  2129. }
  2130. editor.on('drop', function (e) {
  2131. var dropContent, rng;
  2132. rng = getCaretRangeFromEvent(editor, e);
  2133. if (e.isDefaultPrevented() || draggingInternallyState.get()) {
  2134. return;
  2135. }
  2136. dropContent = clipboard.getDataTransferItems(e.dataTransfer);
  2137. var internal = clipboard.hasContentType(dropContent, InternalHtml.internalHtmlMime());
  2138. if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
  2139. return;
  2140. }
  2141. if (rng && Settings.shouldFilterDrop(editor)) {
  2142. var content_1 = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
  2143. if (content_1) {
  2144. e.preventDefault();
  2145. global$3.setEditorTimeout(editor, function () {
  2146. editor.undoManager.transact(function () {
  2147. if (dropContent['mce-internal']) {
  2148. editor.execCommand('Delete');
  2149. }
  2150. setFocusedRange(editor, rng);
  2151. content_1 = Utils.trimHtml(content_1);
  2152. if (!dropContent['text/html']) {
  2153. clipboard.pasteText(content_1);
  2154. } else {
  2155. clipboard.pasteHtml(content_1, internal);
  2156. }
  2157. });
  2158. });
  2159. }
  2160. }
  2161. });
  2162. editor.on('dragstart', function (e) {
  2163. draggingInternallyState.set(true);
  2164. });
  2165. editor.on('dragover dragend', function (e) {
  2166. if (Settings.shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
  2167. e.preventDefault();
  2168. setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
  2169. }
  2170. if (e.type === 'dragend') {
  2171. draggingInternallyState.set(false);
  2172. }
  2173. });
  2174. };
  2175. var DragDrop = { setup: setup };
  2176. var setup$1 = function (editor) {
  2177. var plugin = editor.plugins.paste;
  2178. var preProcess = Settings.getPreProcess(editor);
  2179. if (preProcess) {
  2180. editor.on('PastePreProcess', function (e) {
  2181. preProcess.call(plugin, plugin, e);
  2182. });
  2183. }
  2184. var postProcess = Settings.getPostProcess(editor);
  2185. if (postProcess) {
  2186. editor.on('PastePostProcess', function (e) {
  2187. postProcess.call(plugin, plugin, e);
  2188. });
  2189. }
  2190. };
  2191. var PrePostProcess = { setup: setup$1 };
  2192. function addPreProcessFilter(editor, filterFunc) {
  2193. editor.on('PastePreProcess', function (e) {
  2194. e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
  2195. });
  2196. }
  2197. function addPostProcessFilter(editor, filterFunc) {
  2198. editor.on('PastePostProcess', function (e) {
  2199. filterFunc(editor, e.node);
  2200. });
  2201. }
  2202. function removeExplorerBrElementsAfterBlocks(editor, html) {
  2203. if (!WordFilter.isWordContent(html)) {
  2204. return html;
  2205. }
  2206. var blockElements = [];
  2207. global$4.each(editor.schema.getBlockElements(), function (block, blockName) {
  2208. blockElements.push(blockName);
  2209. });
  2210. var explorerBlocksRegExp = new RegExp('(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*', 'g');
  2211. html = Utils.filter(html, [[
  2212. explorerBlocksRegExp,
  2213. '$1'
  2214. ]]);
  2215. html = Utils.filter(html, [
  2216. [
  2217. /<br><br>/g,
  2218. '<BR><BR>'
  2219. ],
  2220. [
  2221. /<br>/g,
  2222. ' '
  2223. ],
  2224. [
  2225. /<BR><BR>/g,
  2226. '<br>'
  2227. ]
  2228. ]);
  2229. return html;
  2230. }
  2231. function removeWebKitStyles(editor, content, internal, isWordHtml) {
  2232. if (isWordHtml || internal) {
  2233. return content;
  2234. }
  2235. var webKitStylesSetting = Settings.getWebkitStyles(editor);
  2236. var webKitStyles;
  2237. if (Settings.shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === 'all') {
  2238. return content;
  2239. }
  2240. if (webKitStylesSetting) {
  2241. webKitStyles = webKitStylesSetting.split(/[, ]/);
  2242. }
  2243. if (webKitStyles) {
  2244. var dom_1 = editor.dom, node_1 = editor.selection.getNode();
  2245. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function (all, before, value, after) {
  2246. var inputStyles = dom_1.parseStyle(dom_1.decode(value));
  2247. var outputStyles = {};
  2248. if (webKitStyles === 'none') {
  2249. return before + after;
  2250. }
  2251. for (var i = 0; i < webKitStyles.length; i++) {
  2252. var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
  2253. if (/color/.test(webKitStyles[i])) {
  2254. inputValue = dom_1.toHex(inputValue);
  2255. currentValue = dom_1.toHex(currentValue);
  2256. }
  2257. if (currentValue !== inputValue) {
  2258. outputStyles[webKitStyles[i]] = inputValue;
  2259. }
  2260. }
  2261. outputStyles = dom_1.serializeStyle(outputStyles, 'span');
  2262. if (outputStyles) {
  2263. return before + ' style="' + outputStyles + '"' + after;
  2264. }
  2265. return before + after;
  2266. });
  2267. } else {
  2268. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
  2269. }
  2270. content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function (all, before, value, after) {
  2271. return before + ' style="' + value + '"' + after;
  2272. });
  2273. return content;
  2274. }
  2275. function removeUnderlineAndFontInAnchor(editor, root) {
  2276. editor.$('a', root).find('font,u').each(function (i, node) {
  2277. editor.dom.remove(node, true);
  2278. });
  2279. }
  2280. var setup$2 = function (editor) {
  2281. if (global$2.webkit) {
  2282. addPreProcessFilter(editor, removeWebKitStyles);
  2283. }
  2284. if (global$2.ie) {
  2285. addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
  2286. addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
  2287. }
  2288. };
  2289. var Quirks = { setup: setup$2 };
  2290. var stateChange = function (editor, clipboard, e) {
  2291. var ctrl = e.control;
  2292. ctrl.active(clipboard.pasteFormat.get() === 'text');
  2293. editor.on('PastePlainTextToggle', function (e) {
  2294. ctrl.active(e.state);
  2295. });
  2296. };
  2297. var register$2 = function (editor, clipboard) {
  2298. var postRender = curry(stateChange, editor, clipboard);
  2299. editor.addButton('pastetext', {
  2300. active: false,
  2301. icon: 'pastetext',
  2302. tooltip: 'Paste as text',
  2303. cmd: 'mceTogglePlainTextPaste',
  2304. onPostRender: postRender
  2305. });
  2306. editor.addMenuItem('pastetext', {
  2307. text: 'Paste as text',
  2308. selectable: true,
  2309. active: clipboard.pasteFormat,
  2310. cmd: 'mceTogglePlainTextPaste',
  2311. onPostRender: postRender
  2312. });
  2313. };
  2314. var Buttons = { register: register$2 };
  2315. global$1.add('paste', function (editor) {
  2316. if (DetectProPlugin.hasProPlugin(editor) === false) {
  2317. var userIsInformedState = Cell(false);
  2318. var draggingInternallyState = Cell(false);
  2319. var pasteFormat = Cell(Settings.isPasteAsTextEnabled(editor) ? 'text' : 'html');
  2320. var clipboard = Clipboard(editor, pasteFormat);
  2321. var quirks = Quirks.setup(editor);
  2322. Buttons.register(editor, clipboard);
  2323. Commands.register(editor, clipboard, userIsInformedState);
  2324. PrePostProcess.setup(editor);
  2325. CutCopy.register(editor);
  2326. DragDrop.setup(editor, clipboard, draggingInternallyState);
  2327. return Api.get(clipboard, quirks);
  2328. }
  2329. });
  2330. function Plugin () {
  2331. }
  2332. return Plugin;
  2333. }(window));
  2334. })();