1/** 2 * Intercept clicks on configured Shopify store links for logged-in customers 3 * and route them through the Multipass bridge so they arrive signed in. 4 * 5 * Only the first store click in a session goes through Multipass. After that, 6 * opi_shopify_sso is set and clicks go straight to Shopify. 7 */ 8(function () { 9 'use strict'; 10 11 var config = window.OPI_SHOPIFY_MULTIPASS; 12 if (!config || !config.storeDomain || !config.bridgeUrl) { 13 return; 14 } 15 16 var storeDomain = String(config.storeDomain).toLowerCase().replace(/^www\./, ''); 17 var bridgeUrl = config.bridgeUrl; 18 var ssoCookie = config.ssoCookie || 'opi_shopify_sso'; 19 20 function hasCookie(name) { 21 return document.cookie.indexOf(name + '=') !== -1; 22 } 23 24 function isLoggedIn() { 25 return hasCookie('opi_is_logged_in'); 26 } 27 28 function alreadySsoed() { 29 return hasCookie(ssoCookie); 30 } 31 32 function hostnameMatchesStore(hostname) { 33 if (!hostname) { 34 return false; 35 } 36 var host = String(hostname).toLowerCase().replace(/^www\./, ''); 37 return host === storeDomain; 38 } 39 40 function findAnchor(el) { 41 while (el && el !== document) { 42 if (el.tagName && el.tagName.toLowerCase() === 'a' && el.href) { 43 return el; 44 } 45 el = el.parentNode; 46 } 47 return null; 48 } 49 50 function buildBridgeUrl(targetHref) { 51 var sep = bridgeUrl.indexOf('?') === -1 ? '?' : '&'; 52 return bridgeUrl + sep + 'return_to=' + encodeURIComponent(targetHref); 53 } 54 55 document.addEventListener('click', function (event) { 56 if (event.defaultPrevented) { 57 return; 58 } 59 if (event.button !== 0) { 60 return; 61 } 62 if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { 63 return; 64 } 65 if (!isLoggedIn()) { 66 return; 67 } 68 // Already Multipass'd this session â let the store link navigate normally. 69 if (alreadySsoed()) { 70 return; 71 } 72 73 var anchor = findAnchor(event.target); 74 if (!anchor || !anchor.href) { 75 return; 76 } 77 78 if (anchor.href.indexOf('/sso/shopify') !== -1) { 79 return; 80 } 81 82 var url; 83 try { 84 url = new URL(anchor.href, window.location.href); 85 } catch (e) { 86 return; 87 } 88 89 if (!hostnameMatchesStore(url.hostname)) { 90 return; 91 } 92 93 event.preventDefault(); 94 95 var dest = buildBridgeUrl(url.href); 96 var target = (anchor.getAttribute('target') || '').toLowerCase(); 97 98 if (target === '_blank') { 99 window.open(dest, '_blank', 'noopener,noreferrer'); 100 } else { 101 window.location.href = dest; 102 } 103 }, true); 104})();
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.