-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95b5670
commit 2feda2e
Showing
2 changed files
with
47 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import KanbanAPI from "../api/KanbanAPI.js"; | ||
|
||
export default class DropZone { | ||
static createDropZone() { | ||
const range = document.createRange(); | ||
|
||
range.selectNode(document.body); | ||
|
||
const dropZone = range.createContextualFragment(` | ||
<div class="dropzone"></div> | ||
`).children[0]; | ||
|
||
dropZone.addEventListener("dragover", e => { | ||
e.preventDefault(); | ||
dropZone.classList.add("dropzone-active"); | ||
}); | ||
|
||
dropZone.addEventListener("dragleave", () => { | ||
dropZone.classList.remove("dropzone-active"); | ||
}); | ||
|
||
dropZone.addEventListener("drop", e => { | ||
e.preventDefault(); | ||
dropZone.classList.remove("dropzone-active"); | ||
|
||
const columnElement = dropZone.closest(".columns"); | ||
const columnId = Number(columnElement.dataset.id); | ||
const dropZonesInColumn = Array.from(columnElement.querySelectorAll(".dropzone")); | ||
const droppedIndex = dropZonesInColumn.indexOf(dropZone); | ||
const itemId = Number(e.dataTransfer.getData("text/plain")); | ||
const droppedItemElement = document.querySelector(`[data-id="${itemId}"]`); | ||
const insertAfter = dropZone.parentElement.classList.contains("items") ? dropZone.parentElement : dropZone; | ||
|
||
if (droppedItemElement.contains(dropZone)) { | ||
return; | ||
} | ||
|
||
insertAfter.after(droppedItemElement); | ||
KanbanAPI.updateItem(itemId, { | ||
columnId, | ||
position: droppedIndex | ||
}); | ||
}); | ||
|
||
return dropZone; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +0,0 @@ | ||
import KanbanAPI from "../api/KanbanAPI.js"; | ||
|
||
export default class DropZone { | ||
static createDropZone() { | ||
const range = document.createRange(); | ||
|
||
range.selectNode(document.body); | ||
|
||
const dropZone = range.createContextualFragment(` | ||
<div class="dropzone"></div> | ||
`).children[0]; | ||
|
||
dropZone.addEventListener("dragover", e => { | ||
e.preventDefault(); | ||
dropZone.classList.add("dropzone-active"); | ||
}); | ||
|
||
dropZone.addEventListener("dragleave", () => { | ||
dropZone.classList.remove("dropzone-active"); | ||
}); | ||
|
||
dropZone.addEventListener("drop", e => { | ||
e.preventDefault(); | ||
dropZone.classList.remove("dropzone-active"); | ||
|
||
const columnElement = dropZone.closest(".columns"); | ||
const columnId = Number(columnElement.dataset.id); | ||
const dropZonesInColumn = Array.from(columnElement.querySelectorAll(".dropzone")); | ||
const droppedIndex = dropZonesInColumn.indexOf(dropZone); | ||
const itemId = Number(e.dataTransfer.getData("text/plain")); | ||
const droppedItemElement = document.querySelector(`[data-id="${itemId}"]`); | ||
const insertAfter = dropZone.parentElement.classList.contains("items") ? dropZone.parentElement : dropZone; | ||
|
||
if (droppedItemElement.contains(dropZone)) { | ||
return; | ||
} | ||
|
||
insertAfter.after(droppedItemElement); | ||
KanbanAPI.updateItem(itemId, { | ||
columnId, | ||
position: droppedIndex | ||
}); | ||
}); | ||
|
||
return dropZone; | ||
} | ||
} | ||