Debian Codegraph @

debian/missing-sources/pydata-sphinx-theme.js

raw symbols SCIP
1 /* Sphinx injects the html output with jquery and other javascript files.
2 * To enable Popper.js (and other jQuery plugins) to hook into the same instance of jQuery,
3 * jQuery is defined as a Webpack external, thus this import uses the externally defined jquery dependency.
4 */
5 import "jquery";
6
7 import "popper.js";
8 import "bootstrap";
9
10 import "../styles/index.scss";
11
12 function addTOCInteractivity() {
13 // TOC sidebar - add "active" class to parent list
14 //
15 // Bootstrap's scrollspy adds the active class to the <a> link,
16 // but for the automatic collapsing we need this on the parent list item.
17 //
18 // The event is triggered on "window" (and not the nav item as documented),
19 // see https://github.com/twbs/bootstrap/issues/20086
20 $(window).on("activate.bs.scrollspy", function () {
21 const navLinks = document.querySelectorAll("#bd-toc-nav a");
22
23 navLinks.forEach((navLink) => {
24 navLink.parentElement.classList.remove("active");
25 });
26
27 const activeNavLinks = document.querySelectorAll("#bd-toc-nav a.active");
28 activeNavLinks.forEach((navLink) => {
29 navLink.parentElement.classList.add("active");
30 });
31 });
32 }
33
34 // Navigation sidebar scrolling to active page
35 function scrollToActive() {
36 var sidebar = document.querySelector("div.bd-sidebar");
37
38 // Remember the sidebar scroll position between page loads
39 // Inspired on source of revealjs.com
40 let storedScrollTop = parseInt(
41 sessionStorage.getItem("sidebar-scroll-top"),
42 10
43 );
44
45 if (!isNaN(storedScrollTop)) {
46 // If we've got a saved scroll position, just use that
47 sidebar.scrollTop = storedScrollTop;
48 console.log("[PST]: Scrolled sidebar using stored browser position...");
49 } else {
50 // Otherwise, calculate a position to scroll to based on the lowest `active` link
51 var sidebarNav = document.getElementById("bd-docs-nav");
52 var active_pages = sidebarNav.querySelectorAll(".active");
53 if (active_pages.length > 0) {
54 // Use the last active page as the offset since it's the page we're on
55 var latest_active = active_pages[active_pages.length - 1];
56 var offset =
57 latest_active.getBoundingClientRect().y -
58 sidebar.getBoundingClientRect().y;
59 // Only scroll the navbar if the active link is lower than 50% of the page
60 if (latest_active.getBoundingClientRect().y > window.innerHeight * 0.5) {
61 let buffer = 0.25; // Buffer so we have some space above the scrolled item
62 sidebar.scrollTop = offset - sidebar.clientHeight * buffer;
63 console.log("[PST]: Scrolled sidebar using last active link...");
64 }
65 }
66 }
67
68 // Store the sidebar scroll position
69 window.addEventListener("beforeunload", () => {
70 sessionStorage.setItem("sidebar-scroll-top", sidebar.scrollTop);
71 });
72 }
73
74 // This is equivalent to the .ready() function as described in
75 // https://api.jquery.com/ready/
76 $(scrollToActive);
77 $(addTOCInteractivity);