Search the web
Sign In
New User? Sign Up
ydn-javascript · Yahoo! User Interface Library Group
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Strange behavior with Drag & Drop   Message List  
Reply | Forward Message #22952 of 52127 |
Hello,

I'm starting with YUI, and while playing a bit with the Drag & Drop module, I came to find this strange behavior involving an element with two associated D&Ds. I just want to know if I made a mistake or if it really wasn't supposed to happen this way. My code is based on the resizable panel example. Here it goes:

<body>
        <style>
            #a {
                position:absolute;
                left:50px;
                top:50px;
                border: 1px solid;
                width: 150px;
                height: 150px;
                background-color:yellow;
            }
           
            #b {
                height: 30px;
                border: 1px solid;
                background-color:green;
                cursor: move;
            }
           
            #c {
                position: absolute;
                bottom: -1px;
                right: -1px;
                height: 10px;
                width: 10px;
                border: 1px solid;
                background-color:red;
                cursor: se-resize;
            }
        </style>
       
        <div id="a">
            <div id="b"></div>
            <div id="c"></div>
        </div>
       
        <script>
            YAHOO.example.DDResize = function(panelElId, handleElId, sGroup, config) {
                YAHOO.example.DDResize.superclass.constructor.call(this, panelElId, sGroup, config);
                if (handleElId) {
                    this.setHandleElId(handleElId);
                }
            };
           
            YAHOO.extend(YAHOO.example.DDResize, YAHOO.util.DragDrop, {
           
                onMouseDown: function(e) {
                    var panel = this.getEl();
                    this.startWidth = panel.offsetWidth;
                    this.startHeight = panel.offsetHeight;
           
                    this.startPos = [YAHOO.util.Event.getPageX(e),
                                     YAHOO.util.Event.getPageY(e)];
                },
           
                onDrag: function(e) {
                    var newPos = [YAHOO.util.Event.getPageX(e),
                                  YAHOO.util.Event.getPageY(e)];
           
                    var offsetX = newPos[0] - this.startPos[0];
                    var offsetY = newPos[1] - this.startPos[1];
           
                    var newWidth = Math.max(this.startWidth + offsetX, 10);
                    var newHeight = Math.max(this.startHeight + offsetY, 10);
           
                    var panel = this.getEl();
                    panel.style.width = newWidth + "px";
                    panel.style.height = newHeight + "px";
                }
            });
           
            YAHOO.util.Event.onDOMReady(function() {                               
                var dd1 = new YAHOO.util.DD('a', 'move');
                dd1.setHandleElId('b');
               
                var dd2 = new YAHOO.example.DDResize('a', 'c', 'resize');
            });
        </script>
</body>

Here's the situation: the only difference between the example and my code is that 'b' is stated as the handle for 'dd1'. This doesn't work as I think it should, because on Firefox 2 both 'b' and 'c' act as handles for resizing, and on IE7, they both act as handles for dragging. If I switch 'dd1' and 'dd2' instantiations on code, the respective behaviors are switched between browsers. Adding the following line makes this code work for one of the browsers, but not both (but I guess adding it shouldn't have any effect if the code behaved as expected):

dd1.addInvalidHandleId(c);


Any help is much appreciated.


Fri Dec 21, 2007 8:36 pm

guidenapoli
Offline Offline
Send Email Send Email

Forward
Message #22952 of 52127 |
Expand Messages Author Sort by Date

Hello, I'm starting with YUI, and while playing a bit with the Drag & Drop module, I came to find this strange behavior involving an element with two...
Guilherme De Napoli
guidenapoli
Offline Send Email
Dec 21, 2007
8:36 pm

Sorry to insist, everybody, but I would really like some help here. Happy holidays to all of you!...
Guilherme De Napoli
guidenapoli
Offline Send Email
Dec 26, 2007
2:58 pm

What's the strange behavior that you're seeing?...
jasen_halmes
Offline Send Email
Dec 26, 2007
10:32 pm

Guilherme -- Sorry for the late reply :) The issue is that you are placing 2 different DragDrop instances on the same element. When the second is attached it...
dav.glass@...
dav.glass
Offline Send Email
Dec 26, 2007
11:59 pm

Dav, that really helped, thanks a lot! But I'm still curious about something: the official example actually places two D&D instances on the same element like I...
Guilherme De Napoli
guidenapoli
Offline Send Email
Dec 27, 2007
2:23 am

Guilherme -- That's part of it, but there is also this line: dd2.addInvalidHandleId("dd-resize-handle"); That tells the second dd instance (which is the...
dav.glass@...
dav.glass
Offline Send Email
Dec 27, 2007
4:17 am

Ok, Dav! I'll stick to your approach. Thank you very much! Guilherme ... the handle is an invalid handle. So when it is activated it doesn't move the object :)...
Guilherme De Napoli
guidenapoli
Offline Send Email
Dec 27, 2007
12:48 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help