Replaced the traditional function expressions with ES6 arrow function expressions in the JavaScript for the drop-and-drop reorder.

This commit is contained in:
依瑪貓 2023-03-04 08:18:52 +08:00
parent ca86a08f3e
commit a895bd8560

View File

@ -44,15 +44,15 @@ function initializeMouseDragAndDropReordering(list, onReorder) {
let dragged = null; let dragged = null;
for (const item of items) { for (const item of items) {
item.draggable = true; item.draggable = true;
item.addEventListener("dragstart", function () { item.addEventListener("dragstart", () => {
dragged = item; dragged = item;
dragged.classList.add("accounting-dragged"); dragged.classList.add("accounting-dragged");
}); });
item.addEventListener("dragover", function () { item.addEventListener("dragover", () => {
onDragOver(dragged, item); onDragOver(dragged, item);
onReorder(); onReorder();
}); });
item.addEventListener("dragend", function () { item.addEventListener("dragend", () => {
dragged.classList.remove("accounting-dragged"); dragged.classList.remove("accounting-dragged");
dragged = null; dragged = null;
}); });
@ -69,16 +69,16 @@ function initializeMouseDragAndDropReordering(list, onReorder) {
function initializeTouchDragAndDropReordering(list, onReorder) { function initializeTouchDragAndDropReordering(list, onReorder) {
const items = Array.from(list.children); const items = Array.from(list.children);
for (const item of items) { for (const item of items) {
item.addEventListener("touchstart", function () { item.addEventListener("touchstart", () => {
item.classList.add("accounting-dragged"); item.classList.add("accounting-dragged");
}); });
item.addEventListener("touchmove", function (event) { item.addEventListener("touchmove", (event) => {
const touch = event.targetTouches[0]; const touch = event.targetTouches[0];
const target = document.elementFromPoint(touch.pageX, touch.pageY); const target = document.elementFromPoint(touch.pageX, touch.pageY);
onDragOver(item, target); onDragOver(item, target);
onReorder(); onReorder();
}); });
item.addEventListener("touchend", function () { item.addEventListener("touchend", () => {
item.classList.remove("accounting-dragged"); item.classList.remove("accounting-dragged");
}); });
} }