uploadcare / uploadcare-widget

Uploadcare Widget, an ultimate tool for HTML5 file upload supporting multiple file upload, drag&drop, validation by file size/file extension/MIME file type, progress bar for file uploads, image preview.
https://uploadcare.com/products/file_uploader/
BSD 2-Clause "Simplified" License
227 stars 102 forks source link

Expose cleanup() method #328

Open fabien opened 8 years ago

fabien commented 8 years ago

Currently, there is no way to cleanly destroy a Widget from the DOM, which is critical in SPA setups.

The functionality exists, however, in the form of a cleanup() method:

https://github.com/uploadcare/uploadcare-bower/blob/master/uploadcare.js#L8075

But since it's wrapped in a closure, it is not publicly exposed. I think there should be a destroy method on a Widget instance to handle this properly.

homm commented 8 years ago

I think you are right, we need such method in the API. But I don't satisfied with the cleanup quality (for example, it selects .next('.uploadcare-widget') while it can be not exactly widget element). So It's a bit complex than just expose already existing method, but it is definitely doable.

vladimir-socialsweethearts commented 6 years ago

Hi @homm, @Zmoki. Is there any plan to introduce this feature? I see quite old open issues that are referenced here but I am not sure if it was already implemented or not.

Zmoki commented 6 years ago

@vladimir-socialsweethearts hi!

We'll finish and release the methods for destroy widget early next year.

geetfun commented 6 years ago

@Zmoki Just wondering if there's a temporary workaround for this on already initialized widgets to clean it up?

Turbolinks (for Rails) is causing a problem as it caches the pages, and so if the back button is pressed, the same input[role='uploadcare-uploader'] is initialized multiple times.

I'm currently doing the following:

$(document).on('turbolinks:before-cache', function() { $(".uploadcare--dialog__close").trigger("click"); $(".uploadcare--dialog").remove(); $(".uploadcare--widget").remove(); })

anrus commented 4 years ago

Any news for this issue?