added a cancel option to popups (closes #28)
This commit is contained in:
+12
-2
@@ -77,15 +77,20 @@ class Popup {
|
||||
buttons.forEach(btn => buttonSection.appendChild(btn));
|
||||
|
||||
parent.appendChild(outer);
|
||||
Popup.displayed.push(this);
|
||||
|
||||
const code=await Promise.race(buttons.map(btn => new Promise(ok => {
|
||||
const btnActions=buttons.map(btn => new Promise(ok => {
|
||||
btn.addEventListener('click', e => {
|
||||
e.preventDefault();
|
||||
return ok(btn.dataset.code);
|
||||
});
|
||||
})));
|
||||
}));
|
||||
const dismissAction=new Promise(ok => this.dismiss=ok);
|
||||
|
||||
const code=await Promise.race(btnActions.concat([dismissAction]));
|
||||
|
||||
parent.removeChild(outer);
|
||||
Popup.displayed.splice(Popup.displayed.indexOf(this), 1);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -93,4 +98,9 @@ class Popup {
|
||||
Popup.EM=Symbol('EM');
|
||||
Popup.STRONG=Symbol('STRONG');
|
||||
|
||||
Popup.displayed=[];
|
||||
Popup.dismiss=arg => {
|
||||
Popup.displayed.forEach(p => p.dismiss(arg));
|
||||
};
|
||||
|
||||
return module.exports=Popup;
|
||||
|
||||
Reference in New Issue
Block a user