Opened 14 years ago

Closed 12 years ago

#370 closed defect (fixed)

DND does not work when dragging onto a panel with another under lying dragtarget

Reported by: pass.travis@… Owned by: psowden
Priority: high Milestone: 0.9
Component: DnD Version: 0.2
Keywords: Cc:
Blocked By: Blocking:

Description

DND does not work when dragging onto a panel with another under lying dragtarget.

From a quick look at the HtmlDragManager?, it looks like findBestTarget does not take z-index into account

Change History (4)

comment:1 Changed 13 years ago by dojo@…

I've been using this fix to solve a similar problem where i'd like the nested targets to be chosen based on the smallest area first, it should be easy to modify it to work based on Z-Index instead. (This was tested against trunk)

dojo.addOnLoad(function() {
    if(dojo.dnd.dragManager.nestedTargets) {
        dojo.event.connect(
            "after", 
            dojo.dnd.dragManager, 
            "cacheTargetLocations", 
            function() {
                dojo.dnd.dragManager.dropTargetDimensions.sort(function(a,b) {
                    var areaX = a[1][0] * a[1][1];
                    var areaY = b[1][0] * b[1][1];
                    return areaY - areaX;
                });
            }
        );
    }
});

comment:2 Changed 13 years ago by dylan

Component: GeneralDnD
Milestone: 0.5
Owner: changed from anonymous to psowden

comment:3 Changed 13 years ago by dojo@…

This above fix still works as of 0.4, but i'm currently using the following modification to the findBestTarget method, which is a bit cleaner:

findBestTarget: function(e) {
        var _this = this;
        var bestBox = new Object();
        bestBox.target = null;
        bestBox.points = null;
        var bestArea = null;
        dojo.lang.every(this.dropTargetDimensions, function(tmpDA) {
                if(!_this.isInsideBox(e, tmpDA)){
                        return true;
                }
                if(!_this.nestedTargets) {
                        bestBox.target = tmpDA[2];
                        bestBox.points = tmpDA;
                } else {
                        var area = tmpDA[1][0] * tmpDA[1][1];
                        if(bestArea===null || area < bestArea) {
                                bestArea = area;
                                bestBox.target = tmpDA[2];
                                bestBox.points = tmpDA;
                        } 
                }
                        
                // continue iterating only if _this.nestedTargets == true
                return Boolean(_this.nestedTargets);
        });

        return bestBox;
},

I'm currently adding this into the code I'm working on with the following snippet, which is a bit longer than the previous one, but more efficient:

/* Fix to allow the priority selection of DropTargets that have the smallest area first */
if(dojo.dnd.dragManager.nestedTargets) {
    dojo.dnd.dragManager.findBestTarget = dojo.lang.hitch(dojo.dnd.dragManager,function(e) {
        var _this = this;
        var bestBox = new Object();
        bestBox.target = null;
        bestBox.points = null;
        var bestArea = null;
        dojo.lang.every(this.dropTargetDimensions, function(tmpDA) {
                if(!_this.isInsideBox(e, tmpDA)){
                        return true;
                }   
                if(!_this.nestedTargets) {
                        bestBox.target = tmpDA[2];
                        bestBox.points = tmpDA;
                } else {
                        var area = tmpDA[1][0] * tmpDA[1][1];
                        if(bestArea===null || area < bestArea) {
                                bestArea = area;
                                bestBox.target = tmpDA[2];
                                bestBox.points = tmpDA;
                        }   
                }   
                
                // continue iterating only if _this.nestedTargets == true
                return Boolean(_this.nestedTargets);
        });  
        return bestBox;
    });    
}   

comment:4 Changed 12 years ago by Eugene Lazutkin

Resolution: fixed
Status: newclosed

Fixed in 0.9.

Note: See TracTickets for help on using tickets.