From a54e9e5459cd45173b5db76a8bcce76b2e050433 Mon Sep 17 00:00:00 2001 From: Marco Cyriacks Date: Fri, 30 Jan 2015 21:50:00 +0100 Subject: Fix raw image paste from clipboard This patch binds the textarea (markdown area) paste event to the handlePaste() function (that was already present). Furthermore the event processing is improved in the following way: - The default paste event handler of the browser is only disabled if the browser fully supports clipboardData AND there realy is image data in the event object. In all other cases (no support or no image) the default handler processes the text paste. - Some obsolete code was removed. - The pasteText() function (which is somehow buggy because it places the cursor at the end of the text independantly from its position before the paste) is only used to place the image link after image data was pasted. --- app/assets/javascripts/dropzone_input.js.coffee | 31 +++++++++++-------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/dropzone_input.js.coffee b/app/assets/javascripts/dropzone_input.js.coffee index a0f0d98a8dc..abb5bf519ee 100644 --- a/app/assets/javascripts/dropzone_input.js.coffee +++ b/app/assets/javascripts/dropzone_input.js.coffee @@ -13,6 +13,8 @@ class @DropzoneInput form_textarea = $(form).find("textarea.markdown-area") form_textarea.wrap "
" + form_textarea.bind 'paste', (event) => + handlePaste(event) form_dropzone = $(form).find('.div-dropzone') form_dropzone.parent().addClass "div-dropzone-wrapper" @@ -133,24 +135,17 @@ class @DropzoneInput formatLink = (str) -> "![" + str.alt + "](" + str.url + ")" - handlePaste = (e) -> - e.preventDefault() - my_event = e.originalEvent - - if my_event.clipboardData and my_event.clipboardData.items - processItem(my_event) - - processItem = (e) -> - image = isImage(e) - if image - filename = getFilename(e) or "image.png" - text = "{{" + filename + "}}" - pasteText(text) - uploadFile image.getAsFile(), filename - - else - text = e.clipboardData.getData("text/plain") - pasteText(text) + handlePaste = (event) -> + pasteEvent = event.originalEvent + if pasteEvent.clipboardData and pasteEvent.clipboardData.items + image = isImage(pasteEvent) + if image + event.preventDefault() + + filename = getFilename(pasteEvent) or "image.png" + text = "{{" + filename + "}}" + pasteText(text) + uploadFile image.getAsFile(), filename isImage = (data) -> i = 0 -- cgit v1.2.1 From 7b3fd03155eb757b07f53fdee37ce355d2234d89 Mon Sep 17 00:00:00 2001 From: Marco Cyriacks Date: Mon, 2 Feb 2015 09:32:10 +0100 Subject: Add raw image paste fix changelog entry --- CHANGELOG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 2db5beb0022..d57f0d6563f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -42,7 +42,7 @@ v 7.8.0 - Password reset token validity increased from 2 hours to 2 days since it is also send on account creation. - - - - + - Enable raw image paste from clipboard, currently Chrome only (Marco Cyriacks) - - - Add action property to merge request hook (Julien Bianchi) -- cgit v1.2.1