freifunkmanager/webroot/js/gui.js

52 lines
989 B
JavaScript
Raw Normal View History

import * as domlib from './domlib';
import * as lib from './lib';
import {MenuView} from './element/menu';
import Navigo from '../node_modules/navigo/lib/navigo';
import View from './view';
import {singelton as notify} from './element/notify';
2017-05-16 19:18:35 +02:00
const router = new Navigo(null, true, '#'),
elMain = domlib.newEl('main'),
2018-07-17 23:54:11 +02:00
elMenu = new MenuView(),
GUI_RENDER_DEBOUNCER_TIME = 100;
2017-05-16 19:18:35 +02:00
export {router};
2017-05-16 19:18:35 +02:00
let init = false,
currentView = new View(),
debouncer = new lib.Debouncer(GUI_RENDER_DEBOUNCER_TIME, "gui render");
export function render () {
debouncer.run(renderView);
}
2017-05-16 19:18:35 +02:00
2018-07-17 23:54:11 +02:00
function renderView () {
if (!document.body) {
return;
2017-05-16 19:18:35 +02:00
}
if (!init) {
elMenu.bind(document.body);
notify.bind(document.body);
2017-05-16 19:18:35 +02:00
document.body.appendChild(elMain);
2017-05-16 19:18:35 +02:00
init = true;
}
currentView.render();
2017-05-16 19:18:35 +02:00
notify.render();
elMenu.render();
2017-05-16 19:18:35 +02:00
router.resolve();
}
2017-05-16 19:18:35 +02:00
2018-07-17 23:54:11 +02:00
export function setView (toView) {
currentView.unbind();
currentView = toView;
currentView.bind(elMain);
currentView.render();
}