TinyMCE: update to 4.0.18, see #24067

git-svn-id: https://develop.svn.wordpress.org/trunk@27387 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz
2014-03-04 01:56:57 +00:00
parent 4c10cb2ec5
commit e5bed6707f
38 changed files with 1730 additions and 1200 deletions
@@ -197,8 +197,10 @@ define("tinymce/pasteplugin/Utils", [
* This class contains logic for getting HTML contents out of the clipboard.
*
* We need to make a lot of ugly hacks to get the contents out of the clipboard since
* the W3C Clipboard API is broken in all browsers: Gecko/WebKit/Blink. We might rewrite
* this the way those API:s stabilize.
* the W3C Clipboard API is broken in all browsers that have it: Gecko/WebKit/Blink.
* We might rewrite this the way those API:s stabilize. Browsers doesn't handle pasting
* from applications like Word the same way as it does when pasting into a contentEditable area
* so we need to do lots of extra work to try to get to this clipboard data.
*
* Current implementation steps:
* 1. On keydown with paste keys Ctrl+V or Shift+Insert create
@@ -290,17 +292,19 @@ define("tinymce/pasteplugin/Clipboard", [
}
/**
* Creates a paste bin element and moves the selection into that element. It will also move the element offscreen
* so that resize handles doesn't get produced on IE or Drag handles or Firefox.
* Creates a paste bin element as close as possible to the current caret location and places the focus inside that element
* so that when the real paste event occurs the contents gets inserted into this element
* instead of the current editor selection element.
*/
function createPasteBin() {
var dom = editor.dom, body = editor.getBody();
var viewport = editor.dom.getViewPort(editor.getWin()), scrollTop = viewport.y, top = 20;
var scrollContainer;
lastRng = editor.selection.getRng();
if (editor.inline) {
var scrollContainer = editor.selection.getScrollContainer();
scrollContainer = editor.selection.getScrollContainer();
if (scrollContainer) {
scrollTop = scrollContainer.scrollTop;
@@ -311,8 +315,25 @@ define("tinymce/pasteplugin/Clipboard", [
// We want the paste bin to be as close to the caret as possible to avoid scrolling
if (lastRng.getClientRects) {
var rects = lastRng.getClientRects();
if (rects.length) {
// Client rects gets us closes to the actual
// caret location in for example a wrapped paragraph block
top = scrollTop + (rects[0].top - dom.getPos(body).y);
} else {
top = scrollTop;
// Check if we can find a closer location by checking the range element
var container = lastRng.startContainer;
if (container) {
if (container.nodeType == 3 && container.parentNode != body) {
container = container.parentNode;
}
if (container.nodeType == 1) {
top = dom.getPos(container, scrollContainer || body).y;
}
}
}
}
@@ -401,7 +422,11 @@ define("tinymce/pasteplugin/Clipboard", [
var data = {};
if (dataTransfer && dataTransfer.types) {
data['text/plain'] = dataTransfer.getData('Text');
// Use old WebKit API
var legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
data['text/plain'] = legacyText;
}
for (var i = 0; i < dataTransfer.types.length; i++) {
var contentType = dataTransfer.types[i];
@@ -423,16 +448,58 @@ define("tinymce/pasteplugin/Clipboard", [
return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
}
/**
* Checks if the clipboard contains image data if it does it will take that data
* and convert it into a data url image and paste that image at the caret location.
*
* @param {ClipboardEvent} e Paste event object.
* @param {Object} clipboardContent Collection of clipboard contents.
* @return {Boolean} true/false if the image data was found or not.
*/
function pasteImageData(e, clipboardContent) {
function pasteImage(item) {
if (items[i].type == 'image/png') {
var reader = new FileReader();
reader.onload = function() {
pasteHtml('<img src="' + reader.result + '">');
};
reader.readAsDataURL(item.getAsFile());
return true;
}
}
// If paste data images are disabled or there is HTML or plain text
// contents then proceed with the normal paste process
if (!editor.settings.paste_data_images || "text/html" in clipboardContent || "text/plain" in clipboardContent) {
return;
}
if (e.clipboardData) {
var items = e.clipboardData.items;
if (items) {
for (var i = 0; i < items.length; i++) {
if (pasteImage(items[i])) {
return true;
}
}
}
}
}
function getCaretRangeFromEvent(e) {
var doc = editor.getDoc(), rng;
if (doc.caretPositionFromPoint) {
var point = doc.caretPositionFromPoint(e.pageX, e.pageY);
var 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.pageX, e.pageY);
rng = doc.caretRangeFromPoint(e.clientX, e.clientY);
}
return rng;
@@ -476,6 +543,11 @@ define("tinymce/pasteplugin/Clipboard", [
return;
}
if (pasteImageData(e, clipboardContent)) {
removePasteBin();
return;
}
// Not a keyboard paste prevent default paste and try to grab the clipboard contents using different APIs
if (!isKeyBoardPaste) {
e.preventDefault();
@@ -815,7 +887,7 @@ define("tinymce/pasteplugin/WordFilter", [
var validElements = settings.paste_word_valid_elements;
if (!validElements) {
validElements = '@[style],-strong/b,-em/i,-span,-p,-ol,-ul,-li,-h1,-h2,-h3,-h4,-h5,-h6,' +
'-table,-tr,-td[colspan|rowspan],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br';
'-table[width],-tr,-td[colspan|rowspan|width],-th,-thead,-tfoot,-tbody,-a[href|name],sub,sup,strike,br';
}
// Setup strict schema
@@ -928,9 +1000,9 @@ define("tinymce/pasteplugin/Quirks", [
*/
function removeWebKitFragments(html) {
html = Utils.filter(html, [
/^[\s\S]*<!--StartFragment-->|<!--EndFragment-->[\s\S]*$/g, // WebKit fragment
/^[\s\S]*<!--StartFragment-->|<!--EndFragment-->[\s\S]*$/g, // WebKit fragment
[/<span class="Apple-converted-space">\u00a0<\/span>/g, '\u00a0'], // WebKit &nbsp;
/<br>$/ // Traling BR elements
/<br>$/ // Traling BR elements
]);
return html;
File diff suppressed because one or more lines are too long