EventDragUtils.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getRectCenter, intersectRects } from '../lib/geom'
  2. import * as EventRenderUtils from '../event-render/EventRenderUtils'
  3. /*
  4. TODO: Don't rely on legacy simulateDrag
  5. Given the rectangles of the origin and destination
  6. slot or day area.
  7. */
  8. export function drag(rect0, rect1, debug) {
  9. var el = EventRenderUtils.getSingleEl()
  10. var elRect = el[0].getBoundingClientRect()
  11. var point0 = getRectCenter(
  12. intersectRects(elRect, rect0)
  13. )
  14. var point1 = getRectCenter(rect1)
  15. var deferred = $.Deferred()
  16. el.simulate('drag', {
  17. point: point0,
  18. end: point1,
  19. debug: debug
  20. })
  21. currentCalendar.on('eventDragStop', function() {
  22. setTimeout(function() {
  23. deferred.resolve({ isSuccess: false }) // won't do anything if already eventDrop
  24. }, 200) // will happen after eventDrop's timeout
  25. })
  26. currentCalendar.on('eventDrop', function(event) { // always called after eventDragStop, if success
  27. setTimeout(function() {
  28. deferred.resolve({ isSuccess: true, event: event })
  29. }, 100) // will happen first
  30. })
  31. return deferred.promise()
  32. }
  33. // makes the setTimeout's work.
  34. // also makes the tests faster.
  35. pushOptions({
  36. dragRevertDuration: 0
  37. })