From 85c0341a0813556749bc5d34fe35fe8a18f1f5a8 Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Sun, 30 Oct 2022 15:19:30 +0200 Subject: ajatelg done, add to index --- rannak/mangud/uliopilane/ajatelg/script.js | 72 ++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'rannak/mangud/uliopilane/ajatelg/script.js') diff --git a/rannak/mangud/uliopilane/ajatelg/script.js b/rannak/mangud/uliopilane/ajatelg/script.js index e69de29..5c667a5 100644 --- a/rannak/mangud/uliopilane/ajatelg/script.js +++ b/rannak/mangud/uliopilane/ajatelg/script.js @@ -0,0 +1,72 @@ +const list_items = document.querySelectorAll(".list-item"); +const lists = document.querySelectorAll(".list"); + +let draggedItem = null; + +for (let i=0; i < list_items.length; i++){ + const item = list_items[i]; + + /* Event Listeners */ + item.addEventListener("dragstart", e => { + draggedItem = item; + setTimeout(() => (item.style.display = "none"), 0); + }); + + item.addEventListener("dragend", e => { + setTimeout(() => { + draggedItem.style.display = "block"; + draggedItem = null}, 0); + checkIfAllGood(); + }); + + for (let j=0; j < lists.length; j++){ + const list = lists[j]; + + + /* Event Listeners */ + list.addEventListener("dragenter",e => (e.preventDefault())); + + list.addEventListener("dragover",e => { + e.preventDefault(); + //list.style.backgroundColor = "rgba(0,0,0,0.5)"; + }); + + + list.addEventListener("dragleave",e => { + //list.style.backgroundColor = "rgba(0,0,0,0.3)"; + }); + + + list.addEventListener("drop",e => { + if ((list.children.length == 0 && list.id ==draggedItem.id) || list.className.includes("startBasket")) + list.append(draggedItem); + //list.style.backgroundColor = "rgba(0,0,0,0.5)"; + }) + } + +} + +function checkIfAllGood(){ + let rightDone = []; + + for (let j=0; j < lists.length; j++){ + const list = lists[j]; + if (list.className.includes("startBasket")){ + continue; + } + else if (list.children.length == 1){ + if (list.id == list.children[0].id){ + if (!rightDone.includes(list.id)) + rightDone.push(list.id); + console.log(rightDone.length); + console.log(rightDone); + } + } + } // For loop end + + if (rightDone.length == 12) { + const btn = document.querySelector(".moveOn"); + btn.disabled = false; + btn.onclick = () => location.href = ""; + } +} -- cgit v1.2.3