FileDrop icon indicating copy to clipboard operation
FileDrop copied to clipboard

Reset FileDrop instance

Open rafaelmaiolla opened this issue 11 years ago • 7 comments
trafficstars

Is there a way to reset the FileDrop object instance? Or destroy it to instantiate a new instance?

rafaelmaiolla avatar Feb 21 '14 16:02 rafaelmaiolla

What do you mean by "reset"? Unbind it from the zone? This is currently not implemented (if you want to remove event listeners simply reinsert the zone node into the DOM) because apart from this I'll have to remove iframe, form, etc. and I don't see much use of this anyway.

ProgerXP avatar Feb 21 '14 17:02 ProgerXP

I see. I worked around that by removing the elements added by FileDrop and then I was able to instantiate it again in the same zone node.

rafaelmaiolla avatar Feb 21 '14 17:02 rafaelmaiolla

You supposedly could still instantinate another instance on the same zone node because FileDrop reuses existing elements (it won't create iframe and form twice).

What is the use case of reinstantinating it on the same node in your project?

ProgerXP avatar Feb 21 '14 18:02 ProgerXP

I tried to re-instantiate it, but it didn't seem to work properly. I didn't investigate why, but the events were not working properly, this could be a problem here for my project.

In my project, when a view is shown, I don't know if the HTML was removed from the DOM and re-created. So, to guarantee that everything will be working, I re-instantiate the FileDrop instance so it can re-attach the events.

rafaelmaiolla avatar Feb 21 '14 18:02 rafaelmaiolla

It looks like <filedrop>.hook(<zonenode>) would do the trick much better than removing internal stuff like form and iframe. It's also more lightweight and will retain multiple attribute of file input as well as other changes on the DOM tree.

Honestly I didn't test it but I think this should work:

var zone = new FileDrop('id')
...
zone.hook(zone.el)

ProgerXP avatar Feb 21 '14 18:02 ProgerXP

I think you also need to do the following, or the zone.hook will not find the new elements:

zone.opt.input = null;

rafaelmaiolla avatar Feb 24 '14 13:02 rafaelmaiolla

This is only needed if you have changed either the <form> or <input type="file">. If you have just reinserted them into the DOM this is optional. In your case it's necessary though.

Nice to know it works.

ProgerXP avatar Feb 24 '14 13:02 ProgerXP