pastel.codes/obsidian/lib/scripts/webpage.js

1 line
46 KiB
JavaScript
Raw Normal View History

2024-04-29 14:52:09 +01:00
let absoluteBasePath,relativeBasePath,relativePathname,webpageContainer,documentContainer,viewContent,leftSidebar,rightSidebar,sidebarCollapseIcons,sidebarGutters,sidebars,sidebarDefaultWidth,sidebarTargetWidth,contentTargetWidth,themeToggle,searchInput,fileTree,outlineTree,fileTreeItems,outlineTreeItems,canvasWrapper,canvas,canvasNodes,canvasBackground,canvasBackgroundPattern,focusedCanvasNode,loadingIcon,documentType,embedType,customType,deviceSize,lastScreenWidth,loadedURL=new URL(window.location.href),isOffline=!1,collapseIconUp=["m7 15 5 5 5-5","m7 9 5-5 5 5"],collapseIconDown=["m7 20 5-5 5 5","m7 4 5 5 5-5"],isTouchDevice=isTouchCapable(),fullyInitialized=!1;async function initGlobalObjects(){"file:"!=window.location.protocol&&await loadIncludes(),loadingIcon=document.createElement("div"),loadingIcon.classList.add("loading-icon"),document.body.appendChild(loadingIcon),loadingIcon.innerHTML="<div></div><div></div><div></div><div></div>",webpageContainer=document.querySelector(".webpage-container"),documentContainer=document.querySelector(".document-container"),leftSidebar=document.querySelector(".sidebar-left"),rightSidebar=document.querySelector(".sidebar-right"),fileTree=document.querySelector(".file-tree"),outlineTree=document.querySelector(".outline-tree"),fileTreeItems=Array.from(document.querySelectorAll(".tree-container.file-tree .tree-item")),sidebars=[],sidebarGutters=[],sidebarCollapseIcons=[],leftSidebar&&rightSidebar&&(sidebarCollapseIcons=Array.from(document.querySelectorAll(".sidebar-collapse-icon")),sidebarGutters=[sidebarCollapseIcons[0].parentElement,sidebarCollapseIcons[1].parentElement],sidebars=[sidebarGutters[0].parentElement,sidebarGutters[1].parentElement]),themeToggle=document.querySelector(".theme-toggle-input")}async function initializePage(){focusedCanvasNode=null,canvasWrapper=document.querySelector(".canvas-wrapper")??canvasWrapper,canvas=document.querySelector(".canvas")??canvas;let e=document.querySelectorAll(".canvas-node");canvasNodes=e.length>0?e:canvasNodes,canvasBackground=document.querySelector(".canvas-background")??canvasBackground,canvasBackgroundPattern=document.querySelector(".canvas-background pattern")??canvasBackgroundPattern,viewContent=document.querySelector(".document-container > .view-content")??document.querySelector(".document-container > .markdown-preview-view")??viewContent,outlineTreeItems=Array.from(document.querySelectorAll(".tree-container.outline-tree .tree-item")),fullyInitialized||("file:"==window.location.protocol&&initializeForFileProtocol(),await initGlobalObjects(),initializeDocumentTypes(document),setupSidebars(),setupThemeToggle(),await setupSearch(),setupRootPath(document),sidebarDefaultWidth=await getComputedPixelValue("--sidebar-width"),contentTargetWidth=.9*await getComputedPixelValue("--line-width"),window.addEventListener("resize",(()=>onResize())),onResize()),setTimeout((()=>documentContainer.classList.remove("hide"))),!rightSidebar||"video"!=embedType&&"embed"!=embedType&&"excalidraw"!=customType&&"kanban"!=customType&&"canvas"!=documentType?rightSidebar&&rightSidebar.temporarilyCollapsed&&rightSidebar.collapsed&&(rightSidebar.collapse(!1),rightSidebar.temporarilyCollapsed=!1):rightSidebar.collapsed||rightSidebar.temporaryCollapse(),parseURLParams(),relativePathname=getVaultRelativePath(loadedURL.href)}function initializePageEvents(e){e&&(setupHeaders(e),setupTrees(e),setupLists(e),setupCallouts(e),setupCheckboxes(e),setupCanvas(e),setupCodeblocks(e),setupLinks(e),setupScroll(e))}function initializeDocumentTypes(e){e.querySelector(".document-container > .markdown-preview-view")?documentType="markdown":e.querySelector(".canvas-wrapper")?documentType="canvas":(documentType="custom",e.querySelector(".kanban-plugin")?customType="kanban":e.querySelector(".excalidraw-plugin")&&(customType="excalidraw"))}function initializeForFileProtocol(){let e=document.querySelector(".graph-view-placeholder");e&&(console.log("Running locally, skipping graph view initialization and hiding graph."),e.style.display="none",e.previousElementSibling.style.display="none