2025-05-17 10:03:37 +03:00
|
|
|
import "normalize.css";
|
2025-05-17 10:13:03 +03:00
|
|
|
import "@triliumnext/ckeditor5/content.css";
|
2025-06-09 14:13:35 +03:00
|
|
|
import "@triliumnext/share-theme/styles/index.css";
|
2025-06-09 14:39:56 +03:00
|
|
|
import "@triliumnext/share-theme/scripts/index.js";
|
2025-02-21 22:07:23 +01:00
|
|
|
|
2025-06-09 21:00:58 +03:00
|
|
|
async function loadIcons() {
|
|
|
|
if (document.getElementById("menu")) {
|
|
|
|
await import("boxicons/css/boxicons.min.css");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-09 20:15:55 +03:00
|
|
|
async function ensureJQuery() {
|
|
|
|
const $ = (await import("jquery")).default;
|
|
|
|
(window as any).$ = $;
|
|
|
|
}
|
2025-06-09 20:03:32 +03:00
|
|
|
|
2025-06-09 20:15:55 +03:00
|
|
|
async function formatCodeBlocks() {
|
|
|
|
const codeBlocks = document.querySelectorAll("#content pre");
|
2025-06-09 20:03:32 +03:00
|
|
|
if (codeBlocks.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2025-06-09 20:15:55 +03:00
|
|
|
await ensureJQuery();
|
2025-06-09 20:03:32 +03:00
|
|
|
const { formatCodeBlocks } = await import("./services/syntax_highlight.js");
|
2025-06-09 20:15:55 +03:00
|
|
|
await formatCodeBlocks($("#content"));
|
2025-06-09 20:03:32 +03:00
|
|
|
}
|
2025-06-09 18:22:30 +03:00
|
|
|
|
2022-01-01 13:23:09 +01:00
|
|
|
/**
|
|
|
|
* Fetch note with given ID from backend
|
|
|
|
*
|
2023-06-23 00:26:47 +08:00
|
|
|
* @param noteId of the given note to be fetched. If false, fetches current note.
|
2022-01-01 13:23:09 +01:00
|
|
|
*/
|
2025-01-26 20:54:30 +01:00
|
|
|
async function fetchNote(noteId: string | null = null) {
|
2022-01-01 13:23:09 +01:00
|
|
|
if (!noteId) {
|
2022-01-01 22:32:38 +01:00
|
|
|
noteId = document.body.getAttribute("data-note-id");
|
2022-01-01 13:23:09 +01:00
|
|
|
}
|
|
|
|
|
2022-01-01 22:32:38 +01:00
|
|
|
const resp = await fetch(`api/notes/${noteId}`);
|
2022-01-01 13:23:09 +01:00
|
|
|
|
|
|
|
return await resp.json();
|
|
|
|
}
|
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
document.addEventListener(
|
|
|
|
"DOMContentLoaded",
|
|
|
|
() => {
|
2025-06-09 20:15:55 +03:00
|
|
|
formatCodeBlocks();
|
2025-06-09 21:00:58 +03:00
|
|
|
loadIcons();
|
2025-06-09 20:03:32 +03:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
|
|
|
const layout = document.getElementById("layout");
|
2022-01-01 13:23:09 +01:00
|
|
|
|
2025-01-09 18:07:02 +02:00
|
|
|
if (toggleMenuButton && layout) {
|
|
|
|
toggleMenuButton.addEventListener("click", () => layout.classList.toggle("showMenu"));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
2025-01-26 21:23:08 +01:00
|
|
|
|
|
|
|
// workaround to prevent webpack from removing "fetchNote" as dead code:
|
|
|
|
// add fetchNote as property to the window object
|
|
|
|
Object.defineProperty(window, "fetchNote", {
|
|
|
|
value: fetchNote
|
2025-03-02 20:47:57 +01:00
|
|
|
});
|