summaryrefslogtreecommitdiff
path: root/rannak/mangud/kaitseliitlane/kuulsused/script.js
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-09-17 00:17:34 +0300
committerRasmus Luha <rasmus.luha@gmail.com>2022-09-17 00:17:34 +0300
commit2863a49dd0cdae245a741f533c8861c1c8b97fd6 (patch)
treeade3d224162790ed3844f601c7802ee7065683cb /rannak/mangud/kaitseliitlane/kuulsused/script.js
init commit
Diffstat (limited to 'rannak/mangud/kaitseliitlane/kuulsused/script.js')
-rw-r--r--rannak/mangud/kaitseliitlane/kuulsused/script.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/rannak/mangud/kaitseliitlane/kuulsused/script.js b/rannak/mangud/kaitseliitlane/kuulsused/script.js
new file mode 100644
index 0000000..c2ef0d7
--- /dev/null
+++ b/rannak/mangud/kaitseliitlane/kuulsused/script.js
@@ -0,0 +1,71 @@
+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.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 == 8) {
+ const button = document.querySelector(".btn");
+ button.classList.remove('disabled');
+ button.setAttribute('aria-disabled', false);
+ }
+}