YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub
  [ 3 posts ]

Dan Tudor

  • Username: dantudor
  • Joined: Tue Nov 10, 2009 4:56 am
  • Posts: 2
  • Offline
  • Profile

Drag & Drop with external elements to the list

Post Posted: Tue Nov 10, 2009 5:08 am
+0-
Hello All,

I'm currently working on a customization of the drag-drop sort example (http://developer.yahoo.com/yui/examples ... order.html).

My code extends the example to allow elements in the list to be dropped onto a trash icon that will remove the element from the list.
To do this I have assigned a new DDlist Object to my trash can image(img#e_delete) and in YAHOO.extend(YAHOO.chalk.cms.DDList, YAHOO.util.DDProxy, { onDragDrop added the following code:

Code:
  onDragDrop: function(e, id) {
    var Dom = YAHOO.util.Dom;
    var DDM = YAHOO.util.DragDropMgr;
   
    var srcEl = this.getEl();
    var destEl = Dom.get(id);
    var destDD = DDM.getDDById(id);
   
    if (destEl.id=='e_delete') {
      // Call function here to delete the element from the list and database and refresh the list
      destDD.isEmpty = false;
      DDM.refreshCache();
     
    } else if (DDM.interactionInfo.drop.length === 1) {
      var pt = DDM.interactionInfo.point;
      var region = DDM.interactionInfo.sourceRegion;
     
      if (!region.intersect(pt)) {
        destEl.appendChild(this.getEl());
        destDD.isEmpty = false;
        DDM.refreshCache();
      }
    }
  },


But what I have noticed is the trash can icon is also draggable.

My question is should I assign the trash can as a different object type or is there a way to override the ability to select the trash can as a draggable element.
I've tried the following which is unsuccessful:

Code:
  onDrag: function(e) {
    var Event = YAHOO.util.Event;
    var y = Event.getPageY(e);
   
    var srcEl = this.getEl();
   
    if (srcEl.id=='e_delete') Event.stopEvent(e);

Dav Glass

YUI Developer

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 1190
  • Location: Cupertino, CA
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • YUI Developer
  • Offline
  • Profile

Re: Drag & Drop with external elements to the list

Post Posted: Thu Nov 12, 2009 6:39 am
+0-
Instead of making it a DDList object, try just making the Trash Can a DDTarget.

Code:
var trash = new YAHOO.util.DDTarget('e_delete');

Dan Tudor

  • Username: dantudor
  • Joined: Tue Nov 10, 2009 4:56 am
  • Posts: 2
  • Offline
  • Profile

Re: Drag & Drop with external elements to the list

Post Posted: Wed Nov 25, 2009 3:06 am
+0-
Perfect!
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum