FileDrop icon indicating copy to clipboard operation
FileDrop copied to clipboard

If you create a new FileDrop for a node which is not inserted into the DOM, FileDrop fails to initialize properly

Open igormukhin opened this issue 10 years ago • 5 comments

The problem in this case is (in prepareInput()) the line: if (target && global.isTag(global.byID(target), 'iframe')) {

Here global.byID(target) can't find the iframe because the parent DOM is not inserted into the global DOM. It should be like baseNode.findByID(target)

igormukhin avatar Nov 13 '14 12:11 igormukhin

It's not a good idea to initialize FileDrop on a non-inserted zone node because eventually you will insert it into the main document which will remove all previously bound DOM event listeners so you'll need to re-attach them (fd.hook() and friends). This is not a very standard/intended behaviour.

Why are you initializing FileDrop before inserting its zone node into the document?

ProgerXP avatar Nov 13 '14 13:11 ProgerXP

I have something like this.

$("#panel").append(renderComponentNode());

where

function renderComponentNode() {
    var $node = $("<div></div>");
    // ... here much code for creating the contents inside of $node
    // ... here FileDrop is inserted also inside of $node

    // events are working all right
    $node.find("button").click(function () { ... });
    return $node;
}

igormukhin avatar Nov 13 '14 22:11 igormukhin

Sorry for the delay. Do you still need a solution? I think I know what can be done although I expected FileDrop to have access to main DOM upon initiaization.

If you're still on it can you confirm that it currently works fine if you disable iframe? new FileDrop('zone', {input: false})

ProgerXP avatar Nov 25 '14 08:11 ProgerXP

@ProgerXP I had to redesign my code a little bit to get it working, but still I think that FileDrop should not rely on that it has access to the main DOM. Nobody who is using some kind of a component system will not be able to use FileDrop if it need the main DOM.

(I have to support IE8, so I need iFrame support also)

igormukhin avatar Dec 01 '14 10:12 igormukhin

@igormukhin I get your point. Should this question bother someone else - write up here.

ProgerXP avatar Dec 01 '14 12:12 ProgerXP