Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. handleDragOver = (dragEvent) => {
  2. if (libraryManager.currentLibrary.isWritable) {
  3. // Would use dragEvent.dataTransfer here, but can't access that in dragOver events
  4. const validDropTargets = this.dropTargets && this.dropTargets[dragManager.dragType] || [];
  5. // Get the offsetTop for the library contents node
  6. const offsetTop = this.libraryContents.getBoundingClientRect() && this.libraryContents.getBoundingClientRect().top;
  7. const draggedY = dragEvent.clientY - offsetTop + this._scrollTop;
  8. const draggedX = dragEvent.clientX;
  9. // Find the dropTarget we are dragging over
  10. // TODO: This needs to be optimized. Slow for a lot of elements.
  11. const activeDropTarget = validDropTargets.find(dropTarget => {
  12. const isInYBounds = draggedY >= dropTarget.y && draggedY <= dropTarget.y + dropTarget.height;
  13. const isInXBounds = draggedX >= dropTarget.x && draggedX <= dropTarget.x + dropTarget.width;
  14.  
  15. return isInYBounds && isInXBounds;
  16. });
  17.  
  18. // Set or reset the drag manager drop target
  19. dragManager.setActiveDropTarget(activeDropTarget);
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement