2019-03-22 22:35:04 +08:00
|
|
|
import * as nav from "./nav.js";
|
|
|
|
import * as mpd from "./lib/mpd.js";
|
2019-03-21 17:32:58 +08:00
|
|
|
import * as player from "./player.js";
|
2019-03-29 05:52:57 +08:00
|
|
|
import * as html from "./lib/html.js";
|
2019-04-25 22:09:48 +08:00
|
|
|
import * as range from "./lib/range.js";
|
2019-03-22 22:35:04 +08:00
|
|
|
|
|
|
|
import * as queue from "./queue.js";
|
2019-03-25 22:49:23 +08:00
|
|
|
import * as library from "./library.js";
|
|
|
|
import * as fs from "./fs.js";
|
2019-03-28 22:23:28 +08:00
|
|
|
import * as playlists from "./playlists.js";
|
2019-03-29 04:43:18 +08:00
|
|
|
import * as yt from "./yt.js";
|
2019-04-03 01:52:53 +08:00
|
|
|
import * as settings from "./settings.js";
|
2019-03-22 22:35:04 +08:00
|
|
|
|
2019-04-03 01:52:53 +08:00
|
|
|
const components = { queue, library, fs, playlists, yt, settings };
|
2019-03-22 22:35:04 +08:00
|
|
|
|
|
|
|
export function activate(what) {
|
2019-03-29 05:52:57 +08:00
|
|
|
location.hash = what;
|
|
|
|
|
2019-03-22 22:35:04 +08:00
|
|
|
for (let id in components) {
|
|
|
|
let node = document.querySelector(`#${id}`);
|
|
|
|
if (what == id) {
|
|
|
|
node.style.display = "";
|
|
|
|
components[id].activate();
|
|
|
|
} else {
|
|
|
|
node.style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nav.active(what);
|
|
|
|
}
|
2019-03-20 03:45:23 +08:00
|
|
|
|
2019-03-29 05:52:57 +08:00
|
|
|
function initIcons() {
|
|
|
|
Array.from(document.querySelectorAll("[data-icon]")).forEach(node => {
|
|
|
|
let icon = html.icon(node.dataset.icon);
|
|
|
|
node.insertBefore(icon, node.firstChild);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-29 23:28:26 +08:00
|
|
|
function fromHash() {
|
|
|
|
let hash = location.hash.substring(1);
|
|
|
|
activate(hash || "queue");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onHashChange(e) {
|
|
|
|
fromHash();
|
|
|
|
}
|
|
|
|
|
2019-03-20 03:45:23 +08:00
|
|
|
async function init() {
|
2019-03-29 05:52:57 +08:00
|
|
|
initIcons();
|
2019-04-12 19:34:28 +08:00
|
|
|
try {
|
|
|
|
await mpd.init();
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2019-03-26 19:35:47 +08:00
|
|
|
|
2019-03-22 22:35:04 +08:00
|
|
|
nav.init(document.querySelector("nav"));
|
|
|
|
for (let id in components) {
|
|
|
|
let node = document.querySelector(`#${id}`);
|
|
|
|
components[id].init(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
player.init(document.querySelector("#player"));
|
2019-03-29 23:28:26 +08:00
|
|
|
window.addEventListener("hashchange", onHashChange);
|
|
|
|
fromHash();
|
2019-03-20 03:45:23 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 22:35:04 +08:00
|
|
|
|
2019-03-20 03:45:23 +08:00
|
|
|
init();
|
2020-03-09 01:06:54 +08:00
|
|
|
|
|
|
|
class App extends HTMLElement {
|
|
|
|
get mpd() { return mpd; }
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define("cyp-app", App);
|