2020-06-05 22:03:37 +00:00
|
|
|
|
"use strict";
|
2016-06-13 20:34:39 +00:00
|
|
|
|
|
2020-06-05 22:03:37 +00:00
|
|
|
|
const events = require("../events.js");
|
|
|
|
|
const api = require("../api.js");
|
2016-06-13 20:34:39 +00:00
|
|
|
|
|
|
|
|
|
class TopNavigationItem {
|
|
|
|
|
constructor(accessKey, title, url, available, imageUrl) {
|
|
|
|
|
this.accessKey = accessKey;
|
|
|
|
|
this.title = title;
|
|
|
|
|
this.url = url;
|
|
|
|
|
this.available = available === undefined ? true : available;
|
|
|
|
|
this.imageUrl = imageUrl === undefined ? null : imageUrl;
|
|
|
|
|
this.key = null;
|
|
|
|
|
}
|
2020-06-04 18:09:35 +00:00
|
|
|
|
}
|
2016-06-13 20:34:39 +00:00
|
|
|
|
|
|
|
|
|
class TopNavigation extends events.EventTarget {
|
|
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
this.activeItem = null;
|
|
|
|
|
this._keyToItem = new Map();
|
|
|
|
|
this._items = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAll() {
|
|
|
|
|
return this._items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get(key) {
|
|
|
|
|
if (!this._keyToItem.has(key)) {
|
|
|
|
|
throw `An item with key ${key} does not exist.`;
|
|
|
|
|
}
|
|
|
|
|
return this._keyToItem.get(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add(key, item) {
|
|
|
|
|
item.key = key;
|
|
|
|
|
if (this._keyToItem.has(key)) {
|
|
|
|
|
throw `An item with key ${key} was already added.`;
|
|
|
|
|
}
|
|
|
|
|
this._keyToItem.set(key, item);
|
|
|
|
|
this._items.push(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
activate(key) {
|
|
|
|
|
this.activeItem = null;
|
2020-06-05 22:03:37 +00:00
|
|
|
|
this.dispatchEvent(
|
|
|
|
|
new CustomEvent("activate", {
|
|
|
|
|
detail: {
|
|
|
|
|
key: key,
|
|
|
|
|
item: key ? this.get(key) : null,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
);
|
2016-06-13 20:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-13 19:50:07 +00:00
|
|
|
|
setTitle(title) {
|
2018-06-25 14:47:20 +00:00
|
|
|
|
api.fetchConfig().then(() => {
|
|
|
|
|
document.oldTitle = null;
|
2020-06-05 22:03:37 +00:00
|
|
|
|
document.title = api.getName() + (title ? " – " + title : "");
|
2018-06-25 14:47:20 +00:00
|
|
|
|
});
|
2016-07-13 19:50:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 20:34:39 +00:00
|
|
|
|
showAll() {
|
|
|
|
|
for (let item of this._items) {
|
|
|
|
|
item.available = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
show(key) {
|
|
|
|
|
this.get(key).available = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hide(key) {
|
|
|
|
|
this.get(key).available = false;
|
|
|
|
|
}
|
2020-06-04 18:09:35 +00:00
|
|
|
|
}
|
2016-06-13 20:34:39 +00:00
|
|
|
|
|
|
|
|
|
function _makeTopNavigation() {
|
|
|
|
|
const ret = new TopNavigation();
|
2020-06-05 22:03:37 +00:00
|
|
|
|
ret.add("home", new TopNavigationItem("H", "Home", ""));
|
|
|
|
|
ret.add("posts", new TopNavigationItem("P", "Posts", "posts"));
|
|
|
|
|
ret.add("upload", new TopNavigationItem("U", "Upload", "upload"));
|
|
|
|
|
ret.add("comments", new TopNavigationItem("C", "Comments", "comments"));
|
|
|
|
|
ret.add("tags", new TopNavigationItem("T", "Tags", "tags"));
|
|
|
|
|
ret.add("pools", new TopNavigationItem("O", "Pools", "pools"));
|
|
|
|
|
ret.add("users", new TopNavigationItem("S", "Users", "users"));
|
|
|
|
|
ret.add("account", new TopNavigationItem("A", "Account", "user/{me}"));
|
|
|
|
|
ret.add("register", new TopNavigationItem("R", "Register", "register"));
|
|
|
|
|
ret.add("login", new TopNavigationItem("L", "Log in", "login"));
|
|
|
|
|
ret.add("logout", new TopNavigationItem("O", "Logout", "logout"));
|
|
|
|
|
ret.add("help", new TopNavigationItem("E", "Help", "help"));
|
2016-06-13 20:34:39 +00:00
|
|
|
|
ret.add(
|
2020-06-05 22:03:37 +00:00
|
|
|
|
"settings",
|
|
|
|
|
new TopNavigationItem(null, "<i class='fa fa-cog'></i>", "settings")
|
|
|
|
|
);
|
2016-06-13 20:34:39 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = _makeTopNavigation();
|