From fa6f47068880e15e4a13218a4a59dfdbd092ce0e Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 9 Jul 2020 17:03:43 +0200 Subject: [PATCH] Fix image paste in polls --- www/common/sframe-common-codemirror.js | 28 +++++++++++++++----------- www/poll/inner.js | 2 ++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index 3e391fa63..e04dc9c2e 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -75,6 +75,21 @@ define([ } }; + module.handleImagePaste = function (editor) { + // Don't paste file path in the users wants to paste a file + editor.on('paste', function (editor, ev) { + try { + if (!ev.clipboardData.items) { return; } + var items = Array.prototype.slice.apply(ev.clipboardData.items); + var hasFile = items.some(function (el) { + return el.kind === "file"; + }); + if (!hasFile) { return; } + ev.preventDefault(); + } catch (e) { console.error(e); } + }); + }; + module.getHeadingText = function (editor) { var lines = editor.getValue().split(/\n/); @@ -234,18 +249,7 @@ define([ editor.scrollIntoView(cursor); }); - // Don't paste file path in the users wants to paste a file - editor.on('paste', function (editor, ev) { - try { - if (!ev.clipboardData.items) { return; } - var items = Array.prototype.slice.apply(ev.clipboardData.items); - var hasFile = items.some(function (el) { - return el.kind === "file"; - }); - if (!hasFile) { return; } - ev.preventDefault(); - } catch (e) { console.error(e); } - }); + module.handleImagePaste(editor); var setMode = exp.setMode = function (mode, cb) { exp.highlightMode = mode; diff --git a/www/poll/inner.js b/www/poll/inner.js index ae99ac9cd..b36466a13 100644 --- a/www/poll/inner.js +++ b/www/poll/inner.js @@ -959,6 +959,8 @@ define([ }; common.createFileManager(fmConfig); + SframeCM.handleImagePaste(APP.editor); + // Initialize author name for comments. // Disable name modification for logged in users var $cName = APP.$addComment.find('.cp-app-poll-comments-add-name')