/**
* This class contails various utility functions for the paste plugin.
*
- * @class tinymce.pasteplugin.Clipboard
- * @private
+ * @class tinymce.pasteplugin.Utils
*/
define("tinymce/pasteplugin/Utils", [
"tinymce/util/Tools",
*/
define("tinymce/pasteplugin/Clipboard", [
"tinymce/Env",
+ "tinymce/dom/RangeUtils",
"tinymce/util/VK",
"tinymce/pasteplugin/Utils"
-], function(Env, VK, Utils) {
+], function(Env, RangeUtils, VK, Utils) {
return function(editor) {
var self = this, pasteBinElm, lastRng, keyboardPasteTimeStamp = 0, draggingInternally = false;
var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
+ var mceInternalUrlPrefix = 'data:text/mce-internal,';
/**
* Pastes the specified HTML. This means that the HTML is filtered and then
if (dataTransfer.getData) {
var legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
- data['text/plain'] = legacyText;
+ if (legacyText.indexOf(mceInternalUrlPrefix) == -1) {
+ data['text/plain'] = legacyText;
+ }
}
}
var dataTransfer = e.clipboardData || e.dataTransfer;
function processItems(items) {
- var i, item, reader;
+ var i, item, reader, hadImage = false;
- function pasteImage() {
+ function pasteImage(reader) {
if (rng) {
editor.selection.setRng(rng);
rng = null;
for (i = 0; i < items.length; i++) {
item = items[i];
- if (/^image\/(jpeg|png|gif)$/.test(item.type)) {
+ if (/^image\/(jpeg|png|gif|bmp)$/.test(item.type)) {
reader = new FileReader();
- reader.onload = pasteImage;
+ reader.onload = pasteImage.bind(null, reader);
reader.readAsDataURL(item.getAsFile ? item.getAsFile() : item);
e.preventDefault();
- return true;
+ hadImage = true;
}
}
}
+
+ return hadImage;
}
if (editor.settings.paste_data_images && dataTransfer) {
}
function getCaretRangeFromEvent(e) {
- var doc = editor.getDoc(), rng, point;
-
- if (doc.caretPositionFromPoint) {
- point = doc.caretPositionFromPoint(e.clientX, e.clientY);
- rng = doc.createRange();
- rng.setStart(point.offsetNode, point.offset);
- rng.collapse(true);
- } else if (doc.caretRangeFromPoint) {
- rng = doc.caretRangeFromPoint(e.clientX, e.clientY);
- } else if (doc.body.createTextRange) {
- rng = doc.body.createTextRange();
-
- try {
- rng.moveToPoint(e.clientX, e.clientY);
- rng.collapse(true);
- } catch (ex) {
- // Append to top or bottom depending on drop location
- rng.collapse(e.clientY < doc.body.clientHeight);
- }
- }
-
- return rng;
+ return RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
}
function hasContentType(clipboardContent, mimeType) {
});
editor.on('dragover dragend', function(e) {
- var i, dataTransfer = e.dataTransfer;
-
- if (editor.settings.paste_data_images && dataTransfer) {
- for (i = 0; i < dataTransfer.types.length; i++) {
- // Prevent default if we have files dragged into the editor since the pasteImageData handles that
- if (dataTransfer.types[i] == "Files") {
- e.preventDefault();
- return false;
- }
- }
+ if (editor.settings.paste_data_images) {
+ e.preventDefault();
}
});
}
/**
* This class parses word HTML into proper TinyMCE markup.
*
- * @class tinymce.pasteplugin.Quirks
+ * @class tinymce.pasteplugin.WordFilter
* @private
*/
define("tinymce/pasteplugin/WordFilter", [
}
function isBulletList(text) {
- return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u00d8\u25CF]\s*/.test(text);
+ return /^[\s\u00a0]*[\u2022\u00b7\u00a7\u25CF]\s*/.test(text);
}
function WordFilter(editor) {
editor.on('BeforePastePreProcess', function(e) {
var content = e.content, retainStyleProperties, validStyles;
+ // Remove google docs internal guid markers
+ content = content.replace(/<b[^>]+id="?docs-internal-[^>]*>/gi, '');
+ content = content.replace(/<br class="?Apple-interchange-newline"?>/gi, '');
+
retainStyleProperties = settings.paste_retain_style_properties;
if (retainStyleProperties) {
validStyles = Tools.makeMap(retainStyleProperties.split(/[, ]/));
// Remove start of list item "1. " or "· " etc
removeIgnoredNodes(paragraphNode);
trimListStart(paragraphNode, /^\u00a0+/);
- trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u00d8\u25CF]|\w+\.)/);
+ trimListStart(paragraphNode, /^\s*([\u2022\u00b7\u00a7\u25CF]|\w+\.)/);
trimListStart(paragraphNode, /^\u00a0+/);
}
// Add style/class attribute to all element rules since the user might have removed them from
// paste_word_valid_elements config option and we need to check them for properties
Tools.each(schema.elements, function(rule) {
+ /*eslint dot-notation:0*/
if (!rule.attributes["class"]) {
rule.attributes["class"] = {};
rule.attributesOrder.push("class");
node = nodes[i];
className = node.attr('class');
- if (/^(MsoCommentReference|MsoCommentText|msoDel|MsoCaption)$/i.test(className)) {
+ if (/^(MsoCommentReference|MsoCommentText|msoDel)$/i.test(className)) {
node.remove();
}
});
});
-expose(["tinymce/pasteplugin/Utils","tinymce/pasteplugin/WordFilter"]);
+expose(["tinymce/pasteplugin/Utils"]);
})(this);
\ No newline at end of file