Skip to content

Commit c022361

Browse files
author
jasonford
committed
dropped event for touches too
1 parent 8f22373 commit c022361

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/ClientEvents.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,45 @@ window.addEventListener("load", function () {
301301
});
302302
endEvent.target.dispatchEvent(swipeleftEvent);
303303
}
304+
var targetData = {};
304305
var dropEvent = customEvent('drop', {
305306
dx : lastX,
306307
dy : lastY,
308+
targetData : targetData,
307309
swiped : swiped
308310
});
309311
startEvent.target.dispatchEvent(dropEvent);
312+
let hiddenElements = [];
313+
function getDroppedElement(element) {
314+
element.style.display = "none";
315+
hiddenElements.push(element);
316+
requestAnimationFrame(function () {
317+
var elementUnderCursor = document.elementFromPoint(lastX, lastY);
318+
if (element.contains(elementUnderCursor)) {
319+
getDroppedElement(element.parent);
320+
}
321+
else {
322+
if (element) {
323+
// dropped event on element
324+
var droppedEvent = customEvent('dropped', {
325+
x : lastX,
326+
y : lastY,
327+
targetData : targetData,
328+
dx : lastX - startX,
329+
dy : lastY - startY,
330+
swiped : swiped
331+
});
332+
elementUnderCursor.dispatchEvent(droppedEvent)
333+
}
334+
// undo the display="none" we did to get here
335+
hiddenElements.forEach(function (hiddenElement) {
336+
hiddenElement.style.display = null;
337+
});
338+
}
339+
});
340+
}
341+
// get element not in path of given element and under drop
342+
getDroppedElement(startEvent.target);
310343
});
311344
});
312345

@@ -409,13 +442,13 @@ window.addEventListener("load", function () {
409442
var hiddenElements = [];
410443
// disable events on currentTarget while it and its parent is under the event
411444
// so we can trigger a dropped event on the first element that is not an ancestor
412-
function getDroppedElement(element, cb) {
445+
function getDroppedElement(element) {
413446
element.style.display = "none";
414447
hiddenElements.push(element);
415448
requestAnimationFrame(function () {
416449
var elementUnderCursor = document.elementFromPoint(lastX, lastY);
417450
if (element.contains(elementUnderCursor)) {
418-
getDroppedElement(element.parent, cb);
451+
getDroppedElement(element.parent);
419452
}
420453
else {
421454
if (element) {
@@ -438,9 +471,7 @@ window.addEventListener("load", function () {
438471
});
439472
}
440473
// get element not in path of given element and under drop
441-
getDroppedElement(startTarget, function (element) {
442-
console.log('drop on', element)
443-
});
474+
getDroppedElement(startTarget);
444475
});
445476
});
446477
});

0 commit comments

Comments
 (0)