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;
}
.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 @@
</head>
<body>
<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>
<a href=# class=view-about>About</a>
<a href=# class=view-license>License</a>
@ -1157,17 +1157,20 @@
<div class=config>
<a href=# class=teaser>&equiv;</a>
<div class=bulk>
<a href=# class=add-board>Add new board...</a>
<a href="#" class=add-board>Add new board...</a>
<div class=boards>
<!-- here'll be boards -->
</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">
<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-fsize">Use <i>smaller</i><b>larger</b> font</a>
<a href="#" class="flush-namespace">Flush namespace</a>
<a href="#" class="switch-namespace">Set namespace</a>
<div class=namespaces>
<!-- here'll be namespaces -->
</div>
</div>
</div>
</div>
@ -1234,6 +1237,7 @@
</div>
<a href=# class=load-board></a>
<a href=# class=load-namespace></a>
<textarea class=encoder></textarea>
@ -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);