1class Page extends gia.Component { 2 constructor(element) { 3 super(element); 4 } 5 6 mount() { 7 this.onFirstPageLoad(); 8 this.onPageLoad(); 9 swup.hooks.on("content:replace", this.onPageLoad, { priority: -100 }); 10 swup.hooks.on("content:replace", this.updateBodyClass, { priority: -100 }); 11 swup.hooks.on("page:view", this.onPageView, { priority: 0 }); 12 swup.hooks.before("content:replace", this.onPageUnload); 13 } 14 unmount() { 15 this.onPageUnload(); 16 swup.hooks.off("content:replace", this.onPageLoad); 17 swup.hooks.off("content:replace", this.updateBodyClass); 18 swup.hooks.off("page:view", this.onPageView); 19 swup.hooks.off("content:replace", this.onPageUnload); 20 } 21 onFirstPageLoad() { 22 // only on first page load 23 } 24 onPageLoad() { 25 // on every page load, including first page load 26 this.updateActiveLinks(); 27 this.updateExternalLinks(); 28 // this.initFooterAccordeons(); 29 } 30 onPageView() { 31 // not on first page view, but after every onPageLoad() 32 } 33 onPageUnload() { 34 // on every page unload 35 } 36 37 // initFooterAccordeons() { 38 // const mainFooter = document.querySelector("footer#main-footer"); 39 // if (mainFooter) { 40 // const navs = mainFooter.querySelectorAll(".top nav"); 41 42 // navs.forEach((nav) => { 43 // const titleButton = nav.querySelector("button.menu-title"); 44 // if (titleButton) { 45 // titleButton.addEventListener("click", (event) => { 46 // nav.classList.toggle("open"); 47 // }); 48 // } 49 // }); 50 // } 51 // } 52 53 updateBodyClass = (visit, { page: { html } }) => { 54 document.body.className = html.match(/body\sclass=['|"]([^'|"]*)['|"]/)[1]; 55 }; 56 57 updateActiveLinks() { 58 const links = document.querySelectorAll("a"); 59 if (!links.length > 0) return; 60 links.forEach((link) => { 61 link.classList.remove("active"); 62 if (link.href === window.location.href) { 63 link.classList.add("active"); 64 } 65 }); 66 } 67 updateExternalLinks() { 68 const links = document.querySelectorAll("a[href]"); 69 if (!links.length > 0) return; 70 links.forEach((link) => { 71 const linkHostname = new URL(link.href).hostname; 72 if (linkHostname && linkHostname != location.hostname && !linkHostname.includes("sfu")) { 73 link.target = "_blank"; 74 link.classList.add("external"); 75 } 76 }); 77 } 78}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.