25 lines
653 B
JavaScript
25 lines
653 B
JavaScript
// retoor <retoor@molodetz.nl>
|
|
export class EditorPreview {
|
|
constructor() {
|
|
this.source = document.querySelector("[data-preview-source]");
|
|
this.target = document.querySelector("[data-preview-target]");
|
|
if (!this.source || !this.target) {
|
|
return;
|
|
}
|
|
this.timer = null;
|
|
this.source.addEventListener("input", () => this.schedule());
|
|
customElements.whenDefined("dp-content").then(() => this.update());
|
|
}
|
|
|
|
schedule() {
|
|
clearTimeout(this.timer);
|
|
this.timer = setTimeout(() => this.update(), 150);
|
|
}
|
|
|
|
update() {
|
|
this.target.markdown = this.source.value;
|
|
}
|
|
}
|
|
|
|
window.editorPreview = new EditorPreview();
|