+var editMode = false;
+
+function edit() {
+ if (editMode == true) {
+ console.log("Exited edit mode");
+ closeEdit(this);
+ return 0;
+ }
+ console.log("Entered edit mode");
+ this.style.background = hovergrn;
+ this.innerText = tick;
+ addbtn = document.getElementById("addcol");
+ addbtn.style.display = "flex";
+ var cols = document.getElementsByTagName("ul");
+ for (let col of cols) {
+ title = col.getElementsByClassName("title")[0];
+ rmbutton = document.createElement("span");
+ rmbutton.setAttribute("class", "rmcol");
+ rmbutton.setAttribute("id", "rmcol-"+col.id);
+ rmbutton.innerText = "-";
+ rmbutton.addEventListener('click', function(event){
+ console.log("Deleting column " + this.parentNode.parentNode);
+ this.parentNode.parentNode.remove();
+ var index = mainlist.indexOf(this.parentNode.parentNode.id);
+ console.log("Found deleted node " + this.parentNode.parentNode.id + " at index " + index);
+ if (index > -1) {
+ mainlist.splice(index, 1);
+ }
+ save();
+ });
+ title.appendChild(rmbutton);
+ title.getElementsByClassName("add")[0].style.display = "flex";
+ title.getElementsByTagName("p")[0].style.width = "calc(100% - 90px)";
+ }
+ editMode = true;
+}
+
+function closeEdit(editbtn) {
+ editbtn.style.background = hoverbg;
+ editbtn.innerText = "e";
+ addbtn = document.getElementById("addcol");
+ addbtn.style.display = "none";
+ var cols = document.getElementsByTagName("ul");
+ for (let col of cols) {
+ rmbutton = col.getElementsByClassName("title")[0].getElementsByClassName("rmcol")[0];
+ rmbutton.remove();
+ title = col.getElementsByClassName("title")[0];
+ title.getElementsByClassName("add")[0].style.display = "";
+ title.getElementsByTagName("p")[0].style.width = "calc(100% - 45px)";
+ }
+ editMode = false;
+}
+
+function addCol() {
+ var ul = document.createElement("ul");
+ ul.setAttribute("id", "new-category");
+ 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);
+ document.getElementById("links").appendChild(ul);
+
+ var grip = document.createElement("span");
+ grip.setAttribute("class", "grip");
+
+ var title = document.createElement("div");
+ title.setAttribute("class", "title");
+ title.appendChild(grip)
+ ul.appendChild(title);
+
+ var p = document.createElement("p");
+ p.innerText = "new-category";
+ title.appendChild(p);
+
+ title.insertAdjacentHTML("beforeend", "<span class='add' id='add-new-category'>+</span>");
+
+ rmbutton = document.createElement("span");
+ rmbutton.setAttribute("class", "rmcol");
+ rmbutton.setAttribute("id", "rmcol-new-category");
+ rmbutton.innerText = "-";
+ rmbutton.addEventListener('click', function(event){
+ console.log("Deleting column " + this.parentNode.parentNode);
+ this.parentNode.parentNode.remove();
+ var index = mainlist.indexOf(this.parentNode.parentNode.id);
+ console.log("Found deleted node " + this.parentNode.parentNode.id + " at index " + index);
+ if (index > -1) {
+ mainlist.splice(index, 1);
+ }
+ save();
+ });
+ title.appendChild(rmbutton);
+ title.getElementsByClassName("add")[0].style.display = "flex";
+ title.getElementsByTagName("p")[0].style.width = "calc(100% - 90px)";
+
+ listen(title.getElementsByClassName("add")[0]);
+ save();
+}
+