refactored code and added win/lose popups

This commit is contained in:
Nathan DECHER
2020-04-05 16:14:39 +02:00
parent 40ec4fa09a
commit 4746f34537
6 changed files with 353 additions and 146 deletions
+3 -3
View File
@@ -46,7 +46,7 @@ class Popup {
this.content.push(objToDom({[Popup.STRONG]: cnt}));
}
async display() {
async display(parent=document.body) {
let outer=document.createElement('div');
outer.classList.add('popup');
let popup=outer.appendChild(document.createElement('div'));
@@ -67,7 +67,7 @@ class Popup {
});
buttons.forEach(btn => buttonSection.appendChild(btn));
document.body.appendChild(outer);
parent.appendChild(outer);
const code=await Promise.race(buttons.map(btn => new Promise(ok => {
btn.addEventListener('click', e => {
@@ -76,7 +76,7 @@ class Popup {
});
})));
document.body.removeChild(outer);
parent.removeChild(outer);
return code;
}
}