all repos — onyx @ main

minimal map annotation and location data sharing tool

src/24-importExportModal.ts (raw)

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class ImportExportModal implements Modal {
  self(): HTMLElement | null { 
    return document.getElementById("import-export-container");
  }
  
  visible(): boolean {
    return this.self()?.style.display != "none";
  }
  
  setVisible(v: boolean): void {
    const modal = this.self();
    if (modal) {
      modal.style.display = v ? "block" : "none";
    }
  }
  
  setTitle(title: string): void {
    const modalH2 = document.getElementById("import-export-title");
    if (modalH2) {
      modalH2.innerHTML = title;
    }
  }
  
  setTextArea(text: string, readonly: boolean): void {
    const textarea = document.getElementById("import-export-textarea") as HTMLTextAreaElement;
    if (textarea) {
      textarea.value = text;
      textarea.readOnly = readonly;
    }
  }
  
  setErrMsg(text: string, visible: boolean): void {
    const errMsg = document.getElementById("import-export-error");
    if (errMsg) {
      errMsg.innerHTML = text;
      errMsg.style.display = visible ? "unset" : "none";
    }
  }
  
  copyTextArea(): void {
    const textarea = document.getElementById("import-export-textarea") as HTMLTextAreaElement;
    if (textarea) {
      textarea.select();
      textarea.setSelectionRange(0, 9999999);
      navigator.clipboard.writeText(textarea.value);
    }
  }
  
  getText(): string {
    const textarea = document.getElementById("import-export-textarea") as HTMLTextAreaElement;
    if (textarea) {
      return textarea.value;
    }
    return "";
  }
  
  okBtn(): HTMLElement | null {
    return document.getElementById("import-export-ok-btn");
  }
  
  cancelBtn(): HTMLElement | null {
    return document.getElementById("import-export-cancel-btn");
  }
}