1 2// Check if something is empty 3function isEmpty(str) { 4 return !str || 0 === str.length; 5} 6 7// List of invalid parameters to not make sticky like wistia, 404 etc 8var invalidParams = ["v", "wtime", "offset", "reversePaginate", "seek_to_second_number", "404"]; 9 10$(document).ready(function () { 11 12 // Add alert codes param key to the invalid params list 13 if (typeof acKey !== 'undefined' && !isEmpty(acKey)) { 14 invalidParams.push(acKey); 15 } 16 17 // Add search query param key to the invalid params list 18 if (typeof sqKey !== 'undefined' && !isEmpty(sqKey)) { 19 invalidParams.push(sqKey); 20 } 21 22 // Init 23 initParameterSticky(); 24}); 25 26/** 27 * Initializes sticky parameters for the page. 28 * - Retrieves current URL query parameters excluding the "invalidParams" 29 * - Builds a new query string with updated parameters. 30 * - Updates all internal links on the page, adding or updating their query parameters. 31 * This includes handling existing query parameters in links to avoid duplicates. 32 * If both the page URL and anchor link have same param key, we give priority to anchor one 33 */ 34function initParameterSticky() { 35 36 // Retrieve query string of parameters from the current page's URL 37 var pageQs = window.location.search; 38 var pageParams = getQueryParams(pageQs); 39 40 // Encode email once before the loop (skip if already encoded) 41 if (typeof emailKey !== 'undefined' && !isEmpty(pageParams[emailKey]) && !isBase64UrlEncoded(pageParams[emailKey])) { 42 pageParams[emailKey] = base64UrlEncode(pageParams[emailKey]); 43 } 44 45 // Get all links on the page 46 var ye_links = document.getElementsByTagName("a"); 47 48 // Loop through all the links on the page 49 for (var i = 0; i < ye_links.length; i++) { 50 var ye_link = ye_links[i]; 51 52 // Skip links without href attribute 53 if (!ye_link.hasAttribute('href') || !ye_link.href) { 54 continue; 55 } 56 57 // Skip certain types of links 58 if ( 59 ye_link.getAttribute('href').startsWith("#") || 60 ye_link.href.startsWith("tel:") || 61 ye_link.href.startsWith("sms:") || 62 ye_link.href.startsWith("mailto:") 63 ) { 64 continue; 65 } 66 67 // Parse existing query parameters in the link 68 var linkUrl = new URL(ye_link.href, window.location.origin); 69 var linkParams = getQueryParams(linkUrl.search); 70 71 // Add page params to this link 72 for (var key in pageParams) { 73 74 // Skip invalid params 75 if (invalidParams.includes(key)) { continue; } 76 77 // Only add if the link doesn't already have this parameter 78 if (!(key in linkParams)) { 79 linkParams[key] = pageParams[key]; 80 } 81 } 82 83 // Reconstruct the link's URL with updated query parameters 84 linkUrl.search = buildQueryString(linkParams); 85 ye_link.href = linkUrl.href; 86 } 87} 88 89// Used to convert query param to object 90function getQueryParams(query) { 91 const qs = query.replace(/^\?/, ""); 92 const params = {}; 93 94 if (!isEmpty(qs)) { 95 qs.split("&").forEach((param) => { 96 const [key, value] = param.split("="); 97 params[decodeURIComponent(key)] = decodeURIComponent(value); 98 }); 99 } 100 101 return params; 102} 103 104// URL-safe Base64 encode to match Java's Base64.encodeBase64URLSafe (replaces + with -, / with _, and strips = padding) 105function base64UrlEncode(str) { 106 return btoa(str).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); 107} 108 109// Returns true if the value is already Base64 URL-safe encoded (i.e. only contains valid Base64 URL-safe characters) 110function isBase64UrlEncoded(str) { 111 return /^[A-Za-z0-9\-_]+$/.test(str); 112} 113 114// Used to convert object to string query 115function buildQueryString(params) { 116 if (Object.keys(params).length === 0) { return ""; } 117 return Object.keys(params).map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join("&"); 118}
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.