243
// Included from: js/tinymce/plugins/paste/classes/SmartPaste.js
248
* Released under LGPL License.
249
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
251
* License: http://www.tinymce.com/license
252
* Contributing: http://www.tinymce.com/contributing
256
* Tries to be smart depending on what the user pastes if it looks like an url
257
* it will make a link out of the current selection. If it's an image url that looks
258
* like an image it will check if it's an image and insert it as an image.
260
* @class tinymce.pasteplugin.SmartPaste
263
define("tinymce/pasteplugin/SmartPaste", [
265
], function (Tools) {
266
var isAbsoluteUrl = function (url) {
267
return /^https?:\/\/[\w\?\-\/+=.&%]+$/i.test(url);
270
var isImageUrl = function (url) {
271
return isAbsoluteUrl(url) && /.(gif|jpe?g|png)$/.test(url);
274
var createImage = function (editor, url, pasteHtml) {
275
editor.undoManager.extra(function () {
276
pasteHtml(editor, url);
278
editor.insertContent('<img src="' + url + '">');
284
var createLink = function (editor, url, pasteHtml) {
285
editor.undoManager.extra(function () {
286
pasteHtml(editor, url);
288
editor.execCommand('mceInsertLink', false, url);
294
var linkSelection = function (editor, html, pasteHtml) {
295
return editor.selection.isCollapsed() === false && isAbsoluteUrl(html) ? createLink(editor, html, pasteHtml) : false;
298
var insertImage = function (editor, html, pasteHtml) {
299
return isImageUrl(html) ? createImage(editor, html, pasteHtml) : false;
302
var pasteHtml = function (editor, html) {
303
editor.insertContent(html, {
304
merge: editor.settings.paste_merge_formats !== false,
311
var smartInsertContent = function (editor, html) {
316
], function (action) {
317
return action(editor, html, pasteHtml) !== true;
321
var insertContent = function (editor, html) {
322
if (editor.settings.smart_paste === false) {
323
pasteHtml(editor, html);
325
smartInsertContent(editor, html);
330
isImageUrl: isImageUrl,
331
isAbsoluteUrl: isAbsoluteUrl,
332
insertContent: insertContent
243
336
// Included from: js/tinymce/plugins/paste/classes/Clipboard.js
276
369
"tinymce/dom/RangeUtils",
277
370
"tinymce/util/VK",
278
371
"tinymce/pasteplugin/Utils",
372
"tinymce/pasteplugin/SmartPaste",
279
373
"tinymce/util/Delay"
280
], function(Env, RangeUtils, VK, Utils, Delay) {
374
], function(Env, RangeUtils, VK, Utils, SmartPaste, Delay) {
281
375
return function(editor) {
282
376
var self = this, pasteBinElm, lastRng, keyboardPasteTimeStamp = 0, draggingInternally = false;
283
377
var pasteBinDefaultContent = '%MCEPASTEBIN%', keyboardPastePlainTextState;
571
665
return hasContentType(content, 'text/html') || hasContentType(content, 'text/plain');
668
function getBase64FromUri(uri) {
671
idx = uri.indexOf(',');
673
return uri.substr(idx + 1);
679
function isValidDataUriImage(settings, imgElm) {
680
return settings.images_dataimg_filter ? settings.images_dataimg_filter(imgElm) : true;
683
function pasteImage(rng, reader, blob) {
685
editor.selection.setRng(rng);
689
var dataUri = reader.result;
690
var base64 = getBase64FromUri(dataUri);
692
var img = new Image();
695
// TODO: Move the bulk of the cache logic to EditorUpload
696
if (isValidDataUriImage(editor.settings, img)) {
697
var blobCache = editor.editorUpload.blobCache;
698
var blobInfo, existingBlobInfo;
700
existingBlobInfo = blobCache.findFirst(function(cachedBlobInfo) {
701
return cachedBlobInfo.base64() === base64;
704
if (!existingBlobInfo) {
705
blobInfo = blobCache.create(uniqueId(), blob, base64);
706
blobCache.add(blobInfo);
708
blobInfo = existingBlobInfo;
711
pasteHtml('<img src="' + blobInfo.blobUri() + '">');
713
pasteHtml('<img src="' + dataUri + '">');
575
718
* Checks if the clipboard contains image data if it does it will take that data
576
719
* and convert it into a data url image and paste that image at the caret location.
582
725
function pasteImageData(e, rng) {
583
726
var dataTransfer = e.clipboardData || e.dataTransfer;
585
function getBase64FromUri(uri) {
588
idx = uri.indexOf(',');
590
return uri.substr(idx + 1);
596
728
function processItems(items) {
597
729
var i, item, reader, hadImage = false;
599
function pasteImage(reader, blob) {
601
editor.selection.setRng(rng);
605
var blobCache = editor.editorUpload.blobCache;
606
var blobInfo = blobCache.create(uniqueId(), blob, getBase64FromUri(reader.result));
607
blobCache.add(blobInfo);
609
pasteHtml('<img src="' + blobInfo.blobUri() + '">');
613
732
for (i = 0; i < items.length; i++) {
617
736
var blob = item.getAsFile ? item.getAsFile() : item;
619
738
reader = new FileReader();
620
reader.onload = pasteImage.bind(null, reader, blob);
739
reader.onload = pasteImage.bind(null, rng, reader, blob);
621
740
reader.readAsDataURL(blob);
623
742
e.preventDefault();