From 7c1295bf5dc8f72f4e0e43af72fe67847faadf6f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 13 Jun 2020 15:26:41 +0200 Subject: Add collapse button and store collapse state of each node as cookies. --- src/ws/node.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/ws/node.js') diff --git a/src/ws/node.js b/src/ws/node.js index a8208fd..d79137d 100644 --- a/src/ws/node.js +++ b/src/ws/node.js @@ -94,8 +94,8 @@ Node.prototype.addChild = function(node, insertBeforeId) if(this.children[i].id == insertBeforeId) { this.children.splice(i - 1, 0, node); - // Insert after id, title and add button (ie. + 3) - this.element.insertBefore(node.element, this.element.childNodes[i + 3]); + // Insert after id, title, add button and collapse button (ie. + 4) + this.element.insertBefore(node.element, this.element.childNodes[i + 4]); inserted = true; break; } @@ -148,6 +148,15 @@ Node.prototype.create = function() add_child_button.appendChild(txt_plus); node.appendChild(add_child_button); + var collapse_button = document.createElement("div"); + collapse_button.name = "add_button"; + collapse_button.setAttribute("onclick", "collapse(event)"); + collapse_button.setAttribute("nodeid", this.id); + collapse_button.setAttribute("class", "collapse_button"); + var txt_plus = document.createTextNode("v"); + collapse_button.appendChild(txt_plus); + node.appendChild(collapse_button); + /* var subscribe_button = document.createElement("div"); subscribe_button.name = "subscribe_button"; @@ -173,6 +182,18 @@ Node.prototype.create = function() this.div_id.appendChild(id_txt); this.element.appendChild(this.div_title); this.setAttribute("title", ""); + + { + var collapsed = getCookie(node.id+"_collapsed") == "true"; + if(collapsed) + { + this.element.style.maxHeight = "32px"; + } + else + { + this.element.style.maxHeight = "inherit"; + } + } }; Node.prototype.setAttribute = function(name, value) -- cgit v1.2.3