48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
function Screen(modules) {
|
|
var current = document.querySelector("body > div.on");
|
|
var errorBox = document.getElementById('error');
|
|
errorBox.addEventListener('click', function() {
|
|
errorBox.className = "";
|
|
});
|
|
|
|
return {
|
|
error: error,
|
|
dialog: dialog,
|
|
select: select
|
|
};
|
|
|
|
function select(name) {
|
|
current.className = "";
|
|
current = document.getElementById(name);
|
|
current.className = "on";
|
|
}
|
|
|
|
function closeAndRun(dialog, action) {
|
|
return function() {
|
|
dialog.className = '';
|
|
modules.dom.clear(dialog);
|
|
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) {
|
|
answers.appendChild(modules.dom.make('button', {
|
|
textContent: modules.i18n.get(config.answers[i].label),
|
|
onClick: closeAndRun(layer, config.answers[i].action)
|
|
}));
|
|
}
|
|
dialog.appendChild(answers);
|
|
layer.appendChild(dialog);
|
|
layer.className = "on";
|
|
}
|
|
|
|
function error(message) {
|
|
errorBox.textContent = message;
|
|
errorBox.className = "on";
|
|
}
|
|
}
|