plugin.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. (function () {
  2. var paste = (function () {
  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 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  22. var hasProPlugin = function (editor) {
  23. if (/(^|[ ,])powerpaste([, ]|$)/.test(editor.settings.plugins) && global.get('powerpaste')) {
  24. if (typeof window.console !== 'undefined' && window.console.log) {
  25. 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 $_15bf6siejjgwect1 = { hasProPlugin: hasProPlugin };
  33. var get = function (clipboard, quirks) {
  34. return {
  35. clipboard: clipboard,
  36. quirks: quirks
  37. };
  38. };
  39. var $_6gtliyigjjgwecte = { 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 $_8tki3zijjjgwectj = {
  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 $_xr8b0ikjjgwectl = {
  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 && $_xr8b0ikjjgwectl.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. $_8tki3zijjjgwectj.firePastePlainTextToggle(editor, false);
  142. } else {
  143. clipboard.pasteFormat.set('text');
  144. $_8tki3zijjjgwectj.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 $_2j7vw7iijjgwecti = { togglePlainTextPaste: togglePlainTextPaste };
  153. var register = function (editor, clipboard, userIsInformedState) {
  154. editor.addCommand('mceTogglePlainTextPaste', function () {
  155. $_2j7vw7iijjgwecti.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 $_fldd1mihjjgwecth = { register: register };
  167. var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
  168. var global$2 = tinymce.util.Tools.resolve('tinymce.util.Delay');
  169. var global$3 = tinymce.util.Tools.resolve('tinymce.util.Tools');
  170. var global$4 = 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 $_4x13hjirjjgwecu1 = {
  183. mark: mark,
  184. unmark: unmark,
  185. isMarked: isMarked,
  186. internalHtmlMime: function () {
  187. return internalMimeType;
  188. }
  189. };
  190. var global$5 = 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$5.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$3.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$3.map(paragraphs, stitch).join('');
  224. };
  225. var convert = function (text, rootTag, rootAttrs) {
  226. return rootTag ? toBlockElements(text, rootTag, rootAttrs) : toBRs(text);
  227. };
  228. var $_4h3hnrisjjgwecu2 = {
  229. isPlainText: isPlainText,
  230. convert: convert,
  231. toBRs: toBRs,
  232. toBlockElements: toBlockElements
  233. };
  234. var global$6 = tinymce.util.Tools.resolve('tinymce.html.DomParser');
  235. var global$7 = tinymce.util.Tools.resolve('tinymce.html.Node');
  236. var global$8 = tinymce.util.Tools.resolve('tinymce.html.Schema');
  237. var global$9 = tinymce.util.Tools.resolve('tinymce.html.Serializer');
  238. function filter(content, items) {
  239. global$3.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$8();
  250. var domParser = global$6({}, schema);
  251. var text = '';
  252. var shortEndedElements = schema.getShortEndedElements();
  253. var ignoreElements = global$3.makeMap('script noscript style textarea video audio iframe object', ' ');
  254. var blockElements = schema.getBlockElements();
  255. function walk(node) {
  256. var name$$1 = node.name, currentNode = node;
  257. if (name$$1 === 'br') {
  258. text += '\n';
  259. return;
  260. }
  261. if (shortEndedElements[name$$1]) {
  262. text += ' ';
  263. }
  264. if (ignoreElements[name$$1]) {
  265. text += ' ';
  266. return;
  267. }
  268. if (node.type === 3) {
  269. text += node.value;
  270. }
  271. if (!node.shortEnded) {
  272. if (node = node.firstChild) {
  273. do {
  274. walk(node);
  275. } while (node = node.next);
  276. }
  277. }
  278. if (blockElements[name$$1] && currentNode.next) {
  279. text += '\n';
  280. if (name$$1 === 'p') {
  281. text += '\n';
  282. }
  283. }
  284. }
  285. html = filter(html, [/<!\[[^\]]+\]>/g]);
  286. walk(domParser.parse(html));
  287. return text;
  288. }
  289. function trimHtml(html) {
  290. function trimSpaces(all, s1, s2) {
  291. if (!s1 && !s2) {
  292. return ' ';
  293. }
  294. return '\xA0';
  295. }
  296. html = filter(html, [
  297. /^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig,
  298. /<!--StartFragment-->|<!--EndFragment-->/g,
  299. [
  300. /( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g,
  301. trimSpaces
  302. ],
  303. /<br class="Apple-interchange-newline">/g,
  304. /<br>$/i
  305. ]);
  306. return html;
  307. }
  308. function createIdGenerator(prefix) {
  309. var count = 0;
  310. return function () {
  311. return prefix + count++;
  312. };
  313. }
  314. var isMsEdge = function () {
  315. return navigator.userAgent.indexOf(' Edge/') !== -1;
  316. };
  317. var $_4bi2o9j0jjgwecui = {
  318. filter: filter,
  319. innerText: innerText,
  320. trimHtml: trimHtml,
  321. createIdGenerator: createIdGenerator,
  322. isMsEdge: isMsEdge
  323. };
  324. function isWordContent(content) {
  325. 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);
  326. }
  327. function isNumericList(text) {
  328. var found, patterns;
  329. patterns = [
  330. /^[IVXLMCD]{1,2}\.[ \u00a0]/,
  331. /^[ivxlmcd]{1,2}\.[ \u00a0]/,
  332. /^[a-z]{1,2}[\.\)][ \u00a0]/,
  333. /^[A-Z]{1,2}[\.\)][ \u00a0]/,
  334. /^[0-9]+\.[ \u00a0]/,
  335. /^[\u3007\u4e00\u4e8c\u4e09\u56db\u4e94\u516d\u4e03\u516b\u4e5d]+\.[ \u00a0]/,
  336. /^[\u58f1\u5f10\u53c2\u56db\u4f0d\u516d\u4e03\u516b\u4e5d\u62fe]+\.[ \u00a0]/
  337. ];
  338. text = text.replace(/^[\u00a0 ]+/, '');
  339. global$3.each(patterns, function (pattern) {
  340. if (pattern.test(text)) {
  341. found = true;
  342. return false;
  343. }
  344. });
  345. return found;
  346. }
  347. function isBulletList(text) {
  348. return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
  349. }
  350. function convertFakeListsToProperLists(node) {
  351. var currentListNode, prevListNode, lastLevel = 1;
  352. function getText(node) {
  353. var txt = '';
  354. if (node.type === 3) {
  355. return node.value;
  356. }
  357. if (node = node.firstChild) {
  358. do {
  359. txt += getText(node);
  360. } while (node = node.next);
  361. }
  362. return txt;
  363. }
  364. function trimListStart(node, regExp) {
  365. if (node.type === 3) {
  366. if (regExp.test(node.value)) {
  367. node.value = node.value.replace(regExp, '');
  368. return false;
  369. }
  370. }
  371. if (node = node.firstChild) {
  372. do {
  373. if (!trimListStart(node, regExp)) {
  374. return false;
  375. }
  376. } while (node = node.next);
  377. }
  378. return true;
  379. }
  380. function removeIgnoredNodes(node) {
  381. if (node._listIgnore) {
  382. node.remove();
  383. return;
  384. }
  385. if (node = node.firstChild) {
  386. do {
  387. removeIgnoredNodes(node);
  388. } while (node = node.next);
  389. }
  390. }
  391. function convertParagraphToLi(paragraphNode, listName, start) {
  392. var level = paragraphNode._listLevel || lastLevel;
  393. if (level !== lastLevel) {
  394. if (level < lastLevel) {
  395. if (currentListNode) {
  396. currentListNode = currentListNode.parent.parent;
  397. }
  398. } else {
  399. prevListNode = currentListNode;
  400. currentListNode = null;
  401. }
  402. }
  403. if (!currentListNode || currentListNode.name !== listName) {
  404. prevListNode = prevListNode || currentListNode;
  405. currentListNode = new global$7(listName, 1);
  406. if (start > 1) {
  407. currentListNode.attr('start', '' + start);
  408. }
  409. paragraphNode.wrap(currentListNode);
  410. } else {
  411. currentListNode.append(paragraphNode);
  412. }
  413. paragraphNode.name = 'li';
  414. if (level > lastLevel && prevListNode) {
  415. prevListNode.lastChild.append(currentListNode);
  416. }
  417. lastLevel = level;
  418. removeIgnoredNodes(paragraphNode);
  419. trimListStart(paragraphNode, /^\u00a0+/);
  420. trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
  421. trimListStart(paragraphNode, /^\u00a0+/);
  422. }
  423. var elements = [];
  424. var child = node.firstChild;
  425. while (typeof child !== 'undefined' && child !== null) {
  426. elements.push(child);
  427. child = child.walk();
  428. if (child !== null) {
  429. while (typeof child !== 'undefined' && child.parent !== node) {
  430. child = child.walk();
  431. }
  432. }
  433. }
  434. for (var i = 0; i < elements.length; i++) {
  435. node = elements[i];
  436. if (node.name === 'p' && node.firstChild) {
  437. var nodeText = getText(node);
  438. if (isBulletList(nodeText)) {
  439. convertParagraphToLi(node, 'ul');
  440. continue;
  441. }
  442. if (isNumericList(nodeText)) {
  443. var matches = /([0-9]+)\./.exec(nodeText);
  444. var start = 1;
  445. if (matches) {
  446. start = parseInt(matches[1], 10);
  447. }
  448. convertParagraphToLi(node, 'ol', start);
  449. continue;
  450. }
  451. if (node._listLevel) {
  452. convertParagraphToLi(node, 'ul', 1);
  453. continue;
  454. }
  455. currentListNode = null;
  456. } else {
  457. prevListNode = currentListNode;
  458. currentListNode = null;
  459. }
  460. }
  461. }
  462. function filterStyles(editor, validStyles, node, styleValue) {
  463. var outputStyles = {}, matches;
  464. var styles = editor.dom.parseStyle(styleValue);
  465. global$3.each(styles, function (value, name) {
  466. switch (name) {
  467. case 'mso-list':
  468. matches = /\w+ \w+([0-9]+)/i.exec(styleValue);
  469. if (matches) {
  470. node._listLevel = parseInt(matches[1], 10);
  471. }
  472. if (/Ignore/i.test(value) && node.firstChild) {
  473. node._listIgnore = true;
  474. node.firstChild._listIgnore = true;
  475. }
  476. break;
  477. case 'horiz-align':
  478. name = 'text-align';
  479. break;
  480. case 'vert-align':
  481. name = 'vertical-align';
  482. break;
  483. case 'font-color':
  484. case 'mso-foreground':
  485. name = 'color';
  486. break;
  487. case 'mso-background':
  488. case 'mso-highlight':
  489. name = 'background';
  490. break;
  491. case 'font-weight':
  492. case 'font-style':
  493. if (value !== 'normal') {
  494. outputStyles[name] = value;
  495. }
  496. return;
  497. case 'mso-element':
  498. if (/^(comment|comment-list)$/i.test(value)) {
  499. node.remove();
  500. return;
  501. }
  502. break;
  503. }
  504. if (name.indexOf('mso-comment') === 0) {
  505. node.remove();
  506. return;
  507. }
  508. if (name.indexOf('mso-') === 0) {
  509. return;
  510. }
  511. if ($_xr8b0ikjjgwectl.getRetainStyleProps(editor) === 'all' || validStyles && validStyles[name]) {
  512. outputStyles[name] = value;
  513. }
  514. });
  515. if (/(bold)/i.test(outputStyles['font-weight'])) {
  516. delete outputStyles['font-weight'];
  517. node.wrap(new global$7('b', 1));
  518. }
  519. if (/(italic)/i.test(outputStyles['font-style'])) {
  520. delete outputStyles['font-style'];
  521. node.wrap(new global$7('i', 1));
  522. }
  523. outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
  524. if (outputStyles) {
  525. return outputStyles;
  526. }
  527. return null;
  528. }
  529. var filterWordContent = function (editor, content) {
  530. var retainStyleProperties, validStyles;
  531. retainStyleProperties = $_xr8b0ikjjgwectl.getRetainStyleProps(editor);
  532. if (retainStyleProperties) {
  533. validStyles = global$3.makeMap(retainStyleProperties.split(/[, ]/));
  534. }
  535. content = $_4bi2o9j0jjgwecui.filter(content, [
  536. /<br class="?Apple-interchange-newline"?>/gi,
  537. /<b[^>]+id="?docs-internal-[^>]*>/gi,
  538. /<!--[\s\S]+?-->/gi,
  539. /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
  540. [
  541. /<(\/?)s>/gi,
  542. '<$1strike>'
  543. ],
  544. [
  545. /&nbsp;/gi,
  546. '\xA0'
  547. ],
  548. [
  549. /<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
  550. function (str, spaces) {
  551. return spaces.length > 0 ? spaces.replace(/./, ' ').slice(Math.floor(spaces.length / 2)).split('').join('\xA0') : '';
  552. }
  553. ]
  554. ]);
  555. var validElements = $_xr8b0ikjjgwectl.getWordValidElements(editor);
  556. var schema = global$8({
  557. valid_elements: validElements,
  558. valid_children: '-li[p]'
  559. });
  560. global$3.each(schema.elements, function (rule) {
  561. if (!rule.attributes.class) {
  562. rule.attributes.class = {};
  563. rule.attributesOrder.push('class');
  564. }
  565. if (!rule.attributes.style) {
  566. rule.attributes.style = {};
  567. rule.attributesOrder.push('style');
  568. }
  569. });
  570. var domParser = global$6({}, schema);
  571. domParser.addAttributeFilter('style', function (nodes) {
  572. var i = nodes.length, node;
  573. while (i--) {
  574. node = nodes[i];
  575. node.attr('style', filterStyles(editor, validStyles, node, node.attr('style')));
  576. if (node.name === 'span' && node.parent && !node.attributes.length) {
  577. node.unwrap();
  578. }
  579. }
  580. });
  581. domParser.addAttributeFilter('class', function (nodes) {
  582. var i = nodes.length, node, className;
  583. while (i--) {
  584. node = nodes[i];
  585. className = node.attr('class');
  586. if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
  587. node.remove();
  588. }
  589. node.attr('class', null);
  590. }
  591. });
  592. domParser.addNodeFilter('del', function (nodes) {
  593. var i = nodes.length;
  594. while (i--) {
  595. nodes[i].remove();
  596. }
  597. });
  598. domParser.addNodeFilter('a', function (nodes) {
  599. var i = nodes.length, node, href, name;
  600. while (i--) {
  601. node = nodes[i];
  602. href = node.attr('href');
  603. name = node.attr('name');
  604. if (href && href.indexOf('#_msocom_') !== -1) {
  605. node.remove();
  606. continue;
  607. }
  608. if (href && href.indexOf('file://') === 0) {
  609. href = href.split('#')[1];
  610. if (href) {
  611. href = '#' + href;
  612. }
  613. }
  614. if (!href && !name) {
  615. node.unwrap();
  616. } else {
  617. if (name && !/^_?(?:toc|edn|ftn)/i.test(name)) {
  618. node.unwrap();
  619. continue;
  620. }
  621. node.attr({
  622. href: href,
  623. name: name
  624. });
  625. }
  626. }
  627. });
  628. var rootNode = domParser.parse(content);
  629. if ($_xr8b0ikjjgwectl.shouldConvertWordFakeLists(editor)) {
  630. convertFakeListsToProperLists(rootNode);
  631. }
  632. content = global$9({ validate: editor.settings.validate }, schema).serialize(rootNode);
  633. return content;
  634. };
  635. var preProcess = function (editor, content) {
  636. return $_xr8b0ikjjgwectl.shouldUseDefaultFilters(editor) ? filterWordContent(editor, content) : content;
  637. };
  638. var $_dfatuiivjjgwecu8 = {
  639. preProcess: preProcess,
  640. isWordContent: isWordContent
  641. };
  642. var processResult = function (content, cancelled) {
  643. return {
  644. content: content,
  645. cancelled: cancelled
  646. };
  647. };
  648. var postProcessFilter = function (editor, html, internal, isWordHtml) {
  649. var tempBody = editor.dom.create('div', { style: 'display:none' }, html);
  650. var postProcessArgs = $_8tki3zijjjgwectj.firePastePostProcess(editor, tempBody, internal, isWordHtml);
  651. return processResult(postProcessArgs.node.innerHTML, postProcessArgs.isDefaultPrevented());
  652. };
  653. var filterContent = function (editor, content, internal, isWordHtml) {
  654. var preProcessArgs = $_8tki3zijjjgwectj.firePastePreProcess(editor, content, internal, isWordHtml);
  655. if (editor.hasEventListeners('PastePostProcess') && !preProcessArgs.isDefaultPrevented()) {
  656. return postProcessFilter(editor, preProcessArgs.content, internal, isWordHtml);
  657. } else {
  658. return processResult(preProcessArgs.content, preProcessArgs.isDefaultPrevented());
  659. }
  660. };
  661. var process = function (editor, html, internal) {
  662. var isWordHtml = $_dfatuiivjjgwecu8.isWordContent(html);
  663. var content = isWordHtml ? $_dfatuiivjjgwecu8.preProcess(editor, html) : html;
  664. return filterContent(editor, content, internal, isWordHtml);
  665. };
  666. var $_3scw66iujjgwecu4 = { process: process };
  667. var pasteHtml = function (editor, html) {
  668. editor.insertContent(html, {
  669. merge: $_xr8b0ikjjgwectl.shouldMergeFormats(editor),
  670. paste: true
  671. });
  672. return true;
  673. };
  674. var isAbsoluteUrl = function (url) {
  675. return /^https?:\/\/[\w\?\-\/+=.&%@~#]+$/i.test(url);
  676. };
  677. var isImageUrl = function (url) {
  678. return isAbsoluteUrl(url) && /.(gif|jpe?g|png)$/.test(url);
  679. };
  680. var createImage = function (editor, url, pasteHtmlFn) {
  681. editor.undoManager.extra(function () {
  682. pasteHtmlFn(editor, url);
  683. }, function () {
  684. editor.insertContent('<img src="' + url + '">');
  685. });
  686. return true;
  687. };
  688. var createLink = function (editor, url, pasteHtmlFn) {
  689. editor.undoManager.extra(function () {
  690. pasteHtmlFn(editor, url);
  691. }, function () {
  692. editor.execCommand('mceInsertLink', false, url);
  693. });
  694. return true;
  695. };
  696. var linkSelection = function (editor, html, pasteHtmlFn) {
  697. return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtmlFn) : false;
  698. };
  699. var insertImage = function (editor, html, pasteHtmlFn) {
  700. return isImageUrl(html) ? createImage(editor, html, pasteHtmlFn) : false;
  701. };
  702. var smartInsertContent = function (editor, html) {
  703. global$3.each([
  704. linkSelection,
  705. insertImage,
  706. pasteHtml
  707. ], function (action) {
  708. return action(editor, html, pasteHtml) !== true;
  709. });
  710. };
  711. var insertContent = function (editor, html) {
  712. if ($_xr8b0ikjjgwectl.isSmartPasteEnabled(editor) === false) {
  713. pasteHtml(editor, html);
  714. } else {
  715. smartInsertContent(editor, html);
  716. }
  717. };
  718. var $_d8pzpej1jjgwecum = {
  719. isImageUrl: isImageUrl,
  720. isAbsoluteUrl: isAbsoluteUrl,
  721. insertContent: insertContent
  722. };
  723. var pasteHtml$1 = function (editor, html, internalFlag) {
  724. var internal = internalFlag ? internalFlag : $_4x13hjirjjgwecu1.isMarked(html);
  725. var args = $_3scw66iujjgwecu4.process(editor, $_4x13hjirjjgwecu1.unmark(html), internal);
  726. if (args.cancelled === false) {
  727. $_d8pzpej1jjgwecum.insertContent(editor, args.content);
  728. }
  729. };
  730. var pasteText = function (editor, text) {
  731. text = editor.dom.encode(text).replace(/\r\n/g, '\n');
  732. text = $_4h3hnrisjjgwecu2.convert(text, editor.settings.forced_root_block, editor.settings.forced_root_block_attrs);
  733. pasteHtml$1(editor, text, false);
  734. };
  735. var getDataTransferItems = function (dataTransfer) {
  736. var items = {};
  737. var mceInternalUrlPrefix = 'data:text/mce-internal,';
  738. if (dataTransfer) {
  739. if (dataTransfer.getData) {
  740. var legacyText = dataTransfer.getData('Text');
  741. if (legacyText && legacyText.length > 0) {
  742. if (legacyText.indexOf(mceInternalUrlPrefix) === -1) {
  743. items['text/plain'] = legacyText;
  744. }
  745. }
  746. }
  747. if (dataTransfer.types) {
  748. for (var i = 0; i < dataTransfer.types.length; i++) {
  749. var contentType = dataTransfer.types[i];
  750. try {
  751. items[contentType] = dataTransfer.getData(contentType);
  752. } catch (ex) {
  753. items[contentType] = '';
  754. }
  755. }
  756. }
  757. }
  758. return items;
  759. };
  760. var getClipboardContent = function (editor, clipboardEvent) {
  761. var content = getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
  762. return $_4bi2o9j0jjgwecui.isMsEdge() ? global$3.extend(content, { 'text/html': '' }) : content;
  763. };
  764. var hasContentType = function (clipboardContent, mimeType) {
  765. return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
  766. };
  767. var hasHtmlOrText = function (content) {
  768. return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
  769. };
  770. var getBase64FromUri = function (uri) {
  771. var idx;
  772. idx = uri.indexOf(',');
  773. if (idx !== -1) {
  774. return uri.substr(idx + 1);
  775. }
  776. return null;
  777. };
  778. var isValidDataUriImage = function (settings, imgElm) {
  779. return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
  780. };
  781. var extractFilename = function (editor, str) {
  782. var m = str.match(/([\s\S]+?)\.(?:jpeg|jpg|png|gif)$/i);
  783. return m ? editor.dom.encode(m[1]) : null;
  784. };
  785. var uniqueId = $_4bi2o9j0jjgwecui.createIdGenerator('mceclip');
  786. var pasteImage = function (editor, rng, reader, blob) {
  787. if (rng) {
  788. editor.selection.setRng(rng);
  789. rng = null;
  790. }
  791. var dataUri = reader.result;
  792. var base64 = getBase64FromUri(dataUri);
  793. var id = uniqueId();
  794. var name$$1 = editor.settings.images_reuse_filename && blob.name ? extractFilename(editor, blob.name) : id;
  795. var img = new Image();
  796. img.src = dataUri;
  797. if (isValidDataUriImage(editor.settings, img)) {
  798. var blobCache = editor.editorUpload.blobCache;
  799. var blobInfo = void 0, existingBlobInfo = void 0;
  800. existingBlobInfo = blobCache.findFirst(function (cachedBlobInfo) {
  801. return cachedBlobInfo.base64() === base64;
  802. });
  803. if (!existingBlobInfo) {
  804. blobInfo = blobCache.create(id, blob, base64, name$$1);
  805. blobCache.add(blobInfo);
  806. } else {
  807. blobInfo = existingBlobInfo;
  808. }
  809. pasteHtml$1(editor, '<img src="' + blobInfo.blobUri() + '">', false);
  810. } else {
  811. pasteHtml$1(editor, '<img src="' + dataUri + '">', false);
  812. }
  813. };
  814. var isClipboardEvent = function (event$$1) {
  815. return event$$1.type === 'paste';
  816. };
  817. var pasteImageData = function (editor, e, rng) {
  818. var dataTransfer = isClipboardEvent(e) ? e.clipboardData : e.dataTransfer;
  819. function processItems(items) {
  820. var i, item, reader, hadImage = false;
  821. if (items) {
  822. for (i = 0; i < items.length; i++) {
  823. item = items[i];
  824. if (/^image\/(jpeg|png|gif|bmp)$/.test(item.type)) {
  825. var blob = item.getAsFile ? item.getAsFile() : item;
  826. reader = new window.FileReader();
  827. reader.onload = pasteImage.bind(null, editor, rng, reader, blob);
  828. reader.readAsDataURL(blob);
  829. e.preventDefault();
  830. hadImage = true;
  831. }
  832. }
  833. }
  834. return hadImage;
  835. }
  836. if (editor.settings.paste_data_images && dataTransfer) {
  837. return processItems(dataTransfer.items) || processItems(dataTransfer.files);
  838. }
  839. };
  840. var isBrokenAndroidClipboardEvent = function (e) {
  841. var clipboardData = e.clipboardData;
  842. return navigator.userAgent.indexOf('Android') !== -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
  843. };
  844. var isKeyboardPasteEvent = function (e) {
  845. return global$4.metaKeyPressed(e) && e.keyCode === 86 || e.shiftKey && e.keyCode === 45;
  846. };
  847. var registerEventHandlers = function (editor, pasteBin, pasteFormat) {
  848. var keyboardPasteTimeStamp = 0;
  849. var keyboardPastePlainTextState;
  850. editor.on('keydown', function (e) {
  851. function removePasteBinOnKeyUp(e) {
  852. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  853. pasteBin.remove();
  854. }
  855. }
  856. if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
  857. keyboardPastePlainTextState = e.shiftKey && e.keyCode === 86;
  858. if (keyboardPastePlainTextState && global$1.webkit && navigator.userAgent.indexOf('Version/') !== -1) {
  859. return;
  860. }
  861. e.stopImmediatePropagation();
  862. keyboardPasteTimeStamp = new Date().getTime();
  863. if (global$1.ie && keyboardPastePlainTextState) {
  864. e.preventDefault();
  865. $_8tki3zijjjgwectj.firePaste(editor, true);
  866. return;
  867. }
  868. pasteBin.remove();
  869. pasteBin.create();
  870. editor.once('keyup', removePasteBinOnKeyUp);
  871. editor.once('paste', function () {
  872. editor.off('keyup', removePasteBinOnKeyUp);
  873. });
  874. }
  875. });
  876. function insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal) {
  877. var content, isPlainTextHtml;
  878. if (hasContentType(clipboardContent, 'text/html')) {
  879. content = clipboardContent['text/html'];
  880. } else {
  881. content = pasteBin.getHtml();
  882. internal = internal ? internal : $_4x13hjirjjgwecu1.isMarked(content);
  883. if (pasteBin.isDefaultContent(content)) {
  884. plainTextMode = true;
  885. }
  886. }
  887. content = $_4bi2o9j0jjgwecui.trimHtml(content);
  888. pasteBin.remove();
  889. isPlainTextHtml = internal === false && $_4h3hnrisjjgwecu2.isPlainText(content);
  890. if (!content.length || isPlainTextHtml) {
  891. plainTextMode = true;
  892. }
  893. if (plainTextMode) {
  894. if (hasContentType(clipboardContent, 'text/plain') && isPlainTextHtml) {
  895. content = clipboardContent['text/plain'];
  896. } else {
  897. content = $_4bi2o9j0jjgwecui.innerText(content);
  898. }
  899. }
  900. if (pasteBin.isDefaultContent(content)) {
  901. if (!isKeyBoardPaste) {
  902. editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
  903. }
  904. return;
  905. }
  906. if (plainTextMode) {
  907. pasteText(editor, content);
  908. } else {
  909. pasteHtml$1(editor, content, internal);
  910. }
  911. }
  912. var getLastRng = function () {
  913. return pasteBin.getLastRng() || editor.selection.getRng();
  914. };
  915. editor.on('paste', function (e) {
  916. var clipboardTimer = new Date().getTime();
  917. var clipboardContent = getClipboardContent(editor, e);
  918. var clipboardDelay = new Date().getTime() - clipboardTimer;
  919. var isKeyBoardPaste = new Date().getTime() - keyboardPasteTimeStamp - clipboardDelay < 1000;
  920. var plainTextMode = pasteFormat.get() === 'text' || keyboardPastePlainTextState;
  921. var internal = hasContentType(clipboardContent, $_4x13hjirjjgwecu1.internalHtmlMime());
  922. keyboardPastePlainTextState = false;
  923. if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
  924. pasteBin.remove();
  925. return;
  926. }
  927. if (!hasHtmlOrText(clipboardContent) && pasteImageData(editor, e, getLastRng())) {
  928. pasteBin.remove();
  929. return;
  930. }
  931. if (!isKeyBoardPaste) {
  932. e.preventDefault();
  933. }
  934. if (global$1.ie && (!isKeyBoardPaste || e.ieFake) && !hasContentType(clipboardContent, 'text/html')) {
  935. pasteBin.create();
  936. editor.dom.bind(pasteBin.getEl(), 'paste', function (e) {
  937. e.stopPropagation();
  938. });
  939. editor.getDoc().execCommand('Paste', false, null);
  940. clipboardContent['text/html'] = pasteBin.getHtml();
  941. }
  942. if (hasContentType(clipboardContent, 'text/html')) {
  943. e.preventDefault();
  944. if (!internal) {
  945. internal = $_4x13hjirjjgwecu1.isMarked(clipboardContent['text/html']);
  946. }
  947. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  948. } else {
  949. global$2.setEditorTimeout(editor, function () {
  950. insertClipboardContent(clipboardContent, isKeyBoardPaste, plainTextMode, internal);
  951. }, 0);
  952. }
  953. });
  954. };
  955. var registerEventsAndFilters = function (editor, pasteBin, pasteFormat) {
  956. registerEventHandlers(editor, pasteBin, pasteFormat);
  957. var src;
  958. editor.parser.addNodeFilter('img', function (nodes, name$$1, args) {
  959. var isPasteInsert = function (args) {
  960. return args.data && args.data.paste === true;
  961. };
  962. var remove = function (node) {
  963. if (!node.attr('data-mce-object') && src !== global$1.transparentSrc) {
  964. node.remove();
  965. }
  966. };
  967. var isWebKitFakeUrl = function (src) {
  968. return src.indexOf('webkit-fake-url') === 0;
  969. };
  970. var isDataUri = function (src) {
  971. return src.indexOf('data:') === 0;
  972. };
  973. if (!editor.settings.paste_data_images && isPasteInsert(args)) {
  974. var i = nodes.length;
  975. while (i--) {
  976. src = nodes[i].attributes.map.src;
  977. if (!src) {
  978. continue;
  979. }
  980. if (isWebKitFakeUrl(src)) {
  981. remove(nodes[i]);
  982. } else if (!editor.settings.allow_html_data_urls && isDataUri(src)) {
  983. remove(nodes[i]);
  984. }
  985. }
  986. }
  987. });
  988. };
  989. var getPasteBinParent = function (editor) {
  990. return global$1.ie && editor.inline ? document.body : editor.getBody();
  991. };
  992. var isExternalPasteBin = function (editor) {
  993. return getPasteBinParent(editor) !== editor.getBody();
  994. };
  995. var delegatePasteEvents = function (editor, pasteBinElm) {
  996. if (isExternalPasteBin(editor)) {
  997. editor.dom.bind(pasteBinElm, 'paste keyup', function (e) {
  998. setTimeout(function () {
  999. editor.fire('paste');
  1000. }, 0);
  1001. });
  1002. }
  1003. };
  1004. var create = function (editor, lastRngCell, pasteBinDefaultContent) {
  1005. var dom = editor.dom, body = editor.getBody();
  1006. var pasteBinElm;
  1007. lastRngCell.set(editor.selection.getRng());
  1008. pasteBinElm = editor.dom.add(getPasteBinParent(editor), 'div', {
  1009. 'id': 'mcepastebin',
  1010. 'class': 'mce-pastebin',
  1011. 'contentEditable': true,
  1012. 'data-mce-bogus': 'all',
  1013. 'style': 'position: fixed; top: 50%; width: 10px; height: 10px; overflow: hidden; opacity: 0'
  1014. }, pasteBinDefaultContent);
  1015. if (global$1.ie || global$1.gecko) {
  1016. dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) === 'rtl' ? 65535 : -65535);
  1017. }
  1018. dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function (e) {
  1019. e.stopPropagation();
  1020. });
  1021. delegatePasteEvents(editor, pasteBinElm);
  1022. pasteBinElm.focus();
  1023. editor.selection.select(pasteBinElm, true);
  1024. };
  1025. var remove = function (editor, lastRngCell) {
  1026. if (getEl(editor)) {
  1027. var pasteBinClone = void 0;
  1028. var lastRng = lastRngCell.get();
  1029. while (pasteBinClone = editor.dom.get('mcepastebin')) {
  1030. editor.dom.remove(pasteBinClone);
  1031. editor.dom.unbind(pasteBinClone);
  1032. }
  1033. if (lastRng) {
  1034. editor.selection.setRng(lastRng);
  1035. }
  1036. }
  1037. lastRngCell.set(null);
  1038. };
  1039. var getEl = function (editor) {
  1040. return editor.dom.get('mcepastebin');
  1041. };
  1042. var getHtml = function (editor) {
  1043. var pasteBinElm, pasteBinClones, i, dirtyWrappers, cleanWrapper;
  1044. var copyAndRemove = function (toElm, fromElm) {
  1045. toElm.appendChild(fromElm);
  1046. editor.dom.remove(fromElm, true);
  1047. };
  1048. pasteBinClones = global$3.grep(getPasteBinParent(editor).childNodes, function (elm) {
  1049. return elm.id === 'mcepastebin';
  1050. });
  1051. pasteBinElm = pasteBinClones.shift();
  1052. global$3.each(pasteBinClones, function (pasteBinClone) {
  1053. copyAndRemove(pasteBinElm, pasteBinClone);
  1054. });
  1055. dirtyWrappers = editor.dom.select('div[id=mcepastebin]', pasteBinElm);
  1056. for (i = dirtyWrappers.length - 1; i >= 0; i--) {
  1057. cleanWrapper = editor.dom.create('div');
  1058. pasteBinElm.insertBefore(cleanWrapper, dirtyWrappers[i]);
  1059. copyAndRemove(cleanWrapper, dirtyWrappers[i]);
  1060. }
  1061. return pasteBinElm ? pasteBinElm.innerHTML : '';
  1062. };
  1063. var getLastRng = function (lastRng) {
  1064. return lastRng.get();
  1065. };
  1066. var isDefaultContent = function (pasteBinDefaultContent, content) {
  1067. return content === pasteBinDefaultContent;
  1068. };
  1069. var isPasteBin = function (elm) {
  1070. return elm && elm.id === 'mcepastebin';
  1071. };
  1072. var isDefault = function (editor, pasteBinDefaultContent) {
  1073. var pasteBinElm = getEl(editor);
  1074. return isPasteBin(pasteBinElm) && isDefaultContent(pasteBinDefaultContent, pasteBinElm.innerHTML);
  1075. };
  1076. var PasteBin = function (editor) {
  1077. var lastRng = Cell(null);
  1078. var pasteBinDefaultContent = '%MCEPASTEBIN%';
  1079. return {
  1080. create: function () {
  1081. return create(editor, lastRng, pasteBinDefaultContent);
  1082. },
  1083. remove: function () {
  1084. return remove(editor, lastRng);
  1085. },
  1086. getEl: function () {
  1087. return getEl(editor);
  1088. },
  1089. getHtml: function () {
  1090. return getHtml(editor);
  1091. },
  1092. getLastRng: function () {
  1093. return getLastRng(lastRng);
  1094. },
  1095. isDefault: function () {
  1096. return isDefault(editor, pasteBinDefaultContent);
  1097. },
  1098. isDefaultContent: function (content) {
  1099. return isDefaultContent(pasteBinDefaultContent, content);
  1100. }
  1101. };
  1102. };
  1103. var Clipboard = function (editor, pasteFormat) {
  1104. var pasteBin = PasteBin(editor);
  1105. editor.on('preInit', function () {
  1106. return registerEventsAndFilters(editor, pasteBin, pasteFormat);
  1107. });
  1108. return {
  1109. pasteFormat: pasteFormat,
  1110. pasteHtml: function (html, internalFlag) {
  1111. return pasteHtml$1(editor, html, internalFlag);
  1112. },
  1113. pasteText: function (text) {
  1114. return pasteText(editor, text);
  1115. },
  1116. pasteImageData: function (e, rng) {
  1117. return pasteImageData(editor, e, rng);
  1118. },
  1119. getDataTransferItems: getDataTransferItems,
  1120. hasHtmlOrText: hasHtmlOrText,
  1121. hasContentType: hasContentType
  1122. };
  1123. };
  1124. var noop = function () {
  1125. };
  1126. var hasWorkingClipboardApi = function (clipboardData) {
  1127. return global$1.iOS === false && clipboardData !== undefined && typeof clipboardData.setData === 'function' && $_4bi2o9j0jjgwecui.isMsEdge() !== true;
  1128. };
  1129. var setHtml5Clipboard = function (clipboardData, html, text) {
  1130. if (hasWorkingClipboardApi(clipboardData)) {
  1131. try {
  1132. clipboardData.clearData();
  1133. clipboardData.setData('text/html', html);
  1134. clipboardData.setData('text/plain', text);
  1135. clipboardData.setData($_4x13hjirjjgwecu1.internalHtmlMime(), html);
  1136. return true;
  1137. } catch (e) {
  1138. return false;
  1139. }
  1140. } else {
  1141. return false;
  1142. }
  1143. };
  1144. var setClipboardData = function (evt, data, fallback, done) {
  1145. if (setHtml5Clipboard(evt.clipboardData, data.html, data.text)) {
  1146. evt.preventDefault();
  1147. done();
  1148. } else {
  1149. fallback(data.html, done);
  1150. }
  1151. };
  1152. var fallback = function (editor) {
  1153. return function (html, done) {
  1154. var markedHtml = $_4x13hjirjjgwecu1.mark(html);
  1155. var outer = editor.dom.create('div', {
  1156. 'contenteditable': 'false',
  1157. 'data-mce-bogus': 'all'
  1158. });
  1159. var inner = editor.dom.create('div', { contenteditable: 'true' }, markedHtml);
  1160. editor.dom.setStyles(outer, {
  1161. position: 'fixed',
  1162. top: '0',
  1163. left: '-3000px',
  1164. width: '1000px',
  1165. overflow: 'hidden'
  1166. });
  1167. outer.appendChild(inner);
  1168. editor.dom.add(editor.getBody(), outer);
  1169. var range = editor.selection.getRng();
  1170. inner.focus();
  1171. var offscreenRange = editor.dom.createRng();
  1172. offscreenRange.selectNodeContents(inner);
  1173. editor.selection.setRng(offscreenRange);
  1174. setTimeout(function () {
  1175. editor.selection.setRng(range);
  1176. outer.parentNode.removeChild(outer);
  1177. done();
  1178. }, 0);
  1179. };
  1180. };
  1181. var getData = function (editor) {
  1182. return {
  1183. html: editor.selection.getContent({ contextual: true }),
  1184. text: editor.selection.getContent({ format: 'text' })
  1185. };
  1186. };
  1187. var cut = function (editor) {
  1188. return function (evt) {
  1189. if (editor.selection.isCollapsed() === false) {
  1190. setClipboardData(evt, getData(editor), fallback(editor), function () {
  1191. setTimeout(function () {
  1192. editor.execCommand('Delete');
  1193. }, 0);
  1194. });
  1195. }
  1196. };
  1197. };
  1198. var copy = function (editor) {
  1199. return function (evt) {
  1200. if (editor.selection.isCollapsed() === false) {
  1201. setClipboardData(evt, getData(editor), fallback(editor), noop);
  1202. }
  1203. };
  1204. };
  1205. var register$1 = function (editor) {
  1206. editor.on('cut', cut(editor));
  1207. editor.on('copy', copy(editor));
  1208. };
  1209. var $_32blojj3jjgwecv4 = { register: register$1 };
  1210. var global$10 = tinymce.util.Tools.resolve('tinymce.dom.RangeUtils');
  1211. var getCaretRangeFromEvent = function (editor, e) {
  1212. return global$10.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
  1213. };
  1214. var isPlainTextFileUrl = function (content) {
  1215. var plainTextContent = content['text/plain'];
  1216. return plainTextContent ? plainTextContent.indexOf('file://') === 0 : false;
  1217. };
  1218. var setFocusedRange = function (editor, rng) {
  1219. editor.focus();
  1220. editor.selection.setRng(rng);
  1221. };
  1222. var setup = function (editor, clipboard, draggingInternallyState) {
  1223. if ($_xr8b0ikjjgwectl.shouldBlockDrop(editor)) {
  1224. editor.on('dragend dragover draggesture dragdrop drop drag', function (e) {
  1225. e.preventDefault();
  1226. e.stopPropagation();
  1227. });
  1228. }
  1229. if (!$_xr8b0ikjjgwectl.shouldPasteDataImages(editor)) {
  1230. editor.on('drop', function (e) {
  1231. var dataTransfer = e.dataTransfer;
  1232. if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
  1233. e.preventDefault();
  1234. }
  1235. });
  1236. }
  1237. editor.on('drop', function (e) {
  1238. var dropContent, rng;
  1239. rng = getCaretRangeFromEvent(editor, e);
  1240. if (e.isDefaultPrevented() || draggingInternallyState.get()) {
  1241. return;
  1242. }
  1243. dropContent = clipboard.getDataTransferItems(e.dataTransfer);
  1244. var internal = clipboard.hasContentType(dropContent, $_4x13hjirjjgwecu1.internalHtmlMime());
  1245. if ((!clipboard.hasHtmlOrText(dropContent) || isPlainTextFileUrl(dropContent)) && clipboard.pasteImageData(e, rng)) {
  1246. return;
  1247. }
  1248. if (rng && $_xr8b0ikjjgwectl.shouldFilterDrop(editor)) {
  1249. var content_1 = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
  1250. if (content_1) {
  1251. e.preventDefault();
  1252. global$2.setEditorTimeout(editor, function () {
  1253. editor.undoManager.transact(function () {
  1254. if (dropContent['mce-internal']) {
  1255. editor.execCommand('Delete');
  1256. }
  1257. setFocusedRange(editor, rng);
  1258. content_1 = $_4bi2o9j0jjgwecui.trimHtml(content_1);
  1259. if (!dropContent['text/html']) {
  1260. clipboard.pasteText(content_1);
  1261. } else {
  1262. clipboard.pasteHtml(content_1, internal);
  1263. }
  1264. });
  1265. });
  1266. }
  1267. }
  1268. });
  1269. editor.on('dragstart', function (e) {
  1270. draggingInternallyState.set(true);
  1271. });
  1272. editor.on('dragover dragend', function (e) {
  1273. if ($_xr8b0ikjjgwectl.shouldPasteDataImages(editor) && draggingInternallyState.get() === false) {
  1274. e.preventDefault();
  1275. setFocusedRange(editor, getCaretRangeFromEvent(editor, e));
  1276. }
  1277. if (e.type === 'dragend') {
  1278. draggingInternallyState.set(false);
  1279. }
  1280. });
  1281. };
  1282. var $_b4etj0j4jjgwecv7 = { setup: setup };
  1283. var setup$1 = function (editor) {
  1284. var plugin = editor.plugins.paste;
  1285. var preProcess = $_xr8b0ikjjgwectl.getPreProcess(editor);
  1286. if (preProcess) {
  1287. editor.on('PastePreProcess', function (e) {
  1288. preProcess.call(plugin, plugin, e);
  1289. });
  1290. }
  1291. var postProcess = $_xr8b0ikjjgwectl.getPostProcess(editor);
  1292. if (postProcess) {
  1293. editor.on('PastePostProcess', function (e) {
  1294. postProcess.call(plugin, plugin, e);
  1295. });
  1296. }
  1297. };
  1298. var $_c5bihmj6jjgwecva = { setup: setup$1 };
  1299. function addPreProcessFilter(editor, filterFunc) {
  1300. editor.on('PastePreProcess', function (e) {
  1301. e.content = filterFunc(editor, e.content, e.internal, e.wordContent);
  1302. });
  1303. }
  1304. function addPostProcessFilter(editor, filterFunc) {
  1305. editor.on('PastePostProcess', function (e) {
  1306. filterFunc(editor, e.node);
  1307. });
  1308. }
  1309. function removeExplorerBrElementsAfterBlocks(editor, html) {
  1310. if (!$_dfatuiivjjgwecu8.isWordContent(html)) {
  1311. return html;
  1312. }
  1313. var blockElements = [];
  1314. global$3.each(editor.schema.getBlockElements(), function (block, blockName) {
  1315. blockElements.push(blockName);
  1316. });
  1317. var explorerBlocksRegExp = new RegExp('(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br>&nbsp;[\\s\\r\\n]+|<br>)*', 'g');
  1318. html = $_4bi2o9j0jjgwecui.filter(html, [[
  1319. explorerBlocksRegExp,
  1320. '$1'
  1321. ]]);
  1322. html = $_4bi2o9j0jjgwecui.filter(html, [
  1323. [
  1324. /<br><br>/g,
  1325. '<BR><BR>'
  1326. ],
  1327. [
  1328. /<br>/g,
  1329. ' '
  1330. ],
  1331. [
  1332. /<BR><BR>/g,
  1333. '<br>'
  1334. ]
  1335. ]);
  1336. return html;
  1337. }
  1338. function removeWebKitStyles(editor, content, internal, isWordHtml) {
  1339. if (isWordHtml || internal) {
  1340. return content;
  1341. }
  1342. var webKitStylesSetting = $_xr8b0ikjjgwectl.getWebkitStyles(editor);
  1343. var webKitStyles;
  1344. if ($_xr8b0ikjjgwectl.shouldRemoveWebKitStyles(editor) === false || webKitStylesSetting === 'all') {
  1345. return content;
  1346. }
  1347. if (webKitStylesSetting) {
  1348. webKitStyles = webKitStylesSetting.split(/[, ]/);
  1349. }
  1350. if (webKitStyles) {
  1351. var dom_1 = editor.dom, node_1 = editor.selection.getNode();
  1352. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, function (all, before, value, after) {
  1353. var inputStyles = dom_1.parseStyle(dom_1.decode(value));
  1354. var outputStyles = {};
  1355. if (webKitStyles === 'none') {
  1356. return before + after;
  1357. }
  1358. for (var i = 0; i < webKitStyles.length; i++) {
  1359. var inputValue = inputStyles[webKitStyles[i]], currentValue = dom_1.getStyle(node_1, webKitStyles[i], true);
  1360. if (/color/.test(webKitStyles[i])) {
  1361. inputValue = dom_1.toHex(inputValue);
  1362. currentValue = dom_1.toHex(currentValue);
  1363. }
  1364. if (currentValue !== inputValue) {
  1365. outputStyles[webKitStyles[i]] = inputValue;
  1366. }
  1367. }
  1368. outputStyles = dom_1.serializeStyle(outputStyles, 'span');
  1369. if (outputStyles) {
  1370. return before + ' style="' + outputStyles + '"' + after;
  1371. }
  1372. return before + after;
  1373. });
  1374. } else {
  1375. content = content.replace(/(<[^>]+) style="([^"]*)"([^>]*>)/gi, '$1$3');
  1376. }
  1377. content = content.replace(/(<[^>]+) data-mce-style="([^"]+)"([^>]*>)/gi, function (all, before, value, after) {
  1378. return before + ' style="' + value + '"' + after;
  1379. });
  1380. return content;
  1381. }
  1382. function removeUnderlineAndFontInAnchor(editor, root) {
  1383. editor.$('a', root).find('font,u').each(function (i, node) {
  1384. editor.dom.remove(node, true);
  1385. });
  1386. }
  1387. var setup$2 = function (editor) {
  1388. if (global$1.webkit) {
  1389. addPreProcessFilter(editor, removeWebKitStyles);
  1390. }
  1391. if (global$1.ie) {
  1392. addPreProcessFilter(editor, removeExplorerBrElementsAfterBlocks);
  1393. addPostProcessFilter(editor, removeUnderlineAndFontInAnchor);
  1394. }
  1395. };
  1396. var $_36tmgyj7jjgwecvc = { setup: setup$2 };
  1397. var curry = function (f) {
  1398. var x = [];
  1399. for (var _i = 1; _i < arguments.length; _i++) {
  1400. x[_i - 1] = arguments[_i];
  1401. }
  1402. var args = new Array(arguments.length - 1);
  1403. for (var i = 1; i < arguments.length; i++)
  1404. args[i - 1] = arguments[i];
  1405. return function () {
  1406. var x = [];
  1407. for (var _i = 0; _i < arguments.length; _i++) {
  1408. x[_i] = arguments[_i];
  1409. }
  1410. var newArgs = new Array(arguments.length);
  1411. for (var j = 0; j < newArgs.length; j++)
  1412. newArgs[j] = arguments[j];
  1413. var all = args.concat(newArgs);
  1414. return f.apply(null, all);
  1415. };
  1416. };
  1417. var stateChange = function (editor, clipboard, e) {
  1418. var ctrl = e.control;
  1419. ctrl.active(clipboard.pasteFormat.get() === 'text');
  1420. editor.on('PastePlainTextToggle', function (e) {
  1421. ctrl.active(e.state);
  1422. });
  1423. };
  1424. var register$2 = function (editor, clipboard) {
  1425. var postRender = curry(stateChange, editor, clipboard);
  1426. editor.addButton('pastetext', {
  1427. active: false,
  1428. icon: 'pastetext',
  1429. tooltip: 'Paste as text',
  1430. cmd: 'mceTogglePlainTextPaste',
  1431. onPostRender: postRender
  1432. });
  1433. editor.addMenuItem('pastetext', {
  1434. text: 'Paste as text',
  1435. selectable: true,
  1436. active: clipboard.pasteFormat,
  1437. cmd: 'mceTogglePlainTextPaste',
  1438. onPostRender: postRender
  1439. });
  1440. };
  1441. var $_g9yhwdj8jjgwecvf = { register: register$2 };
  1442. global.add('paste', function (editor) {
  1443. if ($_15bf6siejjgwect1.hasProPlugin(editor) === false) {
  1444. var userIsInformedState = Cell(false);
  1445. var draggingInternallyState = Cell(false);
  1446. var pasteFormat = Cell($_xr8b0ikjjgwectl.isPasteAsTextEnabled(editor) ? 'text' : 'html');
  1447. var clipboard = Clipboard(editor, pasteFormat);
  1448. var quirks = $_36tmgyj7jjgwecvc.setup(editor);
  1449. $_g9yhwdj8jjgwecvf.register(editor, clipboard);
  1450. $_fldd1mihjjgwecth.register(editor, clipboard, userIsInformedState);
  1451. $_c5bihmj6jjgwecva.setup(editor);
  1452. $_32blojj3jjgwecv4.register(editor);
  1453. $_b4etj0j4jjgwecv7.setup(editor, clipboard, draggingInternallyState);
  1454. return $_6gtliyigjjgwecte.get(clipboard, quirks);
  1455. }
  1456. });
  1457. function Plugin () {
  1458. }
  1459. return Plugin;
  1460. }());
  1461. })();