Commit a54e9e54 authored by Marco Cyriacks's avatar Marco Cyriacks

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.
parent c4732894
...@@ -13,6 +13,8 @@ class @DropzoneInput ...@@ -13,6 +13,8 @@ class @DropzoneInput
form_textarea = $(form).find("textarea.markdown-area") form_textarea = $(form).find("textarea.markdown-area")
form_textarea.wrap "<div class=\"div-dropzone\"></div>" form_textarea.wrap "<div class=\"div-dropzone\"></div>"
form_textarea.bind 'paste', (event) =>
handlePaste(event)
form_dropzone = $(form).find('.div-dropzone') form_dropzone = $(form).find('.div-dropzone')
form_dropzone.parent().addClass "div-dropzone-wrapper" form_dropzone.parent().addClass "div-dropzone-wrapper"
...@@ -133,24 +135,17 @@ class @DropzoneInput ...@@ -133,24 +135,17 @@ class @DropzoneInput
formatLink = (str) -> formatLink = (str) ->
"![" + str.alt + "](" + str.url + ")" "![" + str.alt + "](" + str.url + ")"
handlePaste = (e) -> handlePaste = (event) ->
e.preventDefault() pasteEvent = event.originalEvent
my_event = e.originalEvent if pasteEvent.clipboardData and pasteEvent.clipboardData.items
image = isImage(pasteEvent)
if my_event.clipboardData and my_event.clipboardData.items if image
processItem(my_event) event.preventDefault()
processItem = (e) -> filename = getFilename(pasteEvent) or "image.png"
image = isImage(e) text = "{{" + filename + "}}"
if image pasteText(text)
filename = getFilename(e) or "image.png" uploadFile image.getAsFile(), filename
text = "{{" + filename + "}}"
pasteText(text)
uploadFile image.getAsFile(), filename
else
text = e.clipboardData.getData("text/plain")
pasteText(text)
isImage = (data) -> isImage = (data) ->
i = 0 i = 0
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment