1// Description: Open external links in a new tab and PDF links in a new tab 2// Based on: https://jekyllcodex.org/without-plugin/new-window-fix/ 3 4// Open external links in a new window 5function external_new_window() { 6 for(let c = document.getElementsByTagName("a"), a = 0; a < c.length; a++) { 7 let b = c[a]; 8 if(b.getAttribute("href") && b.host !== location.host) { 9 b.target = "_blank"; 10 b.rel = "noopener"; 11 } 12 } 13} 14 15// Open PDF links in a new window 16function pdf_new_window() { 17 if (!document.getElementsByTagName) { 18 return false; 19 } 20 21 const extensions = ['.pdf', '.doc', '.docx', '.json', '.xls', '.xlsx', '.ppt', '.pptx', '.zip', '.rar', '.tar', '.gz', '.7z', '.bz2', '.xz', '.tgz', '.tar.gz']; 22 let links = document.getElementsByTagName("a"); 23 24 for (let eleLink = 0; eleLink < links.length; eleLink++) { 25 let href = links[eleLink].href.toLowerCase(); // Convert href to lowercase for case-insensitive matching 26 27 if (extensions.some(ext => href.endsWith(ext))) { 28 links[eleLink].onclick = function() { 29 window.open(this.href); 30 return false; 31 } 32 } 33 } 34} 35 36function apply_rules() { 37 external_new_window(); 38 pdf_new_window(); 39} 40 41if (typeof document$ !== "undefined") { 42 // Compatibility with mkdocs-material's instant loading feature 43 document$.subscribe(function() { 44 apply_rules(); 45 }); 46} else { 47 // For browsers without mkdocs-material's instant loading feature 48 document.addEventListener("DOMContentLoaded", function() { 49 apply_rules(); 50 }); 51}
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.