Is it possible to detect drop location

2 posts, 0 answers
  1. Jonathan
    Jonathan avatar
    15 posts
    Member since:
    Sep 2007

    Posted 10 Sep 2010 Link to this post

    If I have a dragable node on a RadTree is it possible to check the x/y location of where the node is dropped in respect to a panel?

    So if I have a panel containing tree A, plus some other controls, I just want to know if the node I have dragged from tree B is over the panel containing tree A possibly changing the background colour of the panel to show that the node is over an area that it can be released?

    I have tried using the following code to test the possibility out, but the domEvent.offsetX seems to keep changing what it is measuring from as I move it around.

    <script type="text/javascript" language="javascript">
      
        function findPosX(obj) {
            var curleft = 0;
            if (obj.offsetParent)
                while (1) {
                    curleft += obj.offsetLeft;
                    if (!obj.offsetParent)
                        break;
                    obj = obj.offsetParent;
                }
            else if (obj.x)
                curleft += obj.x;
            return curleft;
        }
      
        function findPosY(obj) {
            var curtop = 0;
            if (obj.offsetParent)
                while (1) {
                    curtop += obj.offsetTop;
                    if (!obj.offsetParent)
                        break;
                    obj = obj.offsetParent;
                }
            else if (obj.y)
                curtop += obj.y;
            return curtop;
        }
      
        function ClientNodeDragging(sender, eventArgs) {
            var domEvent = eventArgs.get_domEvent();
            var node = eventArgs.get_node();
            var MyPanel;
            if (document.getElementById('<%= leftPanel.FindControl("pnlPositionSelector").ClientID %>') != null) {
                MyPanel = document.getElementById('<%= leftPanel.FindControl("pnlPositionSelector").ClientID %>');
                node.set_text("Dragging X:" + domEvent.offsetX + " Y:" + domEvent.offsetY + " target XPos=" + findPosX(MyPanel) + " target YPos=" + findPosY(MyPanel));
            }
            else {
                node.set_text("Dragging X:" + domEvent.offsetX + " Y:" + domEvent.offsetY);
            }
            //MyPanel.style.height = NewHeight + "px";
            //MyPanel.style.width = NewWidth + "px";
      
      
      
        }
    </script>
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2815 posts

    Posted 15 Sep 2010 Link to this post

    Hi Jonathan,

    Please look at the following demo - Drag-and-drop. It demonstrates how you can determine if the mouse is over a particular DOM element without calculating coordinates.

    Check out the isMouseOverGrid function:

    function isMouseOverGrid(target)
    {
        parentNode = target;
        while (parentNode != null)
        {                   
            if (parentNode.id == gridId)
            {
                return parentNode;
            }
            parentNode = parentNode.parentNode;
        }
     
        return null;
    }

    You should be able to adapt it to your requirements.

    I hope this helps.

    Regards,
    Tsvetomir Tsonev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top