2 * Compiled inline version. (Library mode)
5 /*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
8 (function(exports, undefined) {
13 function require(ids, callback) {
14 var module, defs = [];
16 for (var i = 0; i < ids.length; ++i) {
17 module = modules[ids[i]] || resolve(ids[i]);
19 throw 'module definition dependecy not found: ' + ids[i];
25 callback.apply(null, defs);
28 function define(id, dependencies, definition) {
29 if (typeof id !== 'string') {
30 throw 'invalid module definition, module id must be defined and be a string';
33 if (dependencies === undefined) {
34 throw 'invalid module definition, dependencies must be specified';
37 if (definition === undefined) {
38 throw 'invalid module definition, definition function must be specified';
41 require(dependencies, function() {
42 modules[id] = definition.apply(null, arguments);
46 function defined(id) {
50 function resolve(id) {
52 var fragments = id.split(/[.\/]/);
54 for (var fi = 0; fi < fragments.length; ++fi) {
55 if (!target[fragments[fi]]) {
59 target = target[fragments[fi]];
65 function expose(ids) {
66 for (var i = 0; i < ids.length; i++) {
69 var fragments = id.split(/[.\/]/);
71 for (var fi = 0; fi < fragments.length - 1; ++fi) {
72 if (target[fragments[fi]] === undefined) {
73 target[fragments[fi]] = {};
76 target = target[fragments[fi]];
79 target[fragments[fragments.length - 1]] = modules[id];
83 // Included from: js/tinymce/plugins/paste/classes/Utils.js
88 * Copyright, Moxiecode Systems AB
89 * Released under LGPL License.
91 * License: http://www.tinymce.com/license
92 * Contributing: http://www.tinymce.com/contributing
96 * This class contails various utility functions for the paste plugin.
98 * @class tinymce.pasteplugin.Clipboard
101 define("tinymce/pasteplugin/Utils", [
102 "tinymce/util/Tools",
103 "tinymce/html/DomParser",
104 "tinymce/html/Schema"
105 ], function(Tools, DomParser, Schema) {
106 function filter(content, items) {
107 Tools.each(items, function(v) {
108 if (v.constructor == RegExp) {
109 content = content.replace(v, '');
111 content = content.replace(v[0], v[1]);
119 * Gets the innerText of the specified element. It will handle edge cases
120 * and works better than textContent on Gecko.
122 * @param {String} html HTML string to get text from.
123 * @return {String} String of text with line feeds.
125 function innerText(html) {
126 var schema = new Schema(), domParser = new DomParser({}, schema), text = '';
127 var shortEndedElements = schema.getShortEndedElements();
128 var ignoreElements = Tools.makeMap('script noscript style textarea video audio iframe object', ' ');
129 var blockElements = schema.getBlockElements();
131 function walk(node) {
132 var name = node.name, currentNode = node;
140 if (shortEndedElements[name]) {
144 // Ingore script, video contents
145 if (ignoreElements[name]) {
150 if (node.type == 3) {
155 if (!node.shortEnded) {
156 if ((node = node.firstChild)) {
159 } while ((node = node.next));
163 // Add \n or \n\n for blocks or P
164 if (blockElements[name] && currentNode.next) {
173 walk(domParser.parse(html));
184 // Included from: js/tinymce/plugins/paste/classes/Clipboard.js
189 * Copyright, Moxiecode Systems AB
190 * Released under LGPL License.
192 * License: http://www.tinymce.com/license
193 * Contributing: http://www.tinymce.com/contributing
197 * This class contains logic for getting HTML contents out of the clipboard.
199 * We need to make a lot of ugly hacks to get the contents out of the clipboard since
200 * the W3C Clipboard API is broken in all browsers that have it: Gecko/WebKit/Blink.
201 * We might rewrite this the way those API:s stabilize. Browsers doesn't handle pasting
202 * from applications like Word the same way as it does when pasting into a contentEditable area
203 * so we need to do lots of extra work to try to get to this clipboard data.
205 * Current implementation steps:
206 * 1. On keydown with paste keys Ctrl+V or Shift+Insert create
207 * a paste bin element and move focus to that element.
208 * 2. Wait for the browser to fire a "paste" event and get the contents out of the paste bin.
209 * 3. Check if the paste was successful if true, process the HTML.
210 * (4). If the paste was unsuccessful use IE execCommand, Clipboard API, document.dataTransfer old WebKit API etc.
212 * @class tinymce.pasteplugin.Clipboard
215 define("tinymce/pasteplugin/Clipboard", [
218 "tinymce/pasteplugin/Utils"
219 ], function(Env, VK, Utils) {
220 return function(editor) {
221 var self = this, pasteBinElm, lastRng, keyboardPasteTimeStamp = 0;
222 var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
225 * Pastes the specified HTML. This means that the HTML is filtered and then
226 * inserted at the current selection in the editor. It will also fire paste events
227 * for custom user filtering.
229 * @param {String} html HTML code to paste into the current selection.
231 function pasteHtml(html) {
232 var args, dom = editor.dom;
234 args = editor.fire('BeforePastePreProcess', {content: html}); // Internal event used by Quirks
235 args = editor.fire('PastePreProcess', args);
238 if (!args.isDefaultPrevented()) {
239 // User has bound PastePostProcess events then we need to pass it through a DOM node
240 // This is not ideal but we don't want to let the browser mess up the HTML for example
241 // some browsers add to P tags etc
242 if (editor.hasEventListeners('PastePostProcess') && !args.isDefaultPrevented()) {
243 // We need to attach the element to the DOM so Sizzle selectors work on the contents
244 var tempBody = dom.add(editor.getBody(), 'div', {style: 'display:none'}, html);
245 args = editor.fire('PastePostProcess', {node: tempBody});
246 dom.remove(tempBody);
247 html = args.node.innerHTML;
250 if (!args.isDefaultPrevented()) {
251 editor.insertContent(html);
257 * Pastes the specified text. This means that the plain text is processed
258 * and converted into BR and P elements. It will fire paste events for custom filtering.
260 * @param {String} text Text to paste as the current selection location.
262 function pasteText(text) {
263 text = editor.dom.encode(text).replace(/\r\n/g, '\n');
265 var startBlock = editor.dom.getParent(editor.selection.getStart(), editor.dom.isBlock);
267 // Create start block html for example <p attr="value">
268 var forcedRootBlockName = editor.settings.forced_root_block;
269 var forcedRootBlockStartHtml;
270 if (forcedRootBlockName) {
271 forcedRootBlockStartHtml = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs);
272 forcedRootBlockStartHtml = forcedRootBlockStartHtml.substr(0, forcedRootBlockStartHtml.length - 3) + '>';
275 if ((startBlock && /^(PRE|DIV)$/.test(startBlock.nodeName)) || !forcedRootBlockName) {
276 text = Utils.filter(text, [
280 text = Utils.filter(text, [
281 [/\n\n/g, "</p>" + forcedRootBlockStartHtml],
282 [/^(.*<\/p>)(<p>)$/, forcedRootBlockStartHtml + '$1'],
286 if (text.indexOf('<p>') != -1) {
287 text = forcedRootBlockStartHtml + text;
295 * Creates a paste bin element as close as possible to the current caret location and places the focus inside that element
296 * so that when the real paste event occurs the contents gets inserted into this element
297 * instead of the current editor selection element.
299 function createPasteBin() {
300 var dom = editor.dom, body = editor.getBody();
301 var viewport = editor.dom.getViewPort(editor.getWin()), scrollTop = viewport.y, top = 20;
304 lastRng = editor.selection.getRng();
307 scrollContainer = editor.selection.getScrollContainer();
309 if (scrollContainer) {
310 scrollTop = scrollContainer.scrollTop;
314 // Calculate top cordinate this is needed to avoid scrolling to top of document
315 // We want the paste bin to be as close to the caret as possible to avoid scrolling
316 if (lastRng.getClientRects) {
317 var rects = lastRng.getClientRects();
320 // Client rects gets us closes to the actual
321 // caret location in for example a wrapped paragraph block
322 top = scrollTop + (rects[0].top - dom.getPos(body).y);
326 // Check if we can find a closer location by checking the range element
327 var container = lastRng.startContainer;
329 if (container.nodeType == 3 && container.parentNode != body) {
330 container = container.parentNode;
333 if (container.nodeType == 1) {
334 top = dom.getPos(container, scrollContainer || body).y;
341 pasteBinElm = dom.add(editor.getBody(), 'div', {
343 contentEditable: true,
344 "data-mce-bogus": "1",
345 style: 'position: absolute; top: ' + top + 'px;' +
346 'width: 10px; height: 10px; overflow: hidden; opacity: 0'
347 }, pasteBinDefaultContent);
349 // Move paste bin out of sight since the controlSelection rect gets displayed otherwise on IE and Gecko
350 if (Env.ie || Env.gecko) {
351 dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) == 'rtl' ? 0xFFFF : -0xFFFF);
354 // Prevent focus events from bubbeling fixed FocusManager issues
355 dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function(e) {
360 editor.selection.select(pasteBinElm, true);
364 * Removes the paste bin if it exists.
366 function removePasteBin() {
370 // WebKit/Blink might clone the div so
371 // lets make sure we remove all clones
372 // TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
373 while ((pasteBinClone = editor.dom.get('mcepastebin'))) {
374 editor.dom.remove(pasteBinClone);
375 editor.dom.unbind(pasteBinClone);
379 editor.selection.setRng(lastRng);
383 keyboardPastePlainTextState = false;
384 pasteBinElm = lastRng = null;
388 * Returns the contents of the paste bin as a HTML string.
390 * @return {String} Get the contents of the paste bin.
392 function getPasteBinHtml() {
393 var html = pasteBinDefaultContent, pasteBinClones, i;
395 // Since WebKit/Chrome might clone the paste bin when pasting
396 // for example: <img style="float: right"> we need to check if any of them contains some useful html.
397 // TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
398 pasteBinClones = editor.dom.select('div[id=mcepastebin]');
399 i = pasteBinClones.length;
401 var cloneHtml = pasteBinClones[i].innerHTML;
403 if (html == pasteBinDefaultContent) {
407 if (cloneHtml.length > html.length) {
416 * Gets various content types out of a datatransfer object.
418 * @param {DataTransfer} dataTransfer Event fired on paste.
419 * @return {Object} Object with mime types and data for those mime types.
421 function getDataTransferItems(dataTransfer) {
424 if (dataTransfer && dataTransfer.types) {
425 // Use old WebKit API
426 var legacyText = dataTransfer.getData('Text');
427 if (legacyText && legacyText.length > 0) {
428 data['text/plain'] = legacyText;
431 for (var i = 0; i < dataTransfer.types.length; i++) {
432 var contentType = dataTransfer.types[i];
433 data[contentType] = dataTransfer.getData(contentType);
441 * Gets various content types out of the Clipboard API. It will also get the
442 * plain text using older IE and WebKit API:s.
444 * @param {ClipboardEvent} clipboardEvent Event fired on paste.
445 * @return {Object} Object with mime types and data for those mime types.
447 function getClipboardContent(clipboardEvent) {
448 return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
452 * Checks if the clipboard contains image data if it does it will take that data
453 * and convert it into a data url image and paste that image at the caret location.
455 * @param {ClipboardEvent} e Paste event object.
456 * @param {Object} clipboardContent Collection of clipboard contents.
457 * @return {Boolean} true/false if the image data was found or not.
459 function pasteImageData(e, clipboardContent) {
460 function pasteImage(item) {
461 if (items[i].type == 'image/png') {
462 var reader = new FileReader();
464 reader.onload = function() {
465 pasteHtml('<img src="' + reader.result + '">');
468 reader.readAsDataURL(item.getAsFile());
474 // If paste data images are disabled or there is HTML or plain text
475 // contents then proceed with the normal paste process
476 if (!editor.settings.paste_data_images || "text/html" in clipboardContent || "text/plain" in clipboardContent) {
480 if (e.clipboardData) {
481 var items = e.clipboardData.items;
484 for (var i = 0; i < items.length; i++) {
485 if (pasteImage(items[i])) {
493 function getCaretRangeFromEvent(e) {
494 var doc = editor.getDoc(), rng;
496 if (doc.caretPositionFromPoint) {
497 var point = doc.caretPositionFromPoint(e.clientX, e.clientY);
498 rng = doc.createRange();
499 rng.setStart(point.offsetNode, point.offset);
501 } else if (doc.caretRangeFromPoint) {
502 rng = doc.caretRangeFromPoint(e.clientX, e.clientY);
508 function hasContentType(clipboardContent, mimeType) {
509 return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
512 function registerEventHandlers() {
513 editor.on('keydown', function(e) {
514 if (e.isDefaultPrevented()) {
518 // Ctrl+V or Shift+Insert
519 if ((VK.metaKeyPressed(e) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45)) {
520 keyboardPastePlainTextState = e.shiftKey && e.keyCode == 86;
522 // Prevent undoManager keydown handler from making an undo level with the pastebin in it
523 e.stopImmediatePropagation();
525 keyboardPasteTimeStamp = new Date().getTime();
527 // IE doesn't support Ctrl+Shift+V and it doesn't even produce a paste event
528 // so lets fake a paste event and let IE use the execCommand/dataTransfer methods
529 if (Env.ie && keyboardPastePlainTextState) {
531 editor.fire('paste', {ieFake: true});
540 editor.on('paste', function(e) {
541 var clipboardContent = getClipboardContent(e);
542 var isKeyBoardPaste = new Date().getTime() - keyboardPasteTimeStamp < 1000;
543 var plainTextMode = self.pasteFormat == "text" || keyboardPastePlainTextState;
545 if (e.isDefaultPrevented()) {
550 if (pasteImageData(e, clipboardContent)) {
555 // Not a keyboard paste prevent default paste and try to grab the clipboard contents using different APIs
556 if (!isKeyBoardPaste) {
560 // Try IE only method if paste isn't a keyboard paste
561 if (Env.ie && (!isKeyBoardPaste || e.ieFake)) {
564 editor.dom.bind(pasteBinElm, 'paste', function(e) {
568 editor.getDoc().execCommand('Paste', false, null);
569 clipboardContent["text/html"] = getPasteBinHtml();
572 setTimeout(function() {
573 var html = getPasteBinHtml();
575 // WebKit has a nice bug where it clones the paste bin if you paste from for example notepad
576 if (pasteBinElm && pasteBinElm.firstChild && pasteBinElm.firstChild.id === 'mcepastebin') {
577 plainTextMode = true;
582 // Always use pastebin HTML if it's available since it contains Word contents
583 if (!plainTextMode && isKeyBoardPaste && html && html != pasteBinDefaultContent) {
584 clipboardContent['text/html'] = html;
587 if (html == pasteBinDefaultContent || !isKeyBoardPaste) {
588 html = clipboardContent['text/html'] || clipboardContent['text/plain'] || pasteBinDefaultContent;
590 if (html == pasteBinDefaultContent) {
591 if (!isKeyBoardPaste) {
592 editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
599 // Force plain text mode if we only got a text/plain content type
600 if (!hasContentType(clipboardContent, 'text/html') && hasContentType(clipboardContent, 'text/plain')) {
601 plainTextMode = true;
605 pasteText(clipboardContent['text/plain'] || Utils.innerText(html));
612 editor.on('dragstart', function(e) {
613 if (e.dataTransfer.types) {
615 e.dataTransfer.setData('mce-internal', editor.selection.getContent());
617 // IE 10 throws an error since it doesn't support custom data items
622 editor.on('drop', function(e) {
623 var rng = getCaretRangeFromEvent(e);
625 if (rng && !e.isDefaultPrevented()) {
626 var dropContent = getDataTransferItems(e.dataTransfer);
627 var content = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
632 editor.undoManager.transact(function() {
633 if (dropContent['mce-internal']) {
634 editor.execCommand('Delete');
637 editor.selection.setRng(rng);
639 if (!dropContent['text/html']) {
650 self.pasteHtml = pasteHtml;
651 self.pasteText = pasteText;
653 editor.on('preInit', function() {
654 registerEventHandlers();
656 // Remove all data images from paste for example from Gecko
657 // except internal images like video elements
658 editor.parser.addNodeFilter('img', function(nodes) {
659 if (!editor.settings.paste_data_images) {
660 var i = nodes.length;
663 var src = nodes[i].attributes.map.src;
664 if (src && src.indexOf('data:image') === 0) {
665 if (!nodes[i].attr('data-mce-object') && src !== Env.transparentSrc) {
674 // Fix for #6504 we need to remove the paste bin on IE if the user paste in a file
675 editor.on('PreProcess', function() {
676 editor.dom.remove(editor.dom.get('mcepastebin'));
681 // Included from: js/tinymce/plugins/paste/classes/WordFilter.js
686 * Copyright, Moxiecode Systems AB
687 * Released under LGPL License.
689 * License: http://www.tinymce.com/license
690 * Contributing: http://www.tinymce.com/contributing
694 * This class parses word HTML into proper TinyMCE markup.
696 * @class tinymce.pasteplugin.Quirks
699 define("tinymce/pasteplugin/WordFilter", [
700 "tinymce/util/Tools",
701 "tinymce/html/DomParser",
702 "tinymce/html/Schema",
703 "tinymce/html/Serializer",
705 "tinymce/pasteplugin/Utils"
706 ], function(Tools, DomParser, Schema, Serializer, Node, Utils) {
708 * Checks if the specified content is from any of the following sources: MS Word/Office 365/Google docs.
710 function isWordContent(content) {
712 (/<font face="Times New Roman"|class="?Mso|style="[^"]*\bmso-|style='[^'']*\bmso-|w:WordDocument/i).test(content) ||
713 (/class="OutlineElement/).test(content) ||
714 (/id="?docs\-internal\-guid\-/.test(content))
718 function WordFilter(editor) {
719 var settings = editor.settings;
721 editor.on('BeforePastePreProcess', function(e) {
722 var content = e.content, retainStyleProperties, validStyles;
724 retainStyleProperties = settings.paste_retain_style_properties;
725 if (retainStyleProperties) {
726 validStyles = Tools.makeMap(retainStyleProperties.split(/[, ]/));
730 * Converts fake bullet and numbered lists to real semantic OL/UL.
732 * @param {tinymce.html.Node} node Root node to convert children of.
734 function convertFakeListsToProperLists(node) {
735 var currentListNode, prevListNode, lastLevel = 1;
737 function convertParagraphToLi(paragraphNode, listStartTextNode, listName, start) {
738 var level = paragraphNode._listLevel || lastLevel;
740 // Handle list nesting
741 if (level != lastLevel) {
742 if (level < lastLevel) {
743 // Move to parent list
744 if (currentListNode) {
745 currentListNode = currentListNode.parent.parent;
749 prevListNode = currentListNode;
750 currentListNode = null;
754 if (!currentListNode || currentListNode.name != listName) {
755 prevListNode = prevListNode || currentListNode;
756 currentListNode = new Node(listName, 1);
759 currentListNode.attr('start', '' + start);
762 paragraphNode.wrap(currentListNode);
764 currentListNode.append(paragraphNode);
767 paragraphNode.name = 'li';
768 listStartTextNode.value = '';
770 var nextNode = listStartTextNode.next;
771 if (nextNode && nextNode.type == 3) {
772 nextNode.value = nextNode.value.replace(/^\u00a0+/, '');
775 // Append list to previous list if it exists
776 if (level > lastLevel && prevListNode) {
777 prevListNode.lastChild.append(currentListNode);
783 var paragraphs = node.getAll('p');
785 for (var i = 0; i < paragraphs.length; i++) {
786 node = paragraphs[i];
788 if (node.name == 'p' && node.firstChild) {
789 // Find first text node in paragraph
791 var listStartTextNode = node.firstChild;
793 while (listStartTextNode) {
794 nodeText = listStartTextNode.value;
799 listStartTextNode = listStartTextNode.firstChild;
802 // Detect unordered lists look for bullets
803 if (/^\s*[\u2022\u00b7\u00a7\u00d8\u25CF]\s*$/.test(nodeText)) {
804 convertParagraphToLi(node, listStartTextNode, 'ul');
808 // Detect ordered lists 1., a. or ixv.
809 if (/^\s*\w+\.$/.test(nodeText)) {
810 // Parse OL start number
811 var matches = /([0-9])\./.exec(nodeText);
814 start = parseInt(matches[1], 10);
817 convertParagraphToLi(node, listStartTextNode, 'ol', start);
821 currentListNode = null;
826 function filterStyles(node, styleValue) {
827 var outputStyles = {}, styles = editor.dom.parseStyle(styleValue);
829 // Parse out list indent level for lists
830 if (node.name === 'p') {
831 var matches = /mso-list:\w+ \w+([0-9]+)/.exec(styleValue);
834 node._listLevel = parseInt(matches[1], 10);
838 Tools.each(styles, function(value, name) {
839 // Convert various MS styles to W3C styles
846 name = "vertical-align";
850 case "mso-foreground":
854 case "mso-background":
855 case "mso-highlight":
861 if (value != "normal") {
862 outputStyles[name] = value;
867 // Remove track changes code
868 if (/^(comment|comment-list)$/i.test(value)) {
876 if (name.indexOf('mso-comment') === 0) {
881 // Never allow mso- prefixed names
882 if (name.indexOf('mso-') === 0) {
886 // Output only valid styles
887 if (retainStyleProperties == "all" || (validStyles && validStyles[name])) {
888 outputStyles[name] = value;
892 // Convert bold style to "b" element
893 if (/(bold)/i.test(outputStyles["font-weight"])) {
894 delete outputStyles["font-weight"];
895 node.wrap(new Node("b", 1));
898 // Convert italic style to "i" element
899 if (/(italic)/i.test(outputStyles["font-style"])) {
900 delete outputStyles["font-style"];
901 node.wrap(new Node("i", 1));
904 // Serialize the styles and see if there is something left to keep
905 outputStyles = editor.dom.serializeStyle(outputStyles, node.name);
913 if (settings.paste_enable_default_filters === false) {
917 // Detect is the contents is Word junk HTML
918 if (isWordContent(e.content)) {
919 e.wordContent = true; // Mark it for other processors
921 // Remove basic Word junk
922 content = Utils.filter(content, [
923 // Word comments like conditional comments etc
926 // Remove comments, scripts (e.g., msoShowComment), XML tag, VML content,
927 // MS Office namespaced tags, and a few other tags
928 /<(!|script[^>]*>.*?<\/script(?=[>\s])|\/?(\?xml(:\w+)?|img|meta|link|style|\w:\w+)(?=[\s\/>]))[^>]*>/gi,
930 // Convert <s> into <strike> for line-though
931 [/<(\/?)s>/gi, "<$1strike>"],
933 // Replace nsbp entites to char since it's easier to handle
934 [/ /gi, "\u00a0"],
936 // Convert <span style="mso-spacerun:yes">___</span> to string of alternating
937 // breaking/non-breaking spaces of same length
938 [/<span\s+style\s*=\s*"\s*mso-spacerun\s*:\s*yes\s*;?\s*"\s*>([\s\u00a0]*)<\/span>/gi,
939 function(str, spaces) {
940 return (spaces.length > 0) ?
941 spaces.replace(/./, " ").slice(Math.floor(spaces.length / 2)).split("").join("\u00a0") : "";
946 var validElements = settings.paste_word_valid_elements;
947 if (!validElements) {
948 validElements = '-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,-p/div,' +
949 '-table[width],-tr,-td[colspan|rowspan|width],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br,del';
952 // Setup strict schema
953 var schema = new Schema({
954 valid_elements: validElements,
955 valid_children: '-li[p]'
958 // Add style/class attribute to all element rules since the user might have removed them from
959 // paste_word_valid_elements config option and we need to check them for properties
960 Tools.each(schema.elements, function(rule) {
961 if (!rule.attributes["class"]) {
962 rule.attributes["class"] = {};
963 rule.attributesOrder.push("class");
966 if (!rule.attributes.style) {
967 rule.attributes.style = {};
968 rule.attributesOrder.push("style");
972 // Parse HTML into DOM structure
973 var domParser = new DomParser({}, schema);
975 // Filter styles to remove "mso" specific styles and convert some of them
976 domParser.addAttributeFilter('style', function(nodes) {
977 var i = nodes.length, node;
981 node.attr('style', filterStyles(node, node.attr('style')));
983 // Remove pointess spans
984 if (node.name == 'span' && node.parent && !node.attributes.length) {
990 // Check the class attribute for comments or del items and remove those
991 domParser.addAttributeFilter('class', function(nodes) {
992 var i = nodes.length, node, className;
997 className = node.attr('class');
998 if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
1002 node.attr('class', null);
1006 // Remove all del elements since we don't want the track changes code in the editor
1007 domParser.addNodeFilter('del', function(nodes) {
1008 var i = nodes.length;
1015 // Keep some of the links and anchors
1016 domParser.addNodeFilter('a', function(nodes) {
1017 var i = nodes.length, node, href, name;
1021 href = node.attr('href');
1022 name = node.attr('name');
1024 if (href && href.indexOf('#_msocom_') != -1) {
1029 if (href && href.indexOf('file://') === 0) {
1030 href = href.split('#')[1];
1036 if (!href && !name) {
1039 if (name && name.indexOf('Toc') !== 0) {
1052 // Parse into DOM structure
1053 var rootNode = domParser.parse(content);
1056 convertFakeListsToProperLists(rootNode);
1058 // Serialize DOM back to HTML
1059 e.content = new Serializer({}, schema).serialize(rootNode);
1064 WordFilter.isWordContent = isWordContent;
1069 // Included from: js/tinymce/plugins/paste/classes/Quirks.js
1074 * Copyright, Moxiecode Systems AB
1075 * Released under LGPL License.
1077 * License: http://www.tinymce.com/license
1078 * Contributing: http://www.tinymce.com/contributing
1082 * This class contains various fixes for browsers. These issues can not be feature
1083 * detected since we have no direct control over the clipboard. However we might be able
1084 * to remove some of these fixes once the browsers gets updated/fixed.
1086 * @class tinymce.pasteplugin.Quirks
1089 define("tinymce/pasteplugin/Quirks", [
1091 "tinymce/util/Tools",
1092 "tinymce/pasteplugin/WordFilter",
1093 "tinymce/pasteplugin/Utils"
1094 ], function(Env, Tools, WordFilter, Utils) {
1097 return function(editor) {
1098 function addPreProcessFilter(filterFunc) {
1099 editor.on('BeforePastePreProcess', function(e) {
1100 e.content = filterFunc(e.content);
1105 * Removes WebKit fragment comments and converted-space spans.
1108 * <!--StartFragment-->a<span class="Apple-converted-space"> </span>b<!--EndFragment-->
1113 function removeWebKitFragments(html) {
1114 html = Utils.filter(html, [
1115 /^[\s\S]*<!--StartFragment-->|<!--EndFragment-->[\s\S]*$/g, // WebKit fragment
1116 [/<span class="Apple-converted-space">\u00a0<\/span>/g, '\u00a0'], // WebKit
1117 /<br>$/i // Traling BR elements
1124 * Removes BR elements after block elements. IE9 has a nasty bug where it puts a BR element after each
1125 * block element when pasting from word. This removes those elements.
1128 * <p>a</p><br><p>b</p>
1133 function removeExplorerBrElementsAfterBlocks(html) {
1134 // Only filter word specific content
1135 if (!WordFilter.isWordContent(html)) {
1139 // Produce block regexp based on the block elements in schema
1140 var blockElements = [];
1142 Tools.each(editor.schema.getBlockElements(), function(block, blockName) {
1143 blockElements.push(blockName);
1146 var explorerBlocksRegExp = new RegExp(
1147 '(?:<br> [\\s\\r\\n]+|<br>)*(<\\/?(' + blockElements.join('|') + ')[^>]*>)(?:<br> [\\s\\r\\n]+|<br>)*',
1151 // Remove BR:s from: <BLOCK>X</BLOCK><BR>
1152 html = Utils.filter(html, [
1153 [explorerBlocksRegExp, '$1']
1156 // IE9 also adds an extra BR element for each soft-linefeed and it also adds a BR for each word wrap break
1157 html = Utils.filter(html, [
1158 [/<br><br>/g, '<BR><BR>'], // Replace multiple BR elements with uppercase BR to keep them intact
1159 [/<br>/g, ' '], // Replace single br elements with space since they are word wrap BR:s
1160 [/<BR><BR>/g, '<br>'] // Replace back the double brs but into a single BR
1167 * WebKit has a nasty bug where the all computed styles gets added to style attributes when copy/pasting contents.
1168 * This fix solves that by simply removing the whole style attribute.
1170 * The paste_webkit_styles option can be set to specify what to keep:
1171 * paste_webkit_styles: "none" // Keep no styles
1172 * paste_webkit_styles: "all", // Keep all of them
1173 * paste_webkit_styles: "font-weight color" // Keep specific ones
1175 * @param {String} content Content that needs to be processed.
1176 * @return {String} Processed contents.
1178 function removeWebKitStyles(content) {
1179 // Passthrough all styles from Word and let the WordFilter handle that junk
1180 if (WordFilter.isWordContent(content)) {
1184 // Filter away styles that isn't matching the target node
1186 var webKitStyles = editor.getParam("paste_webkit_styles", "color font-size font-family background-color").split(/[, ]/);
1188 if (editor.settings.paste_remove_styles_if_webkit === false) {
1189 webKitStyles = "all";
1192 // Keep specific styles that doesn't match the current node computed style
1193 if (webKitStyles != "all") {
1194 var dom = editor.dom, node = editor.selection.getNode();
1196 content = content.replace(/ style=\"([^\"]+)\"/gi, function(a, value) {
1197 var inputStyles = dom.parseStyle(value, 'span'), outputStyles = {};
1199 if (webKitStyles === "none") {
1203 for (var i = 0; i < webKitStyles.length; i++) {
1204 if (dom.toHex(dom.getStyle(node, webKitStyles[i], true)) != inputStyles[webKitStyles[i]]) {
1205 outputStyles[webKitStyles[i]] = inputStyles[webKitStyles[i]];
1209 outputStyles = dom.serializeStyle(outputStyles, 'span');
1211 return ' style="' + outputStyles + '"';
1221 // Sniff browsers and apply fixes since we can't feature detect
1223 addPreProcessFilter(removeWebKitStyles);
1224 addPreProcessFilter(removeWebKitFragments);
1228 addPreProcessFilter(removeExplorerBrElementsAfterBlocks);
1233 // Included from: js/tinymce/plugins/paste/classes/Plugin.js
1238 * Copyright, Moxiecode Systems AB
1239 * Released under LGPL License.
1241 * License: http://www.tinymce.com/license
1242 * Contributing: http://www.tinymce.com/contributing
1246 * This class contains the tinymce plugin logic for the paste plugin.
1248 * @class tinymce.pasteplugin.Plugin
1251 define("tinymce/pasteplugin/Plugin", [
1252 "tinymce/PluginManager",
1253 "tinymce/pasteplugin/Clipboard",
1254 "tinymce/pasteplugin/WordFilter",
1255 "tinymce/pasteplugin/Quirks"
1256 ], function(PluginManager, Clipboard, WordFilter, Quirks) {
1259 PluginManager.add('paste', function(editor) {
1260 var self = this, clipboard, settings = editor.settings;
1262 function togglePlainTextPaste() {
1263 if (clipboard.pasteFormat == "text") {
1265 clipboard.pasteFormat = "html";
1267 clipboard.pasteFormat = "text";
1270 if (!userIsInformed) {
1271 editor.windowManager.alert(
1272 'Paste is now in plain text mode. Contents will now ' +
1273 'be pasted as plain text until you toggle this option off.'
1276 userIsInformed = true;
1281 self.clipboard = clipboard = new Clipboard(editor);
1282 self.quirks = new Quirks(editor);
1283 self.wordFilter = new WordFilter(editor);
1285 if (editor.settings.paste_as_text) {
1286 self.clipboard.pasteFormat = "text";
1289 if (settings.paste_preprocess) {
1290 editor.on('PastePreProcess', function(e) {
1291 settings.paste_preprocess.call(self, self, e);
1295 if (settings.paste_postprocess) {
1296 editor.on('PastePostProcess', function(e) {
1297 settings.paste_postprocess.call(self, self, e);
1301 editor.addCommand('mceInsertClipboardContent', function(ui, value) {
1302 if (value.content) {
1303 self.clipboard.pasteHtml(value.content);
1307 self.clipboard.pasteText(value.text);
1311 // Block all drag/drop events
1312 if (editor.paste_block_drop) {
1313 editor.on('dragend dragover draggesture dragdrop drop drag', function(e) {
1315 e.stopPropagation();
1319 // Prevent users from dropping data images on Gecko
1320 if (!editor.settings.paste_data_images) {
1321 editor.on('drop', function(e) {
1322 var dataTransfer = e.dataTransfer;
1324 if (dataTransfer && dataTransfer.files && dataTransfer.files.length > 0) {
1330 editor.addButton('pastetext', {
1332 tooltip: 'Paste as text',
1333 onclick: togglePlainTextPaste,
1334 active: self.clipboard.pasteFormat == "text"
1337 editor.addMenuItem('pastetext', {
1338 text: 'Paste as text',
1340 active: clipboard.pasteFormat,
1341 onclick: togglePlainTextPaste
1346 expose(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/Clipboard","tinymce/pasteplugin/WordFilter","tinymce/pasteplugin/Quirks","tinymce/pasteplugin/Plugin"]);