From 265d60a65f6426cbf31dc2e291095a4948dc521f Mon Sep 17 00:00:00 2001 From: Mantas Masalskis Date: Wed, 20 Nov 2019 12:34:41 +0100 Subject: [PATCH] Fixes #2645 - Insertion of inline pictures does not work, if you copy an image in your Browser --- .../app/lib/base/jquery.contenteditable.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js index e5c7dd1f7..18c0319a4 100644 --- a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js +++ b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js @@ -284,8 +284,19 @@ if (clipboardData && clipboardData.items && clipboardData.items[0]) { var imageInserted = false - var item = clipboardData.items[0] - if (item.kind == 'file' && (item.type == 'image/png' || item.type == 'image/jpeg')) { + var item + + // look for image only if no HTML with textual content is available. + // E.g. Excel provides images of the spreadsheet along with HTML. + // While some browsers make images available in clipboard as HTML, + // sometimes wrapped in multiple nodes. + if($(clipboardData.getData('text/html')).text().trim().length == 0) { + item = jQuery.grep(clipboardData.items, function(item){ + return item.kind == 'file' && (item.type == 'image/png' || item.type == 'image/jpeg') + })[0] + } + + if (item) { this.log('paste image', item) console.log(item) @@ -326,6 +337,8 @@ reader.readAsDataURL(imageFile) imageInserted = true + } else { + item = clipboardData.items[0] } } if (imageInserted) {