WindowManager._onBodyMouseMove = function()

in assets/scripts/api.simile-widgets.org/ajax/2.2.4/simile-ajax-api-debug.js [1762:1883]


WindowManager._onBodyMouseMove = function(elmt, evt, target) {
    if (WindowManager._draggedElement != null) {
        var callback = WindowManager._draggedElementCallback;
        
        var lastCoords = WindowManager._lastCoords;
        var diffX = evt.clientX - lastCoords.x;
        var diffY = evt.clientY - lastCoords.y;
        
        if (!WindowManager._dragging) {
            if (Math.abs(diffX) > 5 || Math.abs(diffY) > 5) {
                try {
                    if ("onDragStart" in callback) {
                        callback.onDragStart();
                    }
                    
                    if ("ghost" in callback && callback.ghost) {
                        var draggedElmt = WindowManager._draggedElement;
                        
                        WindowManager._ghostCoords = DOM.getPageCoordinates(draggedElmt);
                        WindowManager._ghostCoords.left += diffX;
                        WindowManager._ghostCoords.top += diffY;
                        
                        var ghostElmt = draggedElmt.cloneNode(true);
                        ghostElmt.style.position = "absolute";
                        ghostElmt.style.left = WindowManager._ghostCoords.left + "px";
                        ghostElmt.style.top = WindowManager._ghostCoords.top + "px";
                        ghostElmt.style.zIndex = 1000;
                        Graphics.setOpacity(ghostElmt, 50);
                        
                        document.body.appendChild(ghostElmt);
                        callback._ghostElmt = ghostElmt;
                    }
                    
                    WindowManager._dragging = true;
                    WindowManager._lastCoords = { x: evt.clientX, y: evt.clientY };
                    
                    document.body.focus();
                } catch (e) {
                    Debug.exception("WindowManager: Error handling mouse down", e);
                    WindowManager._cancelDragging();
                }
            }
        } else {
            try {
                WindowManager._lastCoords = { x: evt.clientX, y: evt.clientY };
                
                if ("onDragBy" in callback) {
                    callback.onDragBy(diffX, diffY);
                }
                
                if ("_ghostElmt" in callback) {
                    var ghostElmt = callback._ghostElmt;
                    
                    WindowManager._ghostCoords.left += diffX;
                    WindowManager._ghostCoords.top += diffY;
                    
                    ghostElmt.style.left = WindowManager._ghostCoords.left + "px";
                    ghostElmt.style.top = WindowManager._ghostCoords.top + "px";
                    if (WindowManager._draggingModeIndicatorElmt != null) {
                        var indicatorElmt = WindowManager._draggingModeIndicatorElmt;
                        
                        indicatorElmt.style.left = (WindowManager._ghostCoords.left - 16) + "px";
                        indicatorElmt.style.top = WindowManager._ghostCoords.top + "px";
                    }
                    
                    if ("droppable" in callback && callback.droppable) {
                        var coords = DOM.getEventPageCoordinates(evt);
                        var target = DOM.hittest(
                            coords.x, coords.y, 
                            [   WindowManager._ghostElmt, 
                                WindowManager._dropTargetHighlightElement 
                            ]
                        );
                        target = WindowManager._findDropTarget(target);
                        
                        if (target != WindowManager._potentialDropTarget) {
                            if (WindowManager._dropTargetHighlightElement != null) {
                                document.body.removeChild(WindowManager._dropTargetHighlightElement);
                                
                                WindowManager._dropTargetHighlightElement = null;
                                WindowManager._potentialDropTarget = null;
                            }

                            var droppable = false;
                            if (target != null) {
                                if ((!("canDropOn" in callback) || callback.canDropOn(target)) &&
                                    (!("canDrop" in target) || target.canDrop(WindowManager._draggedElement))) {
                                    
                                    droppable = true;
                                }
                            }
                            
                            if (droppable) {
                                var border = 4;
                                var targetCoords = DOM.getPageCoordinates(target);
                                var highlight = document.createElement("div");
                                highlight.style.border = border + "px solid yellow";
                                highlight.style.backgroundColor = "yellow";
                                highlight.style.position = "absolute";
                                highlight.style.left = targetCoords.left + "px";
                                highlight.style.top = targetCoords.top + "px";
                                highlight.style.width = (target.offsetWidth - border * 2) + "px";
                                highlight.style.height = (target.offsetHeight - border * 2) + "px";
                                Graphics.setOpacity(highlight, 30);
                                document.body.appendChild(highlight);
                                
                                WindowManager._potentialDropTarget = target;
                                WindowManager._dropTargetHighlightElement = highlight;
                            }
                        }
                    }
                }
            } catch (e) {
                Debug.exception("WindowManager: Error handling mouse move", e);
                WindowManager._cancelDragging();
            }
        }
        
        DOM.cancelEvent(evt);
        return false;
    }
};