1let initialOffset = 0; 2 3function returnCorrectSite() { 4 const currentUrl = window.location.href; 5 const url = new URL(currentUrl); 6 const domain = url.hostname; 7 const subdomain = domain.split(".")[1]; 8 const prodSite = `${url.protocol}//${url.hostname}`; 9 const preprodSite = `${url.protocol}//${url.host}${url.pathname 10 .split("/") 11 .slice(0, 3) 12 .join("/")}`; 13 14 return subdomain.includes("rhcscmgr") ? preprodSite : prodSite; 15} 16 17function handleCloseMessage(messageId) { 18 const messageWrapper = document.getElementById(messageId); 19 20 if (messageWrapper) { 21 messageWrapper.remove(); 22 } 23 24 let closedMessageIds = localStorage.getItem("closedMessageIds"); 25 26 closedMessageIds = closedMessageIds ? JSON.parse(closedMessageIds) : []; 27 28 closedMessageIds.push(messageId); 29 30 localStorage.setItem("closedMessageIds", JSON.stringify(closedMessageIds)); 31} 32 33function isMessageClosed(messageId) { 34 const closedMessageIds = 35 JSON.parse(localStorage.getItem("closedMessageIds")) || []; 36 37 return closedMessageIds.includes(messageId); 38} 39 40function generateIdFromString(inputString) { 41 let hash = 0; 42 43 if (inputString.length === 0) { 44 return hash; 45 } 46 47 for (let i = 0; i < inputString.length; i++) { 48 const char = inputString.charCodeAt(i); 49 hash = (hash << 5) - hash + char; 50 hash = hash & hash; // Convert to 32bit integer 51 } 52 53 return hash; 54} 55 56function handleSitecoreNotifications(a) { 57 var currentURL = window.location.href; 58 var domain = currentURL.split("/")[2]?.toLowerCase(); 59 var preprodPath = currentURL.split("/")[3]?.toLowerCase(); 60 61 const isRamsayPharmacy = 62 domain === "www.ramsaypharmacy.com.au" || 63 preprodPath.toLowerCase() === "pharmacyv2"; 64 const isRamsayPlus = 65 domain === "www.ramsayhealthplus.com.au" || 66 preprodPath.toLowerCase() === "plus"; 67 68 const mainNavContainer = document.getElementById("MainNavBar"); 69 70 let currentMessages = []; 71 72 if (typeof sitecoreNotifications !== "undefined") { 73 sitecoreNotifications?.forEach((e) => { 74 if (e?.Message) { 75 currentMessages.push(e.Message); 76 } 77 }); 78 } 79 80 if (!currentMessages || (currentMessages && currentMessages.length === 0)) { 81 return; 82 } 83 84 const messageContainer = document.createElement("div"); 85 initialOffset = messageContainer.offsetTop; 86 87 messageContainer.id = "NotificationMessageContainer"; 88 messageContainer.style.width = "100%"; 89 messageContainer.style.position = "relative"; 90 messageContainer.style.top = "0"; 91 messageContainer.style.zIndex = "1000"; 92 93 94 95 for (let i = 0; i < currentMessages.length; i++) { 96 97 const msg = currentMessages[i]; 98 99 const currentUrl = window.location.href; 100 const url = new URL(currentUrl); 101 let domain = url.hostname; 102 103 if(domain.includes("vwidc") || domain.includes("rhcsmgr")) { 104 105 domain = url.pathname 106 .split("/") 107 .slice(0, 2) 108 .join("/") 109 110 } 111 112 const messageId = generateIdFromString(msg + domain); 113 114 if (isMessageClosed(messageId)) { 115 // Skip the rest of the code block for closed messages in this iteration 116 continue; 117 } 118 119 const messageWrapper = document.createElement("div"); 120 messageWrapper.id = messageId; 121 messageWrapper.style.position = "relative"; 122 messageWrapper.style.width = "100%"; 123 124 if (currentMessages.length === 1) { 125 messageWrapper.style.backgroundColor = "#0b2f50"; 126 127 if (isRamsayPlus) { 128 messageWrapper.style.backgroundColor = "#ffb71b"; 129 } 130 131 if (isRamsayPharmacy) { 132 messageWrapper.style.backgroundColor = "#643398"; 133 } 134 } else if (i % 2 === 0) { 135 messageWrapper.style.backgroundColor = "#0b2f50"; 136 137 if (isRamsayPlus) { 138 messageWrapper.style.backgroundColor = "#f05223"; 139 } 140 141 if (isRamsayPharmacy) { 142 messageWrapper.style.backgroundColor = "#39aaa7"; 143 } 144 } else { 145 messageWrapper.style.backgroundColor = "#0079c7"; 146 147 if (isRamsayPlus) { 148 messageWrapper.style.backgroundColor = "#ffb71b"; 149 } 150 151 if (isRamsayPharmacy) { 152 messageWrapper.style.backgroundColor = "#643398"; 153 } 154 } 155 156 const messageElement = document.createElement("div"); 157 messageElement.style.position = "relative"; 158 messageElement.style.maxWidth = "800px"; 159 messageElement.style.textAlign = "center"; 160 messageElement.style.padding = "24px 6px 12px 6px"; 161 messageElement.style.boxSizing = "content-box"; 162 messageElement.style.display = "block"; 163 messageElement.style.margin = "0 auto"; 164 messageElement.innerHTML = msg; 165 166 const closeButtonContainer = document.createElement("div"); 167 closeButtonContainer.style.position = "absolute"; 168 closeButtonContainer.style.top = "6px"; 169 closeButtonContainer.style.right = "12px"; 170 closeButtonContainer.style.color = "white"; 171 closeButtonContainer.style.cursor = "pointer"; 172 closeButtonContainer.innerHTML = "x"; 173 closeButtonContainer.style.zIndex = "1001"; 174 175 messageWrapper.appendChild(closeButtonContainer); 176 messageWrapper.appendChild(messageElement); 177 messageContainer.appendChild(messageWrapper); 178 179 closeButtonContainer.addEventListener("click", () => { 180 handleCloseMessage(messageId); 181 }); 182 } 183 184 // Find all anchor tags with spans 185 var anchorTags = messageContainer.querySelectorAll("a"); 186 187 // Loop through each anchor tag and set the underline color
188 anchorTags.forEach(function (ele) { 189 const firstChildColor = ele?.firstChild?.style?.color; 190 // if is a portal condition, else is a sitecore notification condition 191 if (firstChildColor) { 192 ele.style.textDecoration = `underline ${firstChildColor}`; 193 } else { 194 const parentEle = ele.parentElement; 195 196 if (parentEle) { 197 const parentEleColor = parentEle.style.color; 198 199 if (parentEleColor) { 200 ele.style.textDecoration = `underline ${parentEleColor}`; 201 ele.style.color = parentEleColor; 202 } 203 } 204 } 205 }); 206 207 208 document.body.insertBefore(messageContainer, document.body.firstChild); 209 210 if (mainNavContainer) { 211 const currentMessageContainer = document.getElementById( 212 "NotificationMessageContainer" 213 ); 214 215 mainNavContainer.style.marginTop = 216 currentMessageContainer.offsetHeight + "px"; 217 } 218 219 function togglePosition(container) { 220 let difference = 56; 221 222 if (currentMessages && currentMessages.length > 1) { 223 difference = 112; 224 } 225 226 if (container && container.classList.contains("absoluteNav")) { 227 container.style.marginTop = difference.toString() + "px"; 228 } 229 230 if (window.scrollY >= initialOffset + difference) { 231 container.style.position = "sticky"; 232 container.style.top = "0"; 233 container.style.zIndex = "99999"; 234 container.style.marginTop = "0px"; 235 } else { 236 container.style.position = "relative"; 237 container.style.top = "auto"; 238 container.style.zIndex = "auto"; 239 } 240 } 241 242 togglePosition(messageContainer); 243 244 window.onscroll = function () { 245 togglePosition(messageContainer); 246 }; 247} 248 249document.addEventListener("DOMContentLoaded", () => { 250handleSitecoreNotifications(); 251});
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.