5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-04 15:05:47 +00:00
panel/app/javascript/editor/editor.ts
2021-08-10 18:36:55 -03:00

36 lines
841 B
TypeScript

/// @ts-ignore
import SuttyEditor from "@suttyweb/editor";
import "@suttyweb/editor/dist/style.css";
document.addEventListener("turbolinks:load", () => {
const flash = document.querySelector<HTMLElement>(".js-flash");
if (flash) {
const keys = JSON.parse(flash.dataset.keys || "[]");
switch (flash.dataset.target) {
case "editor":
switch (flash.dataset.action) {
case "forget-content":
keys.forEach(forgetContent);
}
}
}
for (const editorEl of document.querySelectorAll<HTMLElement>(
".editor[data-editor]"
)) {
try {
new SuttyEditor({
target: editorEl,
props: {
textareaEl: editorEl.parentElement!.querySelector("textarea"),
},
});
} catch (error) {
console.error(error);
alert(error);
}
}
});