Files
Trilium/src/public/app/services/glob.js

90 lines
2.9 KiB
JavaScript
Raw Normal View History

import utils from "./utils.js";
2022-12-01 13:07:23 +01:00
import appContext from "../components/app_context.js";
import server from "./server.js";
import libraryLoader from "./library_loader.js";
import ws from "./ws.js";
2021-04-16 23:01:56 +02:00
import froca from "./froca.js";
2023-06-29 12:19:01 +02:00
import linkService from "./link.js";
2020-04-12 14:22:51 +02:00
function setupGlobs() {
window.glob.isDesktop = utils.isDesktop;
window.glob.isMobile = utils.isMobile;
window.glob.getComponentByEl = el => appContext.getComponentByEl(el);
window.glob.getHeaders = server.getHeaders;
2023-06-29 12:19:01 +02:00
window.glob.getReferenceLinkTitle = href => linkService.getReferenceLinkTitle(href);
window.glob.getReferenceLinkTitleSync = href => linkService.getReferenceLinkTitleSync(href);
2020-04-12 14:22:51 +02:00
// required for ESLint plugin and CKEditor
2023-06-06 12:31:38 +02:00
window.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
2020-04-12 14:22:51 +02:00
window.glob.requireLibrary = libraryLoader.requireLibrary;
window.glob.ESLINT = libraryLoader.ESLINT;
window.glob.appContext = appContext; // for debugging
2021-04-16 22:57:37 +02:00
window.glob.froca = froca;
2021-04-17 20:52:46 +02:00
window.glob.treeCache = froca; // compatibility for CKEditor builds for a while
2020-04-12 14:22:51 +02:00
// for CKEditor integration (button on block toolbar)
window.glob.importMarkdownInline = async () => appContext.triggerCommand("importMarkdownInline");
2020-04-12 14:22:51 +02:00
window.onerror = function (msg, url, lineNo, columnNo, error) {
const string = msg.toLowerCase();
let message = "Uncaught error: ";
if (string.includes("script error")) {
2020-04-12 14:22:51 +02:00
message += 'No details available';
} else {
message += [
`Message: ${msg}`,
`URL: ${url}`,
`Line: ${lineNo}`,
`Column: ${columnNo}`,
`Error object: ${JSON.stringify(error)}`,
`Stack: ${error && error.stack}`
].join(', ');
2020-04-12 14:22:51 +02:00
}
ws.logError(message);
return false;
};
2024-10-25 19:57:40 +03:00
window.addEventListener("unhandledrejection", (e) => {
const string = e.reason.message.toLowerCase();
let message = "Uncaught error: ";
if (string.includes("script error")) {
message += 'No details available';
} else {
message += [
`Message: ${e.reason.message}`,
`Line: ${e.reason.lineNumber}`,
`Column: ${e.reason.columnNumber}`,
`Error object: ${JSON.stringify(e.reason)}`,
`Stack: ${e.reason && e.reason.stack}`
].join(', ');
}
ws.logError(message);
return false;
});
2020-04-12 14:22:51 +02:00
for (const appCssNoteId of glob.appCssNoteIds || []) {
libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`, false);
}
utils.initHelpButtons($(window));
2020-04-12 14:22:51 +02:00
$("body").on("click", "a.external", function () {
window.open($(this).attr("href"), '_blank');
return false;
2020-04-12 14:22:51 +02:00
});
}
2020-04-12 14:22:51 +02:00
export default {
setupGlobs
2020-06-06 18:46:45 +02:00
}