mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
refactor(share): don't load jQuery if not needed
This commit is contained in:
parent
0e88818220
commit
4d5a0e7832
@ -4,17 +4,19 @@ import "boxicons/css/boxicons.min.css";
|
|||||||
import "@triliumnext/share-theme/styles/index.css";
|
import "@triliumnext/share-theme/styles/index.css";
|
||||||
import "@triliumnext/share-theme/scripts/index.js";
|
import "@triliumnext/share-theme/scripts/index.js";
|
||||||
|
|
||||||
import $ from "jquery";
|
async function ensureJQuery() {
|
||||||
|
const $ = (await import("jquery")).default;
|
||||||
|
(window as any).$ = $;
|
||||||
|
}
|
||||||
|
|
||||||
window.$ = $;
|
async function formatCodeBlocks() {
|
||||||
|
const codeBlocks = document.querySelectorAll("#content pre");
|
||||||
async function formatCodeBlocks($container: JQuery<HTMLElement>) {
|
|
||||||
const codeBlocks = $container.find("pre code");
|
|
||||||
if (codeBlocks.length === 0) {
|
if (codeBlocks.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await ensureJQuery();
|
||||||
const { formatCodeBlocks } = await import("./services/syntax_highlight.js");
|
const { formatCodeBlocks } = await import("./services/syntax_highlight.js");
|
||||||
await formatCodeBlocks($container);
|
await formatCodeBlocks($("#content"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,7 +37,7 @@ async function fetchNote(noteId: string | null = null) {
|
|||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
"DOMContentLoaded",
|
"DOMContentLoaded",
|
||||||
() => {
|
() => {
|
||||||
formatCodeBlocks($("#content"));
|
formatCodeBlocks();
|
||||||
|
|
||||||
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
const toggleMenuButton = document.getElementById("toggleMenuButton");
|
||||||
const layout = document.getElementById("layout");
|
const layout = document.getElementById("layout");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user