metasocket-cordova/src/app/fullscreen.dialog.ts

74 lines
2.1 KiB
TypeScript

export default class FullscreenDialog
{
protected rootElement: HTMLDivElement;
protected window: HTMLDivElement;
protected title: HTMLHeadElement;
protected message: HTMLParagraphElement;
protected extendedInputArea: HTMLDivElement;
protected buttonArea: HTMLDivElement;
public constructor(title: string, message: string) {
this.rootElement = document.createElement('div');
this.rootElement.classList.add('notification');
this.window = document.createElement('div');
this.window.classList.add('notification-window');
this.rootElement.appendChild(this.window);
this.title = document.createElement('h1');
this.title.classList.add('notification-headline');
this.title.innerText = title;
this.window.appendChild(this.title);
this.message = document.createElement('p');
this.message.innerText = message;
this.window.appendChild(this.message);
this.extendedInputArea = document.createElement('div');
this.extendedInputArea.classList.add('notification-extended-input-area');
this.window.appendChild(this.extendedInputArea);
this.buttonArea = document.createElement('div');
this.buttonArea.classList.add('notification-button-area');
this.window.appendChild(this.buttonArea);
document.body.appendChild(this.rootElement);
}
public addButton(title: string, callback: () => void = () => {}): void
{
const button = document.createElement('button');
button.classList.add('notification-button');
button.innerText = title;
button.onclick = () => {
callback();
this.close();
};
this.buttonArea.appendChild(button);
}
public addUrlButton(title: string, url: string): void
{
const button = document.createElement('a');
button.classList.add('notification-button');
button.innerText = title;
button.href = url;
button.onclick = () => {this.close(); };
this.buttonArea.appendChild(button);
}
public addExtendedInputElement(element: HTMLElement): void
{
this.extendedInputArea.appendChild(element);
}
public close(): void
{
this.rootElement.remove();
}
}