mirror of
https://github.com/zadam/trilium.git
synced 2026-01-06 14:44:25 +01:00
chore(share): bring back most of the logic
This commit is contained in:
parent
e3dd25b591
commit
21b20cf575
@ -9,8 +9,6 @@ async function ensureJQuery() {
|
|||||||
(window as any).$ = $;
|
(window as any).$ = $;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function formatCodeBlocks() {
|
async function formatCodeBlocks() {
|
||||||
const anyCodeBlock = document.querySelector("#content pre");
|
const anyCodeBlock = document.querySelector("#content pre");
|
||||||
if (!anyCodeBlock) {
|
if (!anyCodeBlock) {
|
||||||
@ -24,49 +22,3 @@ async function formatCodeBlocks() {
|
|||||||
async function setupTextNote() {
|
async function setupTextNote() {
|
||||||
formatCodeBlocks();
|
formatCodeBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch note with given ID from backend
|
|
||||||
*
|
|
||||||
* @param noteId of the given note to be fetched. If false, fetches current note.
|
|
||||||
*/
|
|
||||||
async function fetchNote(noteId: string | null = null) {
|
|
||||||
if (!noteId) {
|
|
||||||
noteId = document.body.getAttribute("data-note-id");
|
|
||||||
}
|
|
||||||
|
|
||||||
const resp = await fetch(`api/notes/${noteId}`);
|
|
||||||
|
|
||||||
return await resp.json();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener(
|
|
||||||
"DOMContentLoaded",
|
|
||||||
() => {
|
|
||||||
const noteType = determineNoteType();
|
|
||||||
|
|
||||||
if (noteType === "text") {
|
|
||||||
setupTextNote();
|
|
||||||
}
|
|
||||||
|
|
||||||
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
|
||||||
const layout = document.getElementById("layout");
|
|
||||||
|
|
||||||
if (toggleMenuButton && layout) {
|
|
||||||
toggleMenuButton.addEventListener("click", () => layout.classList.toggle("showMenu"));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
function determineNoteType() {
|
|
||||||
const bodyClass = document.body.className;
|
|
||||||
const match = bodyClass.match(/type-([^\s]+)/);
|
|
||||||
return match ? match[1] : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// workaround to prevent webpack from removing "fetchNote" as dead code:
|
|
||||||
// add fetchNote as property to the window object
|
|
||||||
Object.defineProperty(window, "fetchNote", {
|
|
||||||
value: fetchNote
|
|
||||||
});
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import setupSearch from "./modules/search";
|
|||||||
import setupThemeSelector from "./modules/theme";
|
import setupThemeSelector from "./modules/theme";
|
||||||
import setupMermaid from "./modules/mermaid";
|
import setupMermaid from "./modules/mermaid";
|
||||||
import setupMath from "./modules/math";
|
import setupMath from "./modules/math";
|
||||||
|
import api from "./modules/api";
|
||||||
|
|
||||||
function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) {
|
function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Parameters<T>) {
|
||||||
try {
|
try {
|
||||||
@ -15,10 +16,39 @@ function $try<T extends (...a: unknown[]) => unknown>(func: T, ...args: Paramete
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object.assign(window, api);
|
||||||
$try(setupThemeSelector);
|
$try(setupThemeSelector);
|
||||||
$try(setupToC);
|
$try(setupToC);
|
||||||
$try(setupExpanders);
|
$try(setupExpanders);
|
||||||
$try(setupMobileMenu);
|
$try(setupMobileMenu);
|
||||||
$try(setupSearch);
|
$try(setupSearch);
|
||||||
$try(setupMermaid);
|
|
||||||
$try(setupMath);
|
function setupTextNote() {
|
||||||
|
$try(setupMermaid);
|
||||||
|
$try(setupMath);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener(
|
||||||
|
"DOMContentLoaded",
|
||||||
|
() => {
|
||||||
|
const noteType = determineNoteType();
|
||||||
|
|
||||||
|
if (noteType === "text") {
|
||||||
|
setupTextNote();
|
||||||
|
}
|
||||||
|
|
||||||
|
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
||||||
|
const layout = document.getElementById("layout");
|
||||||
|
|
||||||
|
if (toggleMenuButton && layout) {
|
||||||
|
toggleMenuButton.addEventListener("click", () => layout.classList.toggle("showMenu"));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
function determineNoteType() {
|
||||||
|
const bodyClass = document.body.className;
|
||||||
|
const match = bodyClass.match(/type-([^\s]+)/);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
}
|
||||||
|
|||||||
18
packages/share-theme/src/scripts/modules/api.ts
Normal file
18
packages/share-theme/src/scripts/modules/api.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Fetch note with given ID from backend
|
||||||
|
*
|
||||||
|
* @param noteId of the given note to be fetched. If false, fetches current note.
|
||||||
|
*/
|
||||||
|
async function fetchNote(noteId: string | null = null) {
|
||||||
|
if (!noteId) {
|
||||||
|
noteId = document.body.getAttribute("data-note-id");
|
||||||
|
}
|
||||||
|
|
||||||
|
const resp = await fetch(`api/notes/${noteId}`);
|
||||||
|
|
||||||
|
return await resp.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
fetchNote
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user