2018-08-02 00:00:13 +02:00
|
|
|
function Screen(modules) {
|
2018-05-11 12:31:53 +02:00
|
|
|
var current = document.querySelector("body > div.on");
|
|
|
|
|
|
|
|
return {
|
2018-08-02 00:00:13 +02:00
|
|
|
dialog: dialog,
|
2018-05-11 12:31:53 +02:00
|
|
|
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 = '';
|
2018-08-26 21:56:54 +02:00
|
|
|
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'});
|
2019-01-01 12:57:27 +01:00
|
|
|
for(var i in config.answers) {
|
2018-08-02 00:00:13 +02:00
|
|
|
answers.appendChild(modules.dom.make('button', {
|
2019-01-01 12:57:27 +01:00
|
|
|
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";
|
|
|
|
}
|
2018-05-11 12:31:53 +02:00
|
|
|
}
|