1(function () { 2 var STORAGE_KEY = 'callrec:profileId'; 3 4 function getProfileIdFromUrl() { 5 return new URLSearchParams(window.location.search).get('profileId') || ''; 6 } 7 8 function setStoredProfileId(profileId) { 9 if (profileId) { 10 localStorage.setItem(STORAGE_KEY, profileId); 11 } else { 12 localStorage.removeItem(STORAGE_KEY); 13 } 14 } 15 16 function getStoredProfileId() { 17 return localStorage.getItem(STORAGE_KEY) || ''; 18 } 19 20 function buildUrlWithProfileId(pathname, searchParams, profileId) { 21 var params = new URLSearchParams(searchParams.toString()); 22 params.delete('companyId'); 23 24 if (profileId) { 25 params.set('profileId', profileId); 26 } else { 27 params.delete('profileId'); 28 } 29 30 var query = params.toString(); 31 return query ? pathname + '?' + query : pathname; 32 } 33 34 function shouldDecorateLink(href) { 35 if (!href || href.indexOf('/app/') !== 0) { 36 return false; 37 } 38 39 if (href.indexOf('/account/') === 0 || href.indexOf('/app/account/') === 0) { 40 return false; 41 } 42 43 return true; 44 } 45 46 function decorateNavLinks(profileId) { 47 if (!profileId) { 48 return; 49 } 50 51 document.querySelectorAll('.admin-nav-link, .admin-bottom-nav__link, #adminMoreMenu .admin-nav-link').forEach(function (link) { 52 var href = link.getAttribute('href'); 53 if (!shouldDecorateLink(href)) { 54 return; 55 } 56 57 try { 58 var url = new URL(href, window.location.origin); 59 if (url.searchParams.has('profileId')) { 60 return; 61 } 62 63 url.searchParams.set('profileId', profileId); 64 link.setAttribute('href', url.pathname + url.search + url.hash); 65 } catch (e) { 66 // ignore malformed href 67 } 68 }); 69 } 70 71 function syncProfileFromUrlOnLoad() { 72 if (!window.location.pathname.startsWith('/app')) { 73 return; 74 } 75 76 var urlProfileId = getProfileIdFromUrl(); 77 // Automations use an explicit personal scope when the query has no company. 78 if (window.location.pathname.startsWith('/app/automations')) { 79 setStoredProfileId(urlProfileId); 80 decorateNavLinks(urlProfileId); 81 return; 82 } 83 if (urlProfileId) { 84 setStoredProfileId(urlProfileId); 85 decorateNavLinks(urlProfileId); 86 return; 87 } 88 89 var storedProfileId = getStoredProfileId(); 90 if (storedProfileId) { 91 var targetUrl = buildUrlWithProfileId( 92 window.location.pathname, 93 new URLSearchParams(window.location.search), 94 storedProfileId 95 ); 96 window.location.replace(targetUrl); 97 return; 98 } 99 100 decorateNavLinks(''); 101 } 102 103 function initCompanySelector() { 104 var select = document.getElementById('admin-header-company-select'); 105 if (!select) { 106 return; 107 } 108 109 select.addEventListener('change', function () { 110 var profileId = select.value || ''; 111 var changing = new CustomEvent('callrec:profile-changing', { cancelable: true, detail: { profileId: profileId } }); 112 if (!window.dispatchEvent(changing)) { 113 select.value = getProfileIdFromUrl(); 114 return; 115 } 116 setStoredProfileId(profileId); 117 var automationPage = window.location.pathname.startsWith('/app/automations'); 118 var targetUrl = buildUrlWithProfileId( 119 automationPage ? '/app/automations' : window.location.pathname, 120 new URLSearchParams(automationPage ? '' : window.location.search), 121 profileId 122 ); 123 window.location.assign(targetUrl); 124 }); 125 } 126 127 function initMoreMenu() { 128 var moreMenu = document.getElementById('adminMoreMenu'); 129 if (!moreMenu) { 130 return; 131 } 132 133 moreMenu.querySelectorAll('.admin-nav-link').forEach(function (link) { 134 link.addEventListener('click', function () { 135 var offcanvas = bootstrap.Offcanvas.getInstance(moreMenu); 136 if (offcanvas) { 137 offcanvas.hide(); 138 } 139 }); 140 }); 141 } 142 143 syncProfileFromUrlOnLoad();
144 initCompanySelector(); 145 initMoreMenu(); 146})();
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.