summaryrefslogtreecommitdiff
path: root/WebInterface/NodeJSServer/src/modules/ui/modal.js
blob: e1aa8a2cdc93b8c5ab4434a8e0d2caa4f4a66d9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
export default class Modal {
  constructor(titleString) {
    let modalBackground = document.createElement('div');
    let modal = document.createElement('div');
    let title = document.createElement('h1');
    let body = document.createElement('div');

    modalBackground.className = 'modal-container';
    modal.className = 'modal';
    title.className = 'modal-title';
    body.className = 'modal-body'

    title.textContent = titleString;

    modal.appendChild(title);
    modalBackground.appendChild(modal);
    document.body.appendChild(modalBackground);

    this.bg = modalBackground;
    this.modal = modal;
    this.title = title;
    this.body = body;

    this.registerEvents();
  }

  registerEvents() {
    this.bg.addEventListener('click', () => {
      this.bg.classList.add('hidden');
      this.bg.addEventListener('transitionend', () => {
        document.body.removeChild(this.bg);
      });
    });
  }

  setBodyText(text) {
    this.body.textContent = text;
  }
}