1$(function () { 2 'use strict'; 3 4 function normalizePath(path) { 5 var normalized = decodeURIComponent(path || '/') 6 .split('?')[0] 7 .split('#')[0] 8 .replace(/\/+/g, '/') 9 .replace(/\/index\.(html?|pcf)$/i, '/') 10 .replace(/\.(html?|pcf)$/i, '') 11 .replace(/\/+$/, ''); 12 13 return normalized || '/'; 14 } 15 16 function getCurrentPaths() { 17 var paths = []; 18 19 // Normal live-page or preview URL. 20 if (window.location.pathname) { 21 paths.push(normalizePath(window.location.pathname)); 22 } 23 24 // Canonical URL, if the template provides one. 25 var canonical = document.querySelector('link[rel="canonical"]'); 26 27 if (canonical && canonical.href) { 28 try { 29 paths.push(normalizePath(new URL(canonical.href).pathname)); 30 } catch (error) { 31 // Ignore malformed canonical URLs. 32 } 33 } 34 35 // Base URL, if the CMS preview supplies one. 36 var base = document.querySelector('base'); 37 38 if (base && base.href) { 39 try { 40 paths.push(normalizePath(new URL(base.href).pathname)); 41 } catch (error) { 42 // Ignore malformed base URLs. 43 } 44 } 45 46 return paths.filter(function (path, index, array) { 47 return array.indexOf(path) === index; 48 }); 49 } 50 51 var currentPaths = getCurrentPaths(); 52 53 $('ul[data-nav-path] li a[href]').each(function () { 54 var href = this.getAttribute('href'); 55 56 if (!href || href.charAt(0) === '#') { 57 return; 58 } 59 60 var linkUrl; 61 62 try { 63 linkUrl = new URL(href, document.baseURI || window.location.href); 64 } catch (error) { 65 return; 66 } 67 68 var linkPath = normalizePath(linkUrl.pathname); 69 70 if (currentPaths.indexOf(linkPath) !== -1) { 71 $(this) 72 .attr('aria-current', 'page') 73 .addClass('active'); 74 } 75 }); 76});
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.