From dbb66972ebd987f60e10939bfb4493f87bbc73c3 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Tue, 26 Oct 2021 16:49:09 +0200 Subject: Quick commit with sort-of working WYSiWYG and moving chit --- src/modules/WYSiWYG.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/modules/WYSiWYG.ts (limited to 'src/modules/WYSiWYG.ts') diff --git a/src/modules/WYSiWYG.ts b/src/modules/WYSiWYG.ts new file mode 100644 index 0000000..1161cde --- /dev/null +++ b/src/modules/WYSiWYG.ts @@ -0,0 +1,58 @@ +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 + + 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.#bCancel.onclick = () => this.hide(); + this.hide() + } + + get #tmce(): Editor { + return tinymce.get(this.#id); + } + show(c: Chit) { + console.log(c.txt) + this.#tmce.show(); + this.setContent(c.txt) + } + hide() { + this.#tmce.hide(); + } + setContent(c: string) { + this.#tmce.setContent(c); + } + get content(): string { + return this.#tmce.getContent() + } + + get idAsSel() { + return '#' + this.#id; + } +} -- cgit v1.3.1