refactored code and added win/lose popups
This commit is contained in:
+3
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user