Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop event should not bubble up if the image was uploaded #2837

Closed
zadam opened this issue Mar 7, 2019 · 5 comments · Fixed by ckeditor/ckeditor5-clipboard#63
Closed

Drop event should not bubble up if the image was uploaded #2837

zadam opened this issue Mar 7, 2019 · 5 comments · Fixed by ckeditor/ckeditor5-clipboard#63
Labels
package:upload type:bug This issue reports a buggy (incorrect) behavior. type:question This issue asks a question (how to...).
Milestone

Comments

@zadam
Copy link

zadam commented Mar 7, 2019

I implemented custom image uploader plugin/adapter which allows user to drag & drop images into the text content which then uploads them the server and inserts them at the caret. This works well.

But I also have a custom drop DIV which allows upload of any type of file attachment. CKEditor is inside this DIV since I want to allow dropping attachments on large portion of the app. The way I image it should work is:

  1. image scenario: I drag image & drop it onto the CKEditor instance - CKEditor handles the upload and insert into the text content. Since it handled the upload, it stops the event propagation/bubbling
  2. non-image scenario: I drag a file & drop it onto the CKEditor instance - since it's not an image, CKEditor doesn't upload it and lets the event bubble up, my custom drop DIV handler will process the event and upload the file

This kind of works, except for the fact that in the scenario 1), CKEditor doesn't stop the event propagation even though the event has been handled (image has been uploaded). Result of this is then that I get two uploads of the file.

In the image upload plugin infrastructure I can't see a way how to stop the propagation myself, since I don't have access to the original event AFAICS.

@zadam zadam changed the title Drop event should not be bubble up if the image was uploaded Drop event should not bubble up if the image was uploaded Mar 7, 2019
@Mgsy
Copy link
Member

Mgsy commented Mar 14, 2019

cc @oleq

oleq referenced this issue in ckeditor/ckeditor5-clipboard Mar 18, 2019
oleq referenced this issue in ckeditor/ckeditor5-image Mar 18, 2019
…he `clipboardInput` event is handled correctly. See ckeditor/ckeditor5-upload#92.
Reinmar referenced this issue in ckeditor/ckeditor5-clipboard Mar 28, 2019
Fix: The DOM `drop` event will not bubble up if the `clipboardInput` event was handled. Closes ckeditor/ckeditor5-upload#92.
Reinmar referenced this issue in ckeditor/ckeditor5-image Mar 28, 2019
Tests: Added assertion to the `ImageUploadEditing` tests to make sure the `clipboardInput` event is handled correctly. See ckeditor/ckeditor5-upload#92.
@patrikrazem
Copy link

@zadam Would you mind sharing how you achieved the generic file upload mechanism? Are you disregarding CKEditor's handing entirely, or did you somehow hook into it with a plugin?

@Mgsy
Copy link
Member

Mgsy commented May 27, 2019

@zadam Would you mind sharing how you achieved the generic file upload mechanism? Are you disregarding CKEditor's handing entirely, or did you somehow hook into it with a plugin?

@patrikrazem, you can find a guide about creating custom image upload adapter on our documentation page.

@patrikrazem
Copy link

@Mgsy Thank you, but I've already implemented a custom image upload adapter and it works as expected. What I'm now trying to do is handle uploads of all file types (documents, pdfs, etc.) and then insert them into the content as anchor tags.

@zadam
Copy link
Author

zadam commented May 27, 2019

@patrikrazem It's pretty simple, I have a div element on which I have event listener for drop event. So I drag a file(s) from file manager to the div, drop event gets called and I can access the files from e.originalEvent.dataTransfer.files and upload them using FormData object with AJAX.

In this particular case the div is parent of CKEditor so images are handled by CKEditor upload, but other file types bubble up and are uploaded using the uploaded described above (with no CKEditor involvement).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:upload type:bug This issue reports a buggy (incorrect) behavior. type:question This issue asks a question (how to...).
Projects
None yet
4 participants