5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 23:56:22 +00:00
panel/app/javascript/editor/editor.ts

36 lines
841 B
TypeScript
Raw Normal View History

2021-05-22 21:17:00 +00:00
/// @ts-ignore
import SuttyEditor from "@suttyweb/editor";
import "@suttyweb/editor/dist/style.css";
document.addEventListener("turbolinks:load", () => {
2021-04-28 18:48:50 +00:00
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 {
2021-05-22 21:17:00 +00:00
new SuttyEditor({
target: editorEl,
props: {
textareaEl: editorEl.parentElement!.querySelector("textarea"),
},
});
2021-04-28 18:48:50 +00:00
} catch (error) {
2021-05-22 21:17:00 +00:00
console.error(error);
alert(error);
2021-04-28 18:48:50 +00:00
}
}
});