1/** 2 * Region Cookie Standalone 3 * 4 * Reads the "region" cookie and removes elements with a `data-region` 5 * attribute that do not match the active region. Only the matching content 6 * stays in the DOM. 7 * 8 * Usage: 9 * <script src="region-cookie-standalone.js"></script> 10 * 11 * <p data-region="QC">Visible in Quebec</p> 12 * <p data-region="ON MB AB BC">Visible outside Quebec</p> 13 * 14 * The active region is read from the URL parameter first, then the cookie, 15 * then `<meta name="region-default" content="QC">`, then `data-region-default` 16 * on <body> or <html>, then falls back to "QC". 17 * 18 * Special value: region=ALL â keeps every data-region element visible (useful 19 * for previewing all regional variants on the same page at once). 20 */ 21(function () { 22 'use strict'; 23 24 var COOKIE_NAME = 'region'; 25 var VALID_REGIONS = ['ON', 'MB', 'AB', 'BC', 'QC']; 26 var FALLBACK_REGION = 'QC'; 27 var EXCLUDE_SELECTOR = '.dizz-footer-fluid'; 28 29 function getCookie(name) { 30 var match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)')); 31 return match ? decodeURIComponent(match[1]).trim().toUpperCase() : null; 32 } 33 34 function getUrlParam(name) { 35 var url = new URL(window.location.href); 36 var value = url.searchParams.get(name); 37 return value ? value.trim().toUpperCase() : null; 38 } 39 40 function processRegionElements(active) { 41 var elements = document.querySelectorAll('[data-region]'); 42 for (var i = elements.length - 1; i >= 0; i--) { 43 var el = elements[i]; 44 // Skip anything inside the footer â it's excluded from region logic 45 if (el.closest(EXCLUDE_SELECTOR)) { 46 continue; 47 } 48 if (active === 'ALL') { 49 // Show every regional variant â just strip the attribute, remove nothing 50 el.removeAttribute('data-region'); 51 } else { 52 var regions = (el.getAttribute('data-region') || '').split(/\s+/); 53 if (regions.indexOf(active) === -1) { 54 var parent = el.parentNode; 55 if (parent) parent.removeChild(el); 56 } else { 57 el.removeAttribute('data-region'); 58 } 59 } 60 } 61 } 62 63 function getDefaultRegion() { 64 var meta = document.querySelector('meta[name="region-default"]'); 65 var metaDefault = meta && meta.getAttribute('content'); 66 var bodyDefault = document.body && document.body.getAttribute('data-region-default'); 67 var htmlDefault = document.documentElement.getAttribute('data-region-default'); 68 var candidate = (metaDefault || bodyDefault || htmlDefault || FALLBACK_REGION).toUpperCase(); 69 return VALID_REGIONS.indexOf(candidate) !== -1 ? candidate : FALLBACK_REGION; 70 } 71 72 function init() { 73 // URL param wins (useful for local testing), then cookie, then default 74 var active = getUrlParam(COOKIE_NAME) || getCookie(COOKIE_NAME) || getDefaultRegion(); 75 if (active !== 'ALL' && VALID_REGIONS.indexOf(active) === -1) { 76 active = getDefaultRegion(); 77 } 78 processRegionElements(active); 79 } 80 81 if (document.readyState === 'loading') { 82 document.addEventListener('DOMContentLoaded', init); 83 } else { 84 init(); 85 } 86})();
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.