freifunkmanager/webroot/js/gui.js

44 lines
795 B
JavaScript
Raw Normal View History

import * as domlib from './domlib';
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'),
elMenu = new MenuView();
2017-05-16 19:18:35 +02:00
export {router};
2017-05-16 19:18:35 +02:00
let init = false,
currentView = new View();
2017-05-16 19:18:35 +02:00
export function render () {
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;
}
2017-05-16 19:18:35 +02:00
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
export function setView (toView) {
currentView.unbind();
currentView = toView;
currentView.bind(elMain);
currentView.render();
}