src/pyams_skin/resources/js/ext/tinymce/dev/plugins/paste/classes/Clipboard.js
changeset 557 bca7a7e058a3
equal deleted inserted replaced
-1:000000000000 557:bca7a7e058a3
       
     1 /**
       
     2  * Clipboard.js
       
     3  *
       
     4  * Copyright, Moxiecode Systems AB
       
     5  * Released under LGPL License.
       
     6  *
       
     7  * License: http://www.tinymce.com/license
       
     8  * Contributing: http://www.tinymce.com/contributing
       
     9  */
       
    10 
       
    11 /**
       
    12  * This class contains logic for getting HTML contents out of the clipboard.
       
    13  *
       
    14  * We need to make a lot of ugly hacks to get the contents out of the clipboard since
       
    15  * the W3C Clipboard API is broken in all browsers that have it: Gecko/WebKit/Blink.
       
    16  * We might rewrite this the way those API:s stabilize. Browsers doesn't handle pasting
       
    17  * from applications like Word the same way as it does when pasting into a contentEditable area
       
    18  * so we need to do lots of extra work to try to get to this clipboard data.
       
    19  *
       
    20  * Current implementation steps:
       
    21  *  1. On keydown with paste keys Ctrl+V or Shift+Insert create
       
    22  *     a paste bin element and move focus to that element.
       
    23  *  2. Wait for the browser to fire a "paste" event and get the contents out of the paste bin.
       
    24  *  3. Check if the paste was successful if true, process the HTML.
       
    25  *  (4). If the paste was unsuccessful use IE execCommand, Clipboard API, document.dataTransfer old WebKit API etc.
       
    26  *
       
    27  * @class tinymce.pasteplugin.Clipboard
       
    28  * @private
       
    29  */
       
    30 define("tinymce/pasteplugin/Clipboard", [
       
    31 	"tinymce/Env",
       
    32 	"tinymce/dom/RangeUtils",
       
    33 	"tinymce/util/VK",
       
    34 	"tinymce/pasteplugin/Utils"
       
    35 ], function(Env, RangeUtils, VK, Utils) {
       
    36 	return function(editor) {
       
    37 		var self = this, pasteBinElm, lastRng, keyboardPasteTimeStamp = 0, draggingInternally = false;
       
    38 		var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
       
    39 		var mceInternalUrlPrefix = 'data:text/mce-internal,';
       
    40 
       
    41 		/**
       
    42 		 * Pastes the specified HTML. This means that the HTML is filtered and then
       
    43 		 * inserted at the current selection in the editor. It will also fire paste events
       
    44 		 * for custom user filtering.
       
    45 		 *
       
    46 		 * @param {String} html HTML code to paste into the current selection.
       
    47 		 */
       
    48 		function pasteHtml(html) {
       
    49 			var args, dom = editor.dom;
       
    50 
       
    51 			args = editor.fire('BeforePastePreProcess', {content: html}); // Internal event used by Quirks
       
    52 			args = editor.fire('PastePreProcess', args);
       
    53 			html = args.content;
       
    54 
       
    55 			if (!args.isDefaultPrevented()) {
       
    56 				// User has bound PastePostProcess events then we need to pass it through a DOM node
       
    57 				// This is not ideal but we don't want to let the browser mess up the HTML for example
       
    58 				// some browsers add   to P tags etc
       
    59 				if (editor.hasEventListeners('PastePostProcess') && !args.isDefaultPrevented()) {
       
    60 					// We need to attach the element to the DOM so Sizzle selectors work on the contents
       
    61 					var tempBody = dom.add(editor.getBody(), 'div', {style: 'display:none'}, html);
       
    62 					args = editor.fire('PastePostProcess', {node: tempBody});
       
    63 					dom.remove(tempBody);
       
    64 					html = args.node.innerHTML;
       
    65 				}
       
    66 
       
    67 				if (!args.isDefaultPrevented()) {
       
    68 					editor.insertContent(html, {merge: editor.settings.paste_merge_formats !== false});
       
    69 				}
       
    70 			}
       
    71 		}
       
    72 
       
    73 		/**
       
    74 		 * Pastes the specified text. This means that the plain text is processed
       
    75 		 * and converted into BR and P elements. It will fire paste events for custom filtering.
       
    76 		 *
       
    77 		 * @param {String} text Text to paste as the current selection location.
       
    78 		 */
       
    79 		function pasteText(text) {
       
    80 			text = editor.dom.encode(text).replace(/\r\n/g, '\n');
       
    81 
       
    82 			var startBlock = editor.dom.getParent(editor.selection.getStart(), editor.dom.isBlock);
       
    83 
       
    84 			// Create start block html for example <p attr="value">
       
    85 			var forcedRootBlockName = editor.settings.forced_root_block;
       
    86 			var forcedRootBlockStartHtml;
       
    87 			if (forcedRootBlockName) {
       
    88 				forcedRootBlockStartHtml = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs);
       
    89 				forcedRootBlockStartHtml = forcedRootBlockStartHtml.substr(0, forcedRootBlockStartHtml.length - 3) + '>';
       
    90 			}
       
    91 
       
    92 			if ((startBlock && /^(PRE|DIV)$/.test(startBlock.nodeName)) || !forcedRootBlockName) {
       
    93 				text = Utils.filter(text, [
       
    94 					[/\n/g, "<br>"]
       
    95 				]);
       
    96 			} else {
       
    97 				text = Utils.filter(text, [
       
    98 					[/\n\n/g, "</p>" + forcedRootBlockStartHtml],
       
    99 					[/^(.*<\/p>)(<p>)$/, forcedRootBlockStartHtml + '$1'],
       
   100 					[/\n/g, "<br />"]
       
   101 				]);
       
   102 
       
   103 				if (text.indexOf('<p>') != -1) {
       
   104 					text = forcedRootBlockStartHtml + text;
       
   105 				}
       
   106 			}
       
   107 
       
   108 			pasteHtml(text);
       
   109 		}
       
   110 
       
   111 		/**
       
   112 		 * Creates a paste bin element as close as possible to the current caret location and places the focus inside that element
       
   113 		 * so that when the real paste event occurs the contents gets inserted into this element
       
   114 		 * instead of the current editor selection element.
       
   115 		 */
       
   116 		function createPasteBin() {
       
   117 			var dom = editor.dom, body = editor.getBody();
       
   118 			var viewport = editor.dom.getViewPort(editor.getWin()), scrollTop = viewport.y, top = 20;
       
   119 			var scrollContainer;
       
   120 
       
   121 			lastRng = editor.selection.getRng();
       
   122 
       
   123 			if (editor.inline) {
       
   124 				scrollContainer = editor.selection.getScrollContainer();
       
   125 
       
   126 				// Can't always rely on scrollTop returning a useful value.
       
   127 				// It returns 0 if the browser doesn't support scrollTop for the element or is non-scrollable
       
   128 				if (scrollContainer && scrollContainer.scrollTop > 0) {
       
   129 					scrollTop = scrollContainer.scrollTop;
       
   130 				}
       
   131 			}
       
   132 
       
   133 			/**
       
   134 			 * Returns the rect of the current caret if the caret is in an empty block before a
       
   135 			 * BR we insert a temporary invisible character that we get the rect this way we always get a proper rect.
       
   136 			 *
       
   137 			 * TODO: This might be useful in core.
       
   138 			 */
       
   139 			function getCaretRect(rng) {
       
   140 				var rects, textNode, node, container = rng.startContainer;
       
   141 
       
   142 				rects = rng.getClientRects();
       
   143 				if (rects.length) {
       
   144 					return rects[0];
       
   145 				}
       
   146 
       
   147 				if (!rng.collapsed || container.nodeType != 1) {
       
   148 					return;
       
   149 				}
       
   150 
       
   151 				node = container.childNodes[lastRng.startOffset];
       
   152 
       
   153 				// Skip empty whitespace nodes
       
   154 				while (node && node.nodeType == 3 && !node.data.length) {
       
   155 					node = node.nextSibling;
       
   156 				}
       
   157 
       
   158 				if (!node) {
       
   159 					return;
       
   160 				}
       
   161 
       
   162 				// Check if the location is |<br>
       
   163 				// TODO: Might need to expand this to say |<table>
       
   164 				if (node.tagName == 'BR') {
       
   165 					textNode = dom.doc.createTextNode('\uFEFF');
       
   166 					node.parentNode.insertBefore(textNode, node);
       
   167 
       
   168 					rng = dom.createRng();
       
   169 					rng.setStartBefore(textNode);
       
   170 					rng.setEndAfter(textNode);
       
   171 
       
   172 					rects = rng.getClientRects();
       
   173 					dom.remove(textNode);
       
   174 				}
       
   175 
       
   176 				if (rects.length) {
       
   177 					return rects[0];
       
   178 				}
       
   179 			}
       
   180 
       
   181 			// Calculate top cordinate this is needed to avoid scrolling to top of document
       
   182 			// We want the paste bin to be as close to the caret as possible to avoid scrolling
       
   183 			if (lastRng.getClientRects) {
       
   184 				var rect = getCaretRect(lastRng);
       
   185 
       
   186 				if (rect) {
       
   187 					// Client rects gets us closes to the actual
       
   188 					// caret location in for example a wrapped paragraph block
       
   189 					top = scrollTop + (rect.top - dom.getPos(body).y);
       
   190 				} else {
       
   191 					top = scrollTop;
       
   192 
       
   193 					// Check if we can find a closer location by checking the range element
       
   194 					var container = lastRng.startContainer;
       
   195 					if (container) {
       
   196 						if (container.nodeType == 3 && container.parentNode != body) {
       
   197 							container = container.parentNode;
       
   198 						}
       
   199 
       
   200 						if (container.nodeType == 1) {
       
   201 							top = dom.getPos(container, scrollContainer || body).y;
       
   202 						}
       
   203 					}
       
   204 				}
       
   205 			}
       
   206 
       
   207 			// Create a pastebin
       
   208 			pasteBinElm = dom.add(editor.getBody(), 'div', {
       
   209 				id: "mcepastebin",
       
   210 				contentEditable: true,
       
   211 				"data-mce-bogus": "all",
       
   212 				style: 'position: absolute; top: ' + top + 'px;' +
       
   213 					'width: 10px; height: 10px; overflow: hidden; opacity: 0'
       
   214 			}, pasteBinDefaultContent);
       
   215 
       
   216 			// Move paste bin out of sight since the controlSelection rect gets displayed otherwise on IE and Gecko
       
   217 			if (Env.ie || Env.gecko) {
       
   218 				dom.setStyle(pasteBinElm, 'left', dom.getStyle(body, 'direction', true) == 'rtl' ? 0xFFFF : -0xFFFF);
       
   219 			}
       
   220 
       
   221 			// Prevent focus events from bubbeling fixed FocusManager issues
       
   222 			dom.bind(pasteBinElm, 'beforedeactivate focusin focusout', function(e) {
       
   223 				e.stopPropagation();
       
   224 			});
       
   225 
       
   226 			pasteBinElm.focus();
       
   227 			editor.selection.select(pasteBinElm, true);
       
   228 		}
       
   229 
       
   230 		/**
       
   231 		 * Removes the paste bin if it exists.
       
   232 		 */
       
   233 		function removePasteBin() {
       
   234 			if (pasteBinElm) {
       
   235 				var pasteBinClone;
       
   236 
       
   237 				// WebKit/Blink might clone the div so
       
   238 				// lets make sure we remove all clones
       
   239 				// TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
       
   240 				while ((pasteBinClone = editor.dom.get('mcepastebin'))) {
       
   241 					editor.dom.remove(pasteBinClone);
       
   242 					editor.dom.unbind(pasteBinClone);
       
   243 				}
       
   244 
       
   245 				if (lastRng) {
       
   246 					editor.selection.setRng(lastRng);
       
   247 				}
       
   248 			}
       
   249 
       
   250 			pasteBinElm = lastRng = null;
       
   251 		}
       
   252 
       
   253 		/**
       
   254 		 * Returns the contents of the paste bin as a HTML string.
       
   255 		 *
       
   256 		 * @return {String} Get the contents of the paste bin.
       
   257 		 */
       
   258 		function getPasteBinHtml() {
       
   259 			var html = '', pasteBinClones, i, clone, cloneHtml;
       
   260 
       
   261 			// Since WebKit/Chrome might clone the paste bin when pasting
       
   262 			// for example: <img style="float: right"> we need to check if any of them contains some useful html.
       
   263 			// TODO: Man o man is this ugly. WebKit is the new IE! Remove this if they ever fix it!
       
   264 			pasteBinClones = editor.dom.select('div[id=mcepastebin]');
       
   265 			for (i = 0; i < pasteBinClones.length; i++) {
       
   266 				clone = pasteBinClones[i];
       
   267 
       
   268 				// Pasting plain text produces pastebins in pastebinds makes sence right!?
       
   269 				if (clone.firstChild && clone.firstChild.id == 'mcepastebin') {
       
   270 					clone = clone.firstChild;
       
   271 				}
       
   272 
       
   273 				cloneHtml = clone.innerHTML;
       
   274 				if (html != pasteBinDefaultContent) {
       
   275 					html += cloneHtml;
       
   276 				}
       
   277 			}
       
   278 
       
   279 			return html;
       
   280 		}
       
   281 
       
   282 		/**
       
   283 		 * Gets various content types out of a datatransfer object.
       
   284 		 *
       
   285 		 * @param {DataTransfer} dataTransfer Event fired on paste.
       
   286 		 * @return {Object} Object with mime types and data for those mime types.
       
   287 		 */
       
   288 		function getDataTransferItems(dataTransfer) {
       
   289 			var data = {};
       
   290 
       
   291 			if (dataTransfer) {
       
   292 				// Use old WebKit/IE API
       
   293 				if (dataTransfer.getData) {
       
   294 					var legacyText = dataTransfer.getData('Text');
       
   295 					if (legacyText && legacyText.length > 0) {
       
   296 						if (legacyText.indexOf(mceInternalUrlPrefix) == -1) {
       
   297 							data['text/plain'] = legacyText;
       
   298 						}
       
   299 					}
       
   300 				}
       
   301 
       
   302 				if (dataTransfer.types) {
       
   303 					for (var i = 0; i < dataTransfer.types.length; i++) {
       
   304 						var contentType = dataTransfer.types[i];
       
   305 						data[contentType] = dataTransfer.getData(contentType);
       
   306 					}
       
   307 				}
       
   308 			}
       
   309 
       
   310 			return data;
       
   311 		}
       
   312 
       
   313 		/**
       
   314 		 * Gets various content types out of the Clipboard API. It will also get the
       
   315 		 * plain text using older IE and WebKit API:s.
       
   316 		 *
       
   317 		 * @param {ClipboardEvent} clipboardEvent Event fired on paste.
       
   318 		 * @return {Object} Object with mime types and data for those mime types.
       
   319 		 */
       
   320 		function getClipboardContent(clipboardEvent) {
       
   321 			return getDataTransferItems(clipboardEvent.clipboardData || editor.getDoc().dataTransfer);
       
   322 		}
       
   323 
       
   324 		/**
       
   325 		 * Checks if the clipboard contains image data if it does it will take that data
       
   326 		 * and convert it into a data url image and paste that image at the caret location.
       
   327 		 *
       
   328 		 * @param  {ClipboardEvent} e Paste/drop event object.
       
   329 		 * @param  {DOMRange} rng Optional rng object to move selection to.
       
   330 		 * @return {Boolean} true/false if the image data was found or not.
       
   331 		 */
       
   332 		function pasteImageData(e, rng) {
       
   333 			var dataTransfer = e.clipboardData || e.dataTransfer;
       
   334 
       
   335 			function processItems(items) {
       
   336 				var i, item, reader, hadImage = false;
       
   337 
       
   338 				function pasteImage(reader) {
       
   339 					if (rng) {
       
   340 						editor.selection.setRng(rng);
       
   341 						rng = null;
       
   342 					}
       
   343 
       
   344 					pasteHtml('<img src="' + reader.result + '">');
       
   345 				}
       
   346 
       
   347 				if (items) {
       
   348 					for (i = 0; i < items.length; i++) {
       
   349 						item = items[i];
       
   350 
       
   351 						if (/^image\/(jpeg|png|gif|bmp)$/.test(item.type)) {
       
   352 							reader = new FileReader();
       
   353 							reader.onload = pasteImage.bind(null, reader);
       
   354 							reader.readAsDataURL(item.getAsFile ? item.getAsFile() : item);
       
   355 
       
   356 							e.preventDefault();
       
   357 							hadImage = true;
       
   358 						}
       
   359 					}
       
   360 				}
       
   361 
       
   362 				return hadImage;
       
   363 			}
       
   364 
       
   365 			if (editor.settings.paste_data_images && dataTransfer) {
       
   366 				return processItems(dataTransfer.items) || processItems(dataTransfer.files);
       
   367 			}
       
   368 		}
       
   369 
       
   370 		/**
       
   371 		 * Chrome on Android doesn't support proper clipboard access so we have no choice but to allow the browser default behavior.
       
   372 		 *
       
   373 		 * @param {Event} e Paste event object to check if it contains any data.
       
   374 		 * @return {Boolean} true/false if the clipboard is empty or not.
       
   375 		 */
       
   376 		function isBrokenAndroidClipboardEvent(e) {
       
   377 			var clipboardData = e.clipboardData;
       
   378 
       
   379 			return navigator.userAgent.indexOf('Android') != -1 && clipboardData && clipboardData.items && clipboardData.items.length === 0;
       
   380 		}
       
   381 
       
   382 		function getCaretRangeFromEvent(e) {
       
   383 			return RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc());
       
   384 		}
       
   385 
       
   386 		function hasContentType(clipboardContent, mimeType) {
       
   387 			return mimeType in clipboardContent && clipboardContent[mimeType].length > 0;
       
   388 		}
       
   389 
       
   390 		function isKeyboardPasteEvent(e) {
       
   391 			return (VK.metaKeyPressed(e) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45);
       
   392 		}
       
   393 
       
   394 		function registerEventHandlers() {
       
   395 			editor.on('keydown', function(e) {
       
   396 				function removePasteBinOnKeyUp(e) {
       
   397 					// Ctrl+V or Shift+Insert
       
   398 					if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
       
   399 						removePasteBin();
       
   400 					}
       
   401 				}
       
   402 
       
   403 				// Ctrl+V or Shift+Insert
       
   404 				if (isKeyboardPasteEvent(e) && !e.isDefaultPrevented()) {
       
   405 					keyboardPastePlainTextState = e.shiftKey && e.keyCode == 86;
       
   406 
       
   407 					// Edge case on Safari on Mac where it doesn't handle Cmd+Shift+V correctly
       
   408 					// it fires the keydown but no paste or keyup so we are left with a paste bin
       
   409 					if (keyboardPastePlainTextState && Env.webkit && navigator.userAgent.indexOf('Version/') != -1) {
       
   410 						return;
       
   411 					}
       
   412 
       
   413 					// Prevent undoManager keydown handler from making an undo level with the pastebin in it
       
   414 					e.stopImmediatePropagation();
       
   415 
       
   416 					keyboardPasteTimeStamp = new Date().getTime();
       
   417 
       
   418 					// IE doesn't support Ctrl+Shift+V and it doesn't even produce a paste event
       
   419 					// so lets fake a paste event and let IE use the execCommand/dataTransfer methods
       
   420 					if (Env.ie && keyboardPastePlainTextState) {
       
   421 						e.preventDefault();
       
   422 						editor.fire('paste', {ieFake: true});
       
   423 						return;
       
   424 					}
       
   425 
       
   426 					removePasteBin();
       
   427 					createPasteBin();
       
   428 
       
   429 					// Remove pastebin if we get a keyup and no paste event
       
   430 					// For example pasting a file in IE 11 will not produce a paste event
       
   431 					editor.once('keyup', removePasteBinOnKeyUp);
       
   432 					editor.once('paste', function() {
       
   433 						editor.off('keyup', removePasteBinOnKeyUp);
       
   434 					});
       
   435 				}
       
   436 			});
       
   437 
       
   438 			editor.on('paste', function(e) {
       
   439 				// Getting content from the Clipboard can take some time
       
   440 				var clipboardTimer = new Date().getTime();
       
   441 				var clipboardContent = getClipboardContent(e);
       
   442 				var clipboardDelay = new Date().getTime() - clipboardTimer;
       
   443 
       
   444 				var isKeyBoardPaste = (new Date().getTime() - keyboardPasteTimeStamp - clipboardDelay) < 1000;
       
   445 				var plainTextMode = self.pasteFormat == "text" || keyboardPastePlainTextState;
       
   446 
       
   447 				keyboardPastePlainTextState = false;
       
   448 
       
   449 				if (e.isDefaultPrevented() || isBrokenAndroidClipboardEvent(e)) {
       
   450 					removePasteBin();
       
   451 					return;
       
   452 				}
       
   453 
       
   454 				if (pasteImageData(e)) {
       
   455 					removePasteBin();
       
   456 					return;
       
   457 				}
       
   458 
       
   459 				// Not a keyboard paste prevent default paste and try to grab the clipboard contents using different APIs
       
   460 				if (!isKeyBoardPaste) {
       
   461 					e.preventDefault();
       
   462 				}
       
   463 
       
   464 				// Try IE only method if paste isn't a keyboard paste
       
   465 				if (Env.ie && (!isKeyBoardPaste || e.ieFake)) {
       
   466 					createPasteBin();
       
   467 
       
   468 					editor.dom.bind(pasteBinElm, 'paste', function(e) {
       
   469 						e.stopPropagation();
       
   470 					});
       
   471 
       
   472 					editor.getDoc().execCommand('Paste', false, null);
       
   473 					clipboardContent["text/html"] = getPasteBinHtml();
       
   474 				}
       
   475 
       
   476 				setTimeout(function() {
       
   477 					var content;
       
   478 
       
   479 					// Grab HTML from Clipboard API or paste bin as a fallback
       
   480 					if (hasContentType(clipboardContent, 'text/html')) {
       
   481 						content = clipboardContent['text/html'];
       
   482 					} else {
       
   483 						content = getPasteBinHtml();
       
   484 
       
   485 						// If paste bin is empty try using plain text mode
       
   486 						// since that is better than nothing right
       
   487 						if (content == pasteBinDefaultContent) {
       
   488 							plainTextMode = true;
       
   489 						}
       
   490 					}
       
   491 
       
   492 					content = Utils.trimHtml(content);
       
   493 
       
   494 					// WebKit has a nice bug where it clones the paste bin if you paste from for example notepad
       
   495 					// so we need to force plain text mode in this case
       
   496 					if (pasteBinElm && pasteBinElm.firstChild && pasteBinElm.firstChild.id === 'mcepastebin') {
       
   497 						plainTextMode = true;
       
   498 					}
       
   499 
       
   500 					removePasteBin();
       
   501 
       
   502 					// If we got nothing from clipboard API and pastebin then we could try the last resort: plain/text
       
   503 					if (!content.length) {
       
   504 						plainTextMode = true;
       
   505 					}
       
   506 
       
   507 					// Grab plain text from Clipboard API or convert existing HTML to plain text
       
   508 					if (plainTextMode) {
       
   509 						// Use plain text contents from Clipboard API unless the HTML contains paragraphs then
       
   510 						// we should convert the HTML to plain text since works better when pasting HTML/Word contents as plain text
       
   511 						if (hasContentType(clipboardContent, 'text/plain') && content.indexOf('</p>') == -1) {
       
   512 							content = clipboardContent['text/plain'];
       
   513 						} else {
       
   514 							content = Utils.innerText(content);
       
   515 						}
       
   516 					}
       
   517 
       
   518 					// If the content is the paste bin default HTML then it was
       
   519 					// impossible to get the cliboard data out.
       
   520 					if (content == pasteBinDefaultContent) {
       
   521 						if (!isKeyBoardPaste) {
       
   522 							editor.windowManager.alert('Please use Ctrl+V/Cmd+V keyboard shortcuts to paste contents.');
       
   523 						}
       
   524 
       
   525 						return;
       
   526 					}
       
   527 
       
   528 					if (plainTextMode) {
       
   529 						pasteText(content);
       
   530 					} else {
       
   531 						pasteHtml(content);
       
   532 					}
       
   533 				}, 0);
       
   534 			});
       
   535 
       
   536 			editor.on('dragstart dragend', function(e) {
       
   537 				draggingInternally = e.type == 'dragstart';
       
   538 			});
       
   539 
       
   540 			editor.on('drop', function(e) {
       
   541 				var rng = getCaretRangeFromEvent(e);
       
   542 
       
   543 				if (e.isDefaultPrevented() || draggingInternally) {
       
   544 					return;
       
   545 				}
       
   546 
       
   547 				if (pasteImageData(e, rng)) {
       
   548 					return;
       
   549 				}
       
   550 
       
   551 				if (rng && editor.settings.paste_filter_drop !== false) {
       
   552 					var dropContent = getDataTransferItems(e.dataTransfer);
       
   553 					var content = dropContent['mce-internal'] || dropContent['text/html'] || dropContent['text/plain'];
       
   554 
       
   555 					if (content) {
       
   556 						e.preventDefault();
       
   557 
       
   558 						editor.undoManager.transact(function() {
       
   559 							if (dropContent['mce-internal']) {
       
   560 								editor.execCommand('Delete');
       
   561 							}
       
   562 
       
   563 							editor.selection.setRng(rng);
       
   564 
       
   565 							content = Utils.trimHtml(content);
       
   566 
       
   567 							if (!dropContent['text/html']) {
       
   568 								pasteText(content);
       
   569 							} else {
       
   570 								pasteHtml(content);
       
   571 							}
       
   572 						});
       
   573 					}
       
   574 				}
       
   575 			});
       
   576 
       
   577 			editor.on('dragover dragend', function(e) {
       
   578 				if (editor.settings.paste_data_images) {
       
   579 					e.preventDefault();
       
   580 				}
       
   581 			});
       
   582 		}
       
   583 
       
   584 		self.pasteHtml = pasteHtml;
       
   585 		self.pasteText = pasteText;
       
   586 
       
   587 		editor.on('preInit', function() {
       
   588 			registerEventHandlers();
       
   589 
       
   590 			// Remove all data images from paste for example from Gecko
       
   591 			// except internal images like video elements
       
   592 			editor.parser.addNodeFilter('img', function(nodes) {
       
   593 				if (!editor.settings.paste_data_images) {
       
   594 					var i = nodes.length;
       
   595 
       
   596 					while (i--) {
       
   597 						var src = nodes[i].attributes.map.src;
       
   598 
       
   599 						// Some browsers automatically produce data uris on paste
       
   600 						// Safari on Mac produces webkit-fake-url see: https://bugs.webkit.org/show_bug.cgi?id=49141
       
   601 						if (src && /^(data:image|webkit\-fake\-url)/.test(src)) {
       
   602 							if (!nodes[i].attr('data-mce-object') && src !== Env.transparentSrc) {
       
   603 								nodes[i].remove();
       
   604 							}
       
   605 						}
       
   606 					}
       
   607 				}
       
   608 			});
       
   609 		});
       
   610 	};
       
   611 });