server/www/screen.js

39 lines
1,022 B
JavaScript
Raw Permalink Normal View History

2018-08-02 00:00:13 +02:00
function Screen(modules) {
var current = document.querySelector("body > div.on");
return {
2018-08-02 00:00:13 +02:00
dialog: dialog,
select: select
};
function select(name) {
current.className = "";
current = document.getElementById(name);
current.className = "on";
}
2018-08-02 00:00:13 +02:00
function closeAndRun(dialog, action) {
return function() {
dialog.className = '';
modules.dom.clear(dialog);
2018-08-02 00:00:13 +02:00
action();
};
}
function dialog(config) {
var layer = document.getElementById('dialog');
var dialog = modules.dom.make('div', {});
dialog.appendChild(modules.dom.make('p', {textContent: config.text}));
var answers = modules.dom.make('p', {class: 'answers'});
for(var i in config.answers) {
2018-08-02 00:00:13 +02:00
answers.appendChild(modules.dom.make('button', {
textContent: modules.i18n.get(config.answers[i].label),
onClick: closeAndRun(layer, config.answers[i].action)
2018-08-02 00:00:13 +02:00
}));
}
dialog.appendChild(answers);
layer.appendChild(dialog);
layer.className = "on";
}
}