diff --git a/nullboard.html b/nullboard.html index f32b3e5..a9d0394 100644 --- a/nullboard.html +++ b/nullboard.html @@ -720,7 +720,7 @@ visibility: hidden; } - .config .bulk a.switch-theme { + .config .bulk a.switch-theme a.namespaces { padding-top: 6px; margin-top: 6px; border-top: 1px solid #00000028; @@ -1145,7 +1145,7 @@ + @@ -1490,7 +1494,7 @@ deprefix(key) { - if (key.startsWith(this.namespace + ".")) + if (this.namespace && key.startsWith(this.namespace + ".")) return key.slice(this.namespace.length + 1); return null; } @@ -2660,6 +2664,28 @@ return peek && peek.title; } + function updateNamespaceIndex() + { + var $index = $(['.config', '.namespaces'].join(" ")); + var $entry = $(['tt', '.load-namespace'].join(" ")); + + $index.html(''); + $index.hide(); + + getAllNamespaces().forEach((k) => { + var $e = $entry.clone(); + $e.html( k ); + + if (getCurrentNamespace() == k) + $e.addClass('active'); + + $index.append($e); + empty = false; + }); + + if (! empty) $index.show(); + } + function updateBoardIndex() { var $index = $(['.config', '.boards'].join(" ")); @@ -2942,6 +2968,13 @@ return false; }); + $('.config .load-namespace').live('click', function(){ + var namespace = $(this).html(); + if (getCurrentNamespace() != namespace) + setGlobalStorage(namespace); + return false; + }); + $('.config .load-board').live('click', function(){ var board_id = $(this)[0].board_id; @@ -3076,7 +3109,7 @@ globalStorage.del(k); }); popAllNamespaces(namespace); - setGlobalNamespace(getAllNamespaces()[0]); + setGlobalStorage(getAllNamespaces()[0]); return false; }); @@ -3084,7 +3117,7 @@ var namespace = prompt("Namespace", getCurrentNamespace()); if (namespace != getCurrentNamespace()) { - setGlobalNamespace(namespace); + setGlobalStorage(namespace); return true; } return false; @@ -3226,7 +3259,7 @@ adjustLayout(); } - function setGlobalNamespace(namespace) + function setGlobalStorage(namespace) { try { @@ -3243,6 +3276,8 @@ ); setCurrentNamespace(namespace); + updateNamespaceIndex(); + console.log("set global storage and current namespace to: " + namespace); // if (globalStorage.get('nullboard.theme') == 'dark') @@ -3278,15 +3313,47 @@ function setCurrentNamespace(namespace) { + pushAllNamespaces(namespace); + $('#page-title').html(namespace); return new Local().set("namespace", namespace); } + function popAllNamespaces(namespace) + { + var namespaces = getAllNamespaces(); + var index = namespaces.indexOf(namespace); + if (index == -1) + return; + namespaces.splice(index, 1); + setAllNamespaces(namespaces); + } + + function pushAllNamespaces(namespace) + { + var namespaces = getAllNamespaces(); + if (namespaces.indexOf(namespace) != -1) + return; + namespaces.push(namespace); + setAllNamespaces(namespaces); + } + + function setAllNamespaces(namespaces) + { + new Local().set("namespaces", JSON.stringify(namespaces)); + updateNamespaceIndex(); + } + + function getAllNamespaces() + { + return JSON.parse(new Local().get("namespaces") || '["initial"]') || ["initial"]; + } + function getCurrentNamespace() { - return new Local().get("namespace") || "initial"; + return new Local().get("namespace") || getAllNamespaces[0]; } - setGlobalNamespace(getCurrentNamespace()); + setGlobalStorage(getCurrentNamespace()); // setInterval(adjustListScroller, 100);