improved makeMagicList documentation

This commit is contained in:
ari melody 2024-08-31 15:55:45 +01:00
parent 63122eb428
commit dc0837bfee
Signed by: ari
GPG key ID: CF99829C92678188

View file

@ -1,5 +1,6 @@
/** /**
* Creates a "magic" reorderable list from `container`. * Creates a reorderable list from any `container` and viable list item selector.
*
* This function is absolute magic and I love it * This function is absolute magic and I love it
* *
* Example: * Example:
@ -29,6 +30,8 @@ export function makeMagicList(container, itemSelector, callback) {
item.draggable = true; item.draggable = true;
item.addEventListener("dragstart", () => { item.classList.add("moving") }); item.addEventListener("dragstart", () => { item.classList.add("moving") });
item.addEventListener("dragend", () => { item.classList.remove("moving") }); item.addEventListener("dragend", () => { item.classList.remove("moving") });
// dragging on inputs should take priority
item.querySelectorAll("input").forEach(el => { item.querySelectorAll("input").forEach(el => {
el.addEventListener("mousedown", () => { item.draggable = false }); el.addEventListener("mousedown", () => { item.draggable = false });
el.addEventListener("mouseup", () => { item.draggable = true }); el.addEventListener("mouseup", () => { item.draggable = true });