List global namespaces, set title to active

master
Bel LaPointe 2021-02-28 00:58:05 -06:00
parent 94776831d8
commit 3b9fd7a543
1 changed files with 78 additions and 11 deletions

View File

@ -720,7 +720,7 @@
visibility: hidden; visibility: hidden;
} }
.config .bulk a.switch-theme { .config .bulk a.switch-theme a.namespaces {
padding-top: 6px; padding-top: 6px;
margin-top: 6px; margin-top: 6px;
border-top: 1px solid #00000028; border-top: 1px solid #00000028;
@ -1145,7 +1145,7 @@
</head> </head>
<body> <body>
<div class=logo> <div class=logo>
<a href=https://nullboard.io>Nullboard <span id="pending"></span></a> <a href="#"><span id="page-title">Nullboard</span> <span id="pending"></span></a>
<div class=bulk> <div class=bulk>
<a href=# class=view-about>About</a> <a href=# class=view-about>About</a>
<a href=# class=view-license>License</a> <a href=# class=view-license>License</a>
@ -1157,17 +1157,20 @@
<div class=config> <div class=config>
<a href=# class=teaser>&equiv;</a> <a href=# class=teaser>&equiv;</a>
<div class=bulk> <div class=bulk>
<a href=# class=add-board>Add new board...</a> <a href="#" class=add-board>Add new board...</a>
<div class=boards> <div class=boards>
<!-- here'll be boards --> <!-- here'll be boards -->
</div> </div>
<a href=# class=imp-board>Import board...</a> <a href="#" class=imp-board>Import board...</a>
<input class=imp-board-select type="file" accept=".nbx"> <input class=imp-board-select type="file" accept=".nbx">
<a href=# class=exp-board>Export board...</a> <a href="#" class=exp-board>Export board...</a>
<a href="#" class="switch-theme">Use <i>light</i><b>dark</b> theme</a> <a href="#" class="switch-theme">Use <i>light</i><b>dark</b> theme</a>
<a href="#" class="switch-fsize">Use <i>smaller</i><b>larger</b> font</a> <a href="#" class="switch-fsize">Use <i>smaller</i><b>larger</b> font</a>
<a href="#" class="flush-namespace">Flush namespace</a> <a href="#" class="flush-namespace">Flush namespace</a>
<a href="#" class="switch-namespace">Set namespace</a> <a href="#" class="switch-namespace">Set namespace</a>
<div class=namespaces>
<!-- here'll be namespaces -->
</div>
</div> </div>
</div> </div>
</div> </div>
@ -1234,6 +1237,7 @@
</div> </div>
<a href=# class=load-board></a> <a href=# class=load-board></a>
<a href=# class=load-namespace></a>
<textarea class=encoder></textarea> <textarea class=encoder></textarea>
@ -1490,7 +1494,7 @@
deprefix(key) deprefix(key)
{ {
if (key.startsWith(this.namespace + ".")) if (this.namespace && key.startsWith(this.namespace + "."))
return key.slice(this.namespace.length + 1); return key.slice(this.namespace.length + 1);
return null; return null;
} }
@ -2660,6 +2664,28 @@
return peek && peek.title; 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() function updateBoardIndex()
{ {
var $index = $(['.config', '.boards'].join(" ")); var $index = $(['.config', '.boards'].join(" "));
@ -2942,6 +2968,13 @@
return false; 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(){ $('.config .load-board').live('click', function(){
var board_id = $(this)[0].board_id; var board_id = $(this)[0].board_id;
@ -3076,7 +3109,7 @@
globalStorage.del(k); globalStorage.del(k);
}); });
popAllNamespaces(namespace); popAllNamespaces(namespace);
setGlobalNamespace(getAllNamespaces()[0]); setGlobalStorage(getAllNamespaces()[0]);
return false; return false;
}); });
@ -3084,7 +3117,7 @@
var namespace = prompt("Namespace", getCurrentNamespace()); var namespace = prompt("Namespace", getCurrentNamespace());
if (namespace != getCurrentNamespace()) if (namespace != getCurrentNamespace())
{ {
setGlobalNamespace(namespace); setGlobalStorage(namespace);
return true; return true;
} }
return false; return false;
@ -3226,7 +3259,7 @@
adjustLayout(); adjustLayout();
} }
function setGlobalNamespace(namespace) function setGlobalStorage(namespace)
{ {
try try
{ {
@ -3243,6 +3276,8 @@
); );
setCurrentNamespace(namespace); setCurrentNamespace(namespace);
updateNamespaceIndex();
console.log("set global storage and current namespace to: " + namespace);
// //
if (globalStorage.get('nullboard.theme') == 'dark') if (globalStorage.get('nullboard.theme') == 'dark')
@ -3278,15 +3313,47 @@
function setCurrentNamespace(namespace) function setCurrentNamespace(namespace)
{ {
pushAllNamespaces(namespace);
$('#page-title').html(namespace);
return new Local().set("namespace", 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() function getCurrentNamespace()
{ {
return new Local().get("namespace") || "initial"; return new Local().get("namespace") || getAllNamespaces[0];
} }
setGlobalNamespace(getCurrentNamespace()); setGlobalStorage(getCurrentNamespace());
// //
setInterval(adjustListScroller, 100); setInterval(adjustListScroller, 100);