From e32738a622996fe118533ca0c8b1b07b7fbd6a3c Mon Sep 17 00:00:00 2001 From: Andrew Lorimer Date: Sat, 17 Aug 2019 23:02:03 +1000 Subject: [PATCH] fix bug where settings did not save in edit mode due to textbox replacing title --- admin.js | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/admin.js b/admin.js index 96e4d46..224e692 100644 --- a/admin.js +++ b/admin.js @@ -39,11 +39,22 @@ function columnToArray(list) { function listToArray(list) { var l = []; - console.log(list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent); - l[0] = list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent; + console.log("looking at list:"); + console.log(list); + if (editMode == true) { + l[0] = list.getElementsByClassName('title')[0].getElementsByTagName("input")[0].value; + } + else { + l[0] = list.getElementsByClassName('title')[0].getElementsByTagName("p")[0].textContent; + } var elem = list.getElementsByTagName("li"); for (var i = 0; i < elem.length; ++i) { - l[i+1] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")]; + if (elem[i].class == "new") { + continue; + } + else { + l[i+1] = [elem[i].getElementsByTagName("a")[0].innerText, elem[i].getElementsByTagName("a")[0].getAttribute("href")]; + } } return l; } @@ -58,16 +69,36 @@ var userListsCallback = function(lists) { document.getElementById('addcol').addEventListener('click', addCol, false); var ul = document.createElement("ul"); ul.setAttribute("id", mainlist[i]); - ul.setAttribute('draggable', 'true'); - ul.addEventListener('dragstart', dragStart, false); - ul.addEventListener('dragenter', dragEnter, false); - ul.addEventListener('dragover', dragOver, false); - ul.addEventListener('dragleave', dragLeave, false); - ul.addEventListener('drop', drop, false); + ul.setAttribute('draggable', 'false'); // Draggable attribute must be set on mousedown event, otherwise any cursor movement causes dragstart() document.getElementById("links").appendChild(ul); var grip = document.createElement("span"); grip.setAttribute("class", "grip"); + grip.addEventListener('mousedown', function() { + console.log("Drag started"); + uls = document.getElementsByTagName("ul"); + for (let ul of uls) { + ul.setAttribute("draggable", "true"); + ul.addEventListener('dragstart', dragStart, false); + ul.addEventListener('dragenter', dragEnter, false); + ul.addEventListener('dragover', dragOver, false); + ul.addEventListener('dragleave', dragLeave, false); + ul.addEventListener('drop', drop, false); + } + }); + + grip.addEventListener('mouseup', function() { + console.log("Drag ended"); + uls = document.getElementsByTagName("ul"); + for (let ul of uls) { + ul.setAttribute("draggable", "false"); + ul.removeEventListener('dragstart'); + ul.removeEventListener('dragenter'); + ul.removeEventListener('dragover'); + ul.removeEventListener('dragleave'); + ul.removeEventListener('drop'); + } + }); var title = document.createElement("div"); title.setAttribute("class", "title"); @@ -199,6 +230,7 @@ function edit() { } function closeEdit(editbtn) { + editMode = false; editbtn.style.background = ""; editbtn.innerText = "e"; addbtn = document.getElementById("addcol"); @@ -218,7 +250,6 @@ function closeEdit(editbtn) { col.getElementsByClassName("grip")[0].style.display = "none"; } save(); - editMode = false; } function addCol() { @@ -308,6 +339,8 @@ function addItem(caller, li) { var span = document.getElementById("input-"+columnToArray(li).length.toString()); var form = document.getElementById("form-"+columnToArray(li).length.toString()); span.addEventListener('click', function(event){ + console.log("Adding item to:"); + console.log(this); var li = document.getElementsByClassName("new")[0] var ul = li.parentNode; if (li.getElementsByClassName("name")[0].value != "" && li.getElementsByClassName("url")[0].value != "" && li.getElementsByClassName("url")[0].validity.typeMismatch== false) { -- 2.47.1