
class Alert{
constructor(message,info){
this.div=AddElement(document.body,'div');
this.div.className='alertContainer';
this.buttons=[];
let table=AddElement(this.div,'table');
let tr=AddElement(table,'tr');
let td=AddElement(tr,'td');
let img=AddElement(td,'img');
img.src='../img/icon_128x128.png';
img.width=64;
img.height=64;
tr=AddElement(table,'tr');
AddElement(tr,'td','font-weight:bold;').textContent=message;
if(info){
tr=AddElement(table,'tr');
AddElement(tr,'td').textContent=info;
}
tr=AddElement(table,'tr');
this.buttonContainer=AddElement(table,'td');
this.keyDownHandler=(event)=>{this.handleKeyDown(event);}
document.addEventListener('keydown',this.keyDownHandler);
}
addButton(name,callback){
let button=AddElement(this.buttonContainer,'button');
this.buttons.push(button);
button.type='button';
button.textContent=name;
button.onclick=()=>{
document.removeEventListener('keydown',this.keyDownHandler);
this.div.remove();
if(callback)callback();
};
}
handleKeyDown(event){
if(event.key==="Enter"){
this.buttons[0].click();
}else if(event.key==="Escape"){
if(this.buttons[1])this.buttons[1].click();
else this.buttons[0].click();
}
}
}
function SimpleAlert(message,info){
let alert=new Alert(message,info);
alert.addButton(Loc('OK'),null);
}
