Loading ...
Sorry, an error occurred while loading the content.

Cancelling a drag-and-drop

Expand Messages
  • Dave
    Hi everyone, I ve read through the archive, but I cannot find the answer to my question. I ve created a drag/drop app using proxies objects that is almost
    Message 1 of 6 , May 29 3:10 PM
    • 0 Attachment
      Hi everyone,

      I've read through the archive, but I cannot find the answer to my
      question. I've created a drag/drop app using proxies objects that is
      almost exactly like the sortable list example
      (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist).
      However, the one difference is that the last item in one of the lists
      (no matter which one) cannot be dragged out of the list. Is there a
      way to cancel an attempt to drag if the user drags the last element
      from a list?

      What I've been trying to do is place the code in the startDrag method
      and have been able to identify an attempt to drag the last element as:

      if (!mycontainer.firstChild.nextSibling && this.getEl() ==
      mycontainer.firstChild) {
      }

      But what do I put in this to completely cancel this specific attempt
      at dragging?
    • Adam Platti
      You might want to take a look at the b4Drag method in DD and override that instead. There s a function call in there that actually moves the object, so you
      Message 2 of 6 , May 29 4:29 PM
      • 0 Attachment
        You might want to take a look at the b4Drag method in DD and override that instead.   There's a function call in there that actually moves the object, so you could wrap that call with the opposite of the if statement you wrote to prevent the last child from moving.   i noticed that the onDrag function still fires when you do this, though.    You might need a better solution.

        I noticed on the YAHOO.util.DragDropManager object, there is a private method called stopDrag(e).   You could try calling that.

        Adam

        On 5/29/07, Dave <doyle@...> wrote:

        Hi everyone,

        I've read through the archive, but I cannot find the answer to my
        question. I've created a drag/drop app using proxies objects that is
        almost exactly like the sortable list example
        (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist ).
        However, the one difference is that the last item in one of the lists
        (no matter which one) cannot be dragged out of the list. Is there a
        way to cancel an attempt to drag if the user drags the last element
        from a list?

        What I've been trying to do is place the code in the startDrag method
        and have been able to identify an attempt to drag the last element as:

        if (!mycontainer.firstChild.nextSibling && this.getEl() ==
        mycontainer.firstChild) {
        }

        But what do I put in this to completely cancel this specific attempt
        at dragging?


      • Dave
        I had already tried the stopDrag method, but got so many side effects that I decided it might not be the right way to go. I ll take a look at b4Drag.
        Message 3 of 6 , May 30 7:53 AM
        • 0 Attachment
          I had already tried the 'stopDrag' method, but got so many side
          effects that I decided it might not be the right way to go. I'll take
          a look at b4Drag. Thanks.

          Dave

          --- In ydn-javascript@yahoogroups.com, "Adam Platti" <aplatti@...> wrote:
          >
          > You might want to take a look at the b4Drag method in DD and
          override that
          > instead. There's a function call in there that actually moves the
          object,
          > so you could wrap that call with the opposite of the if statement
          you wrote
          > to prevent the last child from moving. i noticed that the onDrag
          function
          > still fires when you do this, though. You might need a better
          solution.
          >
          > I noticed on the YAHOO.util.DragDropManager object, there is a private
          > method called stopDrag(e). You could try calling that.
          >
          > Adam
          >
          > On 5/29/07, Dave <doyle@...> wrote:
          > >
          > > Hi everyone,
          > >
          > > I've read through the archive, but I cannot find the answer to my
          > > question. I've created a drag/drop app using proxies objects that is
          > > almost exactly like the sortable list example
          > >
          (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist).
          > > However, the one difference is that the last item in one of the lists
          > > (no matter which one) cannot be dragged out of the list. Is there a
          > > way to cancel an attempt to drag if the user drags the last element
          > > from a list?
          > >
          > > What I've been trying to do is place the code in the startDrag method
          > > and have been able to identify an attempt to drag the last element as:
          > >
          > > if (!mycontainer.firstChild.nextSibling && this.getEl() ==
          > > mycontainer.firstChild) {
          > > }
          > >
          > > But what do I put in this to completely cancel this specific attempt
          > > at dragging?
          > >
          > >
          > >
          >
        • someguynameddylan
          Hi, I ve faced an issue like that before, if you don t want the last item to be dragged, then you can call the instance method YAHOO.util.DragDrop.lock() for
          Message 4 of 6 , May 30 10:16 AM
          • 0 Attachment
            Hi,

            I've faced an issue like that before, if you don't want the last item
            to be dragged, then you can call the instance method
            YAHOO.util.DragDrop.lock() for the DD object that is representing that
            last element.

            But then of course you won't be able to drop anything on it. If
            dropping on the item is also desired then you'll have to provide some
            logic to single out the last element in the list and instantiate a
            DDTarget object instead of the regular DD or DDProxy object for it.

            Hope that helps,

            Dylan

            --- In ydn-javascript@yahoogroups.com, "Dave" <doyle@...> wrote:
            >
            > Hi everyone,
            >
            > I've read through the archive, but I cannot find the answer to my
            > question. I've created a drag/drop app using proxies objects that is
            > almost exactly like the sortable list example
            > (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist).
            > However, the one difference is that the last item in one of the lists
            > (no matter which one) cannot be dragged out of the list. Is there a
            > way to cancel an attempt to drag if the user drags the last element
            > from a list?
            >
            > What I've been trying to do is place the code in the startDrag method
            > and have been able to identify an attempt to drag the last element as:
            >
            > if (!mycontainer.firstChild.nextSibling && this.getEl() ==
            > mycontainer.firstChild) {
            > }
            >
            > But what do I put in this to completely cancel this specific attempt
            > at dragging?
            >
          • Dave
            I had already tried this and it almost worked. Unfortunately the proxy still traveled around until it was released, giving the impression that it was still
            Message 5 of 6 , May 30 12:22 PM
            • 0 Attachment
              I had already tried this and it 'almost' worked. Unfortunately the
              proxy still traveled around until it was released, giving the
              impression that it was still droppable. To get this far I locked it
              on startDrag and then checked if it was locked on stopDrag and
              unlocked it if it was.

              But I think I've found a solution that avoids moving the proxy at all.
              As mentioned by Adam earlier, I overrode the b4drag method, and after
              identifying that the user was attempting to drag the last element in a
              list, called DDM.handleMouseUp(e).

              This did what I wanted, but uncovered a bug in the Yahoo codebase.
              For anyone else that wants to do this, you'll need to change line 677
              in the dragdrop.js from:
              this.dragCurrent.onDrag(e);
              to:
              if (this.dragCurrent) this.dragCurrent.onDrag(e);

              Dave

              --- In ydn-javascript@yahoogroups.com, "someguynameddylan"
              <DylanTheDeveloper@...> wrote:
              >
              > Hi,
              >
              > I've faced an issue like that before, if you don't want the last item
              > to be dragged, then you can call the instance method
              > YAHOO.util.DragDrop.lock() for the DD object that is representing that
              > last element.
              >
              > But then of course you won't be able to drop anything on it. If
              > dropping on the item is also desired then you'll have to provide some
              > logic to single out the last element in the list and instantiate a
              > DDTarget object instead of the regular DD or DDProxy object for it.
              >
              > Hope that helps,
              >
              > Dylan
              >
              > --- In ydn-javascript@yahoogroups.com, "Dave" <doyle@> wrote:
              > >
              > > Hi everyone,
              > >
              > > I've read through the archive, but I cannot find the answer to my
              > > question. I've created a drag/drop app using proxies objects that is
              > > almost exactly like the sortable list example
              > >
              (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist).
              > > However, the one difference is that the last item in one of the lists
              > > (no matter which one) cannot be dragged out of the list. Is there a
              > > way to cancel an attempt to drag if the user drags the last element
              > > from a list?
              > >
              > > What I've been trying to do is place the code in the startDrag method
              > > and have been able to identify an attempt to drag the last element as:
              > >
              > > if (!mycontainer.firstChild.nextSibling && this.getEl() ==
              > > mycontainer.firstChild) {
              > > }
              > >
              > > But what do I put in this to completely cancel this specific attempt
              > > at dragging?
              > >
              >
            • Adam Platti
              yea, it would be cool if there was an API for aborting a drag from inside b4Drag. Adam
              Message 6 of 6 , May 31 12:58 PM
              • 0 Attachment
                yea, it would be cool if there was an API for aborting a drag from inside b4Drag.

                Adam

                On 5/30/07, Dave <doyle@... > wrote:

                I had already tried this and it 'almost' worked. Unfortunately the
                proxy still traveled around until it was released, giving the
                impression that it was still droppable. To get this far I locked it
                on startDrag and then checked if it was locked on stopDrag and
                unlocked it if it was.

                But I think I've found a solution that avoids moving the proxy at all.
                As mentioned by Adam earlier, I overrode the b4drag method, and after
                identifying that the user was attempting to drag the last element in a
                list, called DDM.handleMouseUp(e).

                This did what I wanted, but uncovered a bug in the Yahoo codebase.
                For anyone else that wants to do this, you'll need to change line 677
                in the dragdrop.js from:
                this.dragCurrent.onDrag(e);
                to:
                if (this.dragCurrent) this.dragCurrent.onDrag(e);

                Dave

                --- In ydn-javascript@yahoogroups.com, "someguynameddylan"


                <DylanTheDeveloper@...> wrote:
                >
                > Hi,
                >
                > I've faced an issue like that before, if you don't want the last item
                > to be dragged, then you can call the instance method
                > YAHOO.util.DragDrop.lock() for the DD object that is representing that
                > last element.
                >
                > But then of course you won't be able to drop anything on it. If
                > dropping on the item is also desired then you'll have to provide some
                > logic to single out the last element in the list and instantiate a
                > DDTarget object instead of the regular DD or DDProxy object for it.
                >
                > Hope that helps,
                >
                > Dylan
                >
                > --- In ydn-javascript@yahoogroups.com, "Dave" <doyle@> wrote:
                > >
                > > Hi everyone,
                > >
                > > I've read through the archive, but I cannot find the answer to my
                > > question. I've created a drag/drop app using proxies objects that is
                > > almost exactly like the sortable list example
                > >
                (http://developer.yahoo.com/yui/examples/dragdrop/list.html?mode=dist ).
                > > However, the one difference is that the last item in one of the lists
                > > (no matter which one) cannot be dragged out of the list. Is there a
                > > way to cancel an attempt to drag if the user drags the last element
                > > from a list?
                > >
                > > What I've been trying to do is place the code in the startDrag method
                > > and have been able to identify an attempt to drag the last element as:
                > >
                > > if (!mycontainer.firstChild.nextSibling && this.getEl() ==
                > > mycontainer.firstChild) {
                > > }
                > >
                > > But what do I put in this to completely cancel this specific attempt
                > > at dragging?
                > >
                >


              Your message has been successfully submitted and would be delivered to recipients shortly.