summaryrefslogtreecommitdiffstats
path: root/src/modules/WYSiWYG.ts
blob: 39b627ee73079068b5a73cefaabf5d40acc39530 (plain) (blame)
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
import tinymce, { Editor } from 'tinymce';
import 'tinymce/icons/default';
import 'tinymce/themes/silver';
import 'tinymce/skins/ui/oxide/skin.css';
import Chit from './Chit';

export default class WYSiWYG {
  #id = 'tinymce'
  #bSave: HTMLButtonElement
  #bCancel: HTMLButtonElement
  #whoClicked?: Chit;

  constructor() {
    tinymce.init({
      selector: this.idAsSel,
    });

    const s = document.getElementsByClassName("tox-statusbar__branding")[0] as HTMLSpanElement;
    const t = document.getElementsByClassName("tox-tinymce")[0] as HTMLDivElement;
    const tf = s.parentElement as HTMLDivElement
    const tfp = tf.parentElement as HTMLDivElement
    tf.removeChild(s)

    t.id = "wysiwyg"
    tfp.id = "tfp";

    this.#bSave = document.createElement("button")
    this.#bCancel = document.createElement("button")
    this.#bSave.id = "save"
    this.#bCancel.id = "cancel"
    tf.append(this.#bSave, this.#bCancel)

    // this.#bSave.onclick = () => this.setContent(this.content + "asd");
    this.#bSave.onclick = () => this.hide();
    this.#bCancel.onclick = () => this.hide();
    this.hide()
  }

  get #tmce(): Editor {
    return tinymce.get(this.#id);
  }
  show(c: Chit) {
    this.#tmce.show();
    this.setContent(c.txt)
    this.#whoClicked = c;
  }
  hide() {
    if (this.#whoClicked != null)
      this.#whoClicked.txt = this.content;
    this.#tmce.hide();
  }
  setContent(c: string) {
    this.#tmce.setContent(c);
  }
  get content(): string {
    return this.#tmce.getContent()
  }

  get idAsSel() {
    return '#' + this.#id;
  }
}