Drop target within a drop target

57 views
Skip to first unread message

Rich Franzmeier

unread,
Aug 18, 2016, 11:10:11 AM8/18/16
to threedubmedia
I have a drop target within a drop target...think of a calendar (FullCalendar) day having a trash can icon within it.  I can either drop something on the day or on the trash can icon.

This is what is happening now:
  • The first time I get the calendar events, I do the drag/drop binding and I can drop something on the trash can icon
  • Once an update is done to remove the item, I can no longer drop anything on the trash can icon
  • I noticed that the order of the available array items for drop targets matter
    • If the trash can icon is the first in the available array, it works (this is the way it is the first time thru)
    • If the trash can icon is last in the available array, it doesn't work (this is the way it is after a refresh)
Is there any way to get these available array items to load in the same order every time?

I'll work on a sample but I'm not sure it will be possible.

Thanks for any help you can provide.

mike.helgeson

unread,
Aug 18, 2016, 11:44:02 AM8/18/16
to threedubmedia
Not the most elegant solution, but you could set a custom/global "tolerance" function, using the static "$.drop" method. The tolerance function is used to score each drop target, the highest score means it will win. 

If the mouse is inside an element, use it's number of parents to determine it's depth, so that more deeply nested elements will become activated first. 
$.drop({
  tolerance: function( event, proxy, target ){
    // use the cursor and dom depth to determine tolerance
    return this.contains( target, [ event.pageX, event.pageY ] ) 
      ? $( target.elem ).parents().length : 0;
  }
});

Or control the outcome based on a specific selector.
$.drop({
  tolerance: function( event, proxy, target ){
    // use a selector to determine tolerance
    return this.contains( target, [ event.pageX, event.pageY ] ) 
      ? $( target.elem ).is('.trash') ? 2 : 1 : 0;
  }
});

Good Luck.

Rich Franzmeier

unread,
Aug 18, 2016, 11:47:40 AM8/18/16
to threedubmedia
I tried your second suggestion and it worked!  Thank you so much, I've been spending a full day on this issue!
Reply all
Reply to author
Forward
0 new messages