/* @license GPL-2.0-or-later https://www.drupal.org/licensing/faq */ (function($,Drupal,drupalSettings){let callback;let loadAlert=function(siteAlert){let options={ajax_page_state:drupalSettings.ajaxPageState};siteAlert.load(callback,options);if(drupalSettings.siteAlert.timeout>0)setTimeout(function(){loadAlert(siteAlert);},drupalSettings.siteAlert.timeout*1000);};Drupal.behaviors.siteAlert={attach:function(context,settings){if(drupalSettings.siteAlert.workaround_needed){callback=settings.path.baseUrl+'ajax/site_alert';loadAlert($('.site-alert',context));}if(drupalSettings.siteAlert.timeout>0){callback=settings.path.baseUrl+'ajax/site_alert';setTimeout(function(){loadAlert($('.site-alert',context));},drupalSettings.siteAlert.timeout*1000);}}};})(jQuery,Drupal,drupalSettings);; (function(Drupal,drupalSettings,once){const sitewideAlertsSelector='[data-sitewide-alert]';const shouldShowOnThisPage=(pages=[],negate=true)=>{if(pages.length===0)return true;let pagePathMatches=false;const currentPath=window.location.pathname;for(let i=0;i{if(!(`alert-dismissed-${alert.uuid}` in window.localStorage))return false;const dismissedAtTimestamp=Number(window.localStorage.getItem(`alert-dismissed-${alert.uuid}`));return dismissedAtTimestamp>=alert.dismissalIgnoreBefore;};const dismissAlert=(alert)=>{window.localStorage.setItem(`alert-dismissed-${alert.uuid}`,String(Math.round(new Date().getTime()/1000)));document.querySelectorAll(`[data-uuid="${alert.uuid}"]`).forEach((alert)=>{alert.dispatchEvent(new CustomEvent('sitewide-alert-dismissed',{bubbles:true,composed:true}));removeAlert(alert);});};const buildAlertElement=(alert)=>{const alertElement=document.createElement('div');alertElement.innerHTML=alert.renderedAlert;if(alert.dismissible){const dismissButtons=alertElement.getElementsByClassName('js-dismiss-button');for(let i=0;idismissAlert(alert));}return alertElement.firstElementChild;};const removeAlert=(alert)=>{alert.dispatchEvent(new CustomEvent('sitewide-alert-removed',{bubbles:true,composed:true}));alert.remove();};const fetchAlerts=()=>{return fetch(`${window.location.origin+drupalSettings.path.baseUrl+drupalSettings.path.pathPrefix}sitewide_alert/load`).then((res)=>res.json()).then((result)=>result.sitewideAlerts,(error)=>{console.error(error);});};const removeStaleAlerts=(alerts)=>{const roots=document.querySelectorAll(sitewideAlertsSelector);roots.forEach((root)=>{const existingAlerts=root.querySelectorAll('[data-uuid]');const alertsToBeRemoved=Array.from(existingAlerts).filter((alert)=>!alerts.includes(alert.getAttribute('data-uuid')));alertsToBeRemoved.forEach((alert)=>removeAlert(alert));});};const initAlerts=()=>{const roots=document.querySelectorAll(sitewideAlertsSelector);fetchAlerts().then((alerts)=>{removeStaleAlerts(alerts);alerts.forEach((alert)=>{const dismissed=alertWasDismissed(alert);const showOnThisPage=shouldShowOnThisPage(alert.showOnPages,alert.negateShowOnPages);roots.forEach((root)=>{const existingAlertElement=root.querySelector(`[data-uuid="${alert.uuid}"]`);if(showOnThisPage&&!dismissed){const renderableAlertElement=buildAlertElement(alert);existingAlertElement?root.replaceChild(renderableAlertElement,existingAlertElement):root.appendChild(renderableAlertElement);renderableAlertElement.dispatchEvent(new CustomEvent('sitewide-alert-rendered',{bubbles:true,composed:true}));return;}if((dismissed||!showOnThisPage)&&existingAlertElement)removeAlert(existingAlertElement);});});});};const supportsHistoryPushState=()=>{return ('pushState' in window.history&&window.history['pushState']!==null);};const supportsHistoryReplaceState=()=>{return ('replaceState' in window.history&&window.history['replaceState']!==null);};const proxyPushState=()=>{if(supportsHistoryPushState())window.history.pushState=new Proxy(window.history.pushState,{apply(target,thisArg,argArray){triggerHistoryEvent(thisArg,argArray);return target.apply(thisArg,argArray);}});if(supportsHistoryReplaceState())window.history.replaceState=new Proxy(window.history.replaceState,{apply(target,thisArg,argArray){triggerHistoryEvent(thisArg,argArray);return target.apply(thisArg,argArray);}});};const triggerHistoryEvent=(thisArg,argArray)=>{const event=new CustomEvent('sitewidealerts.popstate',{detail:{state:thisArg,options:argArray}});window.dispatchEvent(event);};const historyListener=()=>{window.addEventListener('sitewidealerts.popstate',()=>initAlerts());window.addEventListener('popstate',()=>initAlerts());};Drupal.behaviors.sitewide_alert_init={attach:(context)=>{once('sitewide_alerts_init','html',context).forEach(()=>{initAlerts();proxyPushState();historyListener();if(drupalSettings.sitewideAlert.automaticRefresh===true){const interval=setInterval(()=>initAlerts(),drupalSettings.sitewideAlert.refreshInterval<1000?1000:drupalSettings.sitewideAlert.refreshInterval);if(!drupalSettings.sitewideAlert.automaticRefresh)clearInterval(interval);}});}};})(Drupal,drupalSettings,once);;