function shareOnFacebook() { var encodedUrl=encodeURIComponent(window.location.href); var facebookUrl=’https://www.facebook.com/sharer/sharer.php?u=’ + encodedUrl; window.open(facebookUrl); } function shareOnTwitter() { var encodedUrl=encodeURIComponent(window.location.href); var twitterUrl=’https://twitter.com/intent/tweet?url=’ + encodedUrl; window.open(twitterUrl); } function shareByEmail() { var encodedUrl=encodeURIComponent(window.location.href); var subject=’Echa un vistazo a este enlace’; var body=’¡Hola! He encontrado este enlace interesante: ‘ + window.location.href; var mailtoUrl=’mailto:?subject=’ + encodeURIComponent(subject) + ‘&body=’ + encodeURIComponent(body); window.location.href=mailtoUrl; } function shareOnWhatsApp() { var encodedUrl=encodeURIComponent(window.location.href); var whatsappUrl=isMobile==true ? ‘https://api.whatsapp.com/send?text=’ + encodedUrl : ‘https://web.whatsapp.com/send?text=’ + encodedUrl; window.open(whatsappUrl); } function copyToClipboard() { var tempInput=document.createElement(«input»); tempInput.value=window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); document.execCommand(«copy»); document.body.removeChild(tempInput); alert(«Enlace copiado al portapapeles: » + window.location.href); } // Import the functions you need from the SDKs you need import { initializeApp } from «https://www.gstatic.com/firebasejs/10.11.0/firebase-app.js»; import { getMessaging, getToken, onMessage } from «https://www.gstatic.com/firebasejs/10.11.0/firebase-messaging.js»; const notificationsStatusBadge=document.getElementById(«notificationsStatusBadge»); const notificationsSubscriptionForceEnable=document.getElementById(«notificationsSubscriptionForceEnable»); const mainIconNotificacionStatus=document.getElementById(«mainIconNotificacionStatus»); const mainIconNotificacionStatusEnabled=document.getElementById(«mainIconNotificationsEnabled»); const mainIconNotificacionStatusDisabled=document.getElementById(«mainIconNotificationsDisabled»); const firebaseConfig={«apiKey»:»AIzaSyC5GCxLosfC98gmTPQ16q2lnHrp28jHrRk»,»authDomain»:»alerta-digital-fe3d4.firebaseapp.com»,»projectId»:»alerta-digital-fe3d4″,»storageBucket»:»alerta-digital-fe3d4.firebasestorage.app»,»messagingSenderId»:»880056710334″,»appId»:»1:880056710334:web:f91f84002a6938cf735aef»,»measurementId»:»G-T1CDBZDVL5″}; const firebaseVersion=2; // Initialize Firebase const app=initializeApp(firebaseConfig); const messaging=getMessaging(app); var messagingNeedUpdate=false; if (‘serviceWorker’ in navigator) { navigator.serviceWorker.register(‘/firebase-messaging-sw.js?_v=v3-22′).then(function(registration) { }).catch(function(error) { }); } function checkSubscriptionDate(date, days) { let dateObject=new Date(date); if (isNaN(dateObject.getTime())) { return false; } let currentDate=new Date(); let pastDate=new Date(dateObject); pastDate.setDate(pastDate.getDate() + days); return currentDate>=pastDate; } function checkSubscriptionNotification(){ let localToken=pushSubscriptionLocalGet(); if(localToken==null){ return { subscribed: false, ask: true }; }else{ try { let tokenObj=JSON.parse(localToken); if(tokenObj?.date==null){ // VERSION ANTERIOR messagingNeedUpdate=true; tokenObj.date=’2026-04-01′; pushSubscriptionLocalSave(tokenObj); return { subscribed: true, ask: true, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } if(tokenObj?.subscribed==1 || tokenObj?.subscribed==true){ // Subscrito if(tokenObj?.firebaseVersion !=firebaseVersion){ if(checkSubscriptionDate(tokenObj?.date, 7)){ messagingNeedUpdate=true; tokenObj.date=’2026-04-01’; pushSubscriptionLocalSave(tokenObj); return { subscribed: true, ask: true, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; }else{ return { subscribed: true, ask: false, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } }else{ return { subscribed: true, ask: false, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } }else{ // NO subscrito if(checkSubscriptionDate(tokenObj?.date, 7)){ return { subscribed: false, ask: true, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } return { subscribed: false, ask: false, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } } catch (error) { // Token incorrecto pushSubscriptionLocalRemove(); return { subscribed: false, ask: false, token: tokenObj?.token, firebaseVersion: tokenObj?.firebaseVersion }; } } } setTimeout(()=> { let subscriptionNotificationStatus=checkSubscriptionNotification(); if(subscriptionNotificationStatus?.ask){ const pushSubscriptionModal=document.getElementById(«pushSubscriptionModal»); const pushSubscriptionModalDetalle=document.getElementById(«pushSubscriptionModalDetalle»); const statusPagePushSubscriptionButton=document.getElementById(«statusPagePushSubscriptionButton»); const statusPagePushSubscriptionButtonDecline=document.getElementById(«statusPagePushSubscriptionButtonDecline»); if (pushSubscriptionModal) { statusPagePushSubscriptionButton.classList.add(«hidden»); pushSubscriptionModal.classList.remove(«hidden»); declinePushSubscription.classList.remove(«hidden»); acceptPushSubscription.classList.remove(«hidden»); if(messagingNeedUpdate){ pushSubscriptionModalDetalle.classList.remove(«hidden»); statusPagePushSubscriptionButton.classList.remove(«hidden»); statusPagePushSubscriptionButtonDecline.classList.remove(«hidden»); declinePushSubscription.classList.add(«hidden»); acceptPushSubscription.classList.add(«hidden»); } setTimeout(function() { pushSubscriptionModal.classList.add(«opacity-100»); }, 100); } } pushSubscriptionInit(subscriptionNotificationStatus); }, 3000 ); function pushSubscriptionInit(subscriptionNotificationStatus){ if («Notification» in window) { if(subscriptionNotificationStatus?.subscribed){ switch (Notification.permission) { case ‘granted’: pushSubscriptionOnMessage(); break; case ‘denied’: if(subscriptionNotificationStatus?.token){ savedTokenUnsubscribeAndDelete(subscriptionNotificationStatus?.token); } notificationsStatusBadgeUpdate(‘disabled’); break; default: pushSubscriptionRequestPermission(); break; } }else{ notificationsStatusBadgeUpdate(‘disabled’); } }else{ notificationsStatusBadgeUpdate(‘unsupported’); } } function pushSubscriptionRequestPermission(){ Notification.requestPermission().then(function(permission) { if (permission===’granted’) { getToken(messaging).then(function(token){ pushSubscriptionOnMessage(); }).catch(function(error) { }); } else { let tokenObj=pushSubscriptionLocalGet(); if(tokenObj?.token !=null){ savedTokenUnsubscribeAndDelete(tokenObj?.token); }else{ let tokenData={ «token»: null, «subscribed»: false, «date»: ‘2026-04-01’ } pushSubscriptionLocalSave(tokenData); } } }).catch(function(err) { notificationsStatusBadgeUpdate(‘error’); }); } function pushSubscriptionOnMessage(){ getToken(messaging).then(function(token){ saveTokenAndSubscribe(token); notificationsStatusBadgeUpdate(‘enabled’); onMessage(messaging, (payload)=> { if(!payload.data){ return false; } const toastContainer=document.createElement(‘div’); toastContainer.style.position=’fixed’; toastContainer.style.top=’20px’; toastContainer.style.right=’20px’; toastContainer.style.backgroundColor=’#333′; toastContainer.style.color=’white’; toastContainer.style.padding=’15px’; toastContainer.style.borderRadius=’5px’; toastContainer.style.zIndex=’100′; toastContainer.style.display=’block’; toastContainer.style.width=’300px’; document.body.appendChild(toastContainer); const toastTitle=document.createElement(‘p’); toastTitle.textContent=payload.notification.title; toastTitle.style.marginTop=’0′; toastTitle.style.fontSize=’10px’; toastContainer.appendChild(toastTitle); const toastBodyLink=document.createElement(‘a’); toastBodyLink.href=payload.data.link; const toastBody=document.createElement(‘h1′); toastBody.textContent=payload.notification.body; toastBody.style.marginBottom=’10px’; toastBodyLink.appendChild(toastBody); toastContainer.appendChild(toastBodyLink); const toastImageLink=document.createElement(‘a’); toastImageLink.href=payload.data.link; const toastImage=document.createElement(‘img’); toastImage.src=payload.notification.image; toastImage.alt=payload.notification.title; toastImage.style.display=’block’; toastImage.style.maxWidth=’100%’; toastImage.style.maxHeight=’120px’; toastImageLink.appendChild(toastImage); toastContainer.appendChild(toastImageLink); const closeButton=document.createElement(‘span’); closeButton.textContent=’×’; closeButton.className=’close’; closeButton.style.position=’absolute’; closeButton.style.top=’5px’; closeButton.style.right=’10px’; closeButton.style.cursor=’pointer’; closeButton.onclick=hideToast; toastContainer.appendChild(closeButton); function hideToast() { document.body.removeChild(toastContainer); } function openURL(url) { window.location.href=url; } }); }).catch(function(error) { notificationsStatusBadgeUpdate(‘error’); }); } function notificationsStatusBadgeUpdate(status){ if(notificationsStatusBadge){ notificationsStatusError.classList.add(«hidden»); notificationsSubscriptionForceEnable.classList.add(«hidden»); } if(mainIconNotificacionStatus){ mainIconNotificacionStatusDisabled.classList.add(«hidden»); } switch (status) { case «enabled»: if(notificationsStatusBadge){ notificationsStatusBadge.innerHTML=’SUSCRIPTO’; notificationsStatusBadge.style.backgroundColor=»#1b8724″; notificationsStatusBadge.style.color=»#ffffff»; } if(mainIconNotificacionStatus){ mainIconNotificacionStatusDisabled.classList.add(«hidden»); mainIconNotificacionStatusEnabled.classList.remove(«hidden»); } break; case «disabled»: if(notificationsStatusBadge){ notificationsStatusBadge.innerHTML=’NO SUSCRIPTO’; notificationsStatusBadge.style.backgroundColor=»#DDDDDD»; notificationsStatusBadge.style.color=»#333333″; notificationsSubscriptionForceEnable.classList.remove(«hidden»); } if(mainIconNotificacionStatus){ mainIconNotificacionStatusEnabled.classList.add(«hidden»); mainIconNotificacionStatusDisabled.classList.remove(«hidden»); } break; case «error»: if(notificationsStatusBadge){ notificationsStatusBadge.innerHTML=’EN PAUSA’; notificationsStatusBadge.style.backgroundColor=»#DDDDDD»; notificationsStatusBadge.style.color=»#333333″; notificationsStatusError.classList.remove(«hidden»); } if(mainIconNotificacionStatus){ mainIconNotificacionStatusEnabled.classList.add(«hidden»); mainIconNotificacionStatusDisabled.classList.remove(«hidden»); } break; case «unsupported»: if(notificationsStatusBadge){ notificationsStatusBadge.innerHTML=’NO SOPORTADO’; notificationsStatusBadge.style.backgroundColor=»#DDDDDD»; notificationsStatusBadge.style.color=»#333333″; } if(mainIconNotificacionStatus){ mainIconNotificacionStatusEnabled.classList.add(«hidden»); mainIconNotificacionStatusDisabled.classList.remove(«hidden»); } break; } } async function saveTokenAndSubscribe(token) { let localToken=pushSubscriptionLocalGet(); try { let tokenObj=JSON.parse(localToken); if(tokenObj?.token==token){ if(tokenObj?.firebaseVersion !=firebaseVersion){ /* Nueva version -> se subscribe */ return await firebaseSubscribeApi(token, tokenObj); }else{ /* Token local igual al token -> Se ignora */ } }else{ /* UNSUBSCRIBE ANTERIOR */ if(tokenObj?.token !=null){ savedTokenUnsubscribeAndDelete(tokenObj?.token); } return await firebaseSubscribeApi(token, tokenObj); } } catch (error) { } } async function firebaseSubscribeApi(token, tokenObj){ // SUBSCRIBE ACTUAL const formData=new URLSearchParams({ ‘token’: token }); try { const response=await fetch(apiURL + ‘firebase/token-subscribe/’, { method: ‘POST’, «headers»: { «content-type»: «application/x-www-form-urlencoded; charset=UTF-8», }, body: formData }); const data=await response.json(); if (data.success) { let tokenData={ «token»: token, «subscribed»: true, «firebaseVersion»: data?.data?.firebaseVersion, «date»: ‘2026-04-01’ } pushSubscriptionLocalSave(tokenData); } return data; } catch (error) { return null; } } function pushSubscriptionLocalSave(tokenObj){ window.localStorage.setItem(‘firebase-token’,JSON.stringify(tokenObj)); } function pushSubscriptionLocalGet(){ return window.localStorage.getItem(‘firebase-token’); } function pushSubscriptionLocalRemove(){ return window.localStorage.removeItem(‘firebase-token’); } async function savedTokenUnsubscribeAndDelete(token) { const url=apiURL + ‘firebase/token-unsubscribe/’; const formData=new URLSearchParams({ ‘token’: token }); try { const response=await fetch(url, { method: ‘POST’, «headers»: { «content-type»: «application/x-www-form-urlencoded; charset=UTF-8», }, body: formData }); const data=await response.json(); let tokenData={ «token»: null, «subscribed»: false, «date»: ‘2026-04-01’ } pushSubscriptionLocalSave(tokenData); return data; } catch (error) { // Handle error if necessary return null; } } if(notificationsSubscriptionForceEnable){ notificationsSubscriptionForceEnable.addEventListener(«click», function(event) { notificationsSubscriptionForceEnable.classList.add(«hidden»); pushSubscriptionModal.classList.add(«hidden»); let tokenData={ «token»: null, «subscribed»: true, «date»: ‘2026-04-01’ } pushSubscriptionLocalSave(tokenData); pushSubscriptionRequestPermission(); }) } var declinePushSubscription=document.getElementById(«declinePushSubscription»); declinePushSubscription.addEventListener(«click», function(event) { let pushSubscriptionModal=document.getElementById(«pushSubscriptionModal»); pushSubscriptionModal.classList.add(«hidden»); let tokenData={ «token»: null, «subscribed»: false, «date»: ‘2026-04-01’ } pushSubscriptionLocalSave(tokenData); }); var acceptPushSubscription=document.getElementById(«acceptPushSubscription»); acceptPushSubscription.addEventListener(«click», function(event) { pushSubscriptionModal.classList.add(«hidden»); let tokenData={ «token»: null, «subscribed»: true, «date»: ‘2026-04-01′ } pushSubscriptionLocalSave(tokenData); pushSubscriptionRequestPermission(); }); var statusPagePushSubscriptionButtonDecline=document.getElementById(«statusPagePushSubscriptionButtonDecline»); statusPagePushSubscriptionButtonDecline.addEventListener(«click», function(event) { let pushSubscriptionModal=document.getElementById(«pushSubscriptionModal»); pushSubscriptionModal.classList.add(«hidden»); }); var statusPagePushSubscriptionButton=document.getElementById(«statusPagePushSubscriptionButton»); statusPagePushSubscriptionButton.addEventListener(«click», function(event) { window.location.href=’/notificationstatus’; });
const modalPopup=document.getElementById(«bannerPopup»); let popup=JSON.parse(modalPopup.dataset.src); if(!popup?.id){ popup=popup[Math.floor(Math.random()*popup.length)]; } const cookieNamePopup=`popup-${popup.zonas_id}-${popup.id}`; const cookiePopup=getCookie(cookieNamePopup); if (!cookiePopup) { let img=modalPopup.querySelector(‘img’); let showPopup=false; if(isMobile){ switch (popup.banners_versiones_id) { case ‘1’: /* Compartida ( Desktop y Mobile ) */ img.setAttribute(‘src’, popup.image); img.style.width=`${popup.banner_ancho}.px`; popup.url=popup.url; popup.target=popup.target; showPopup=true; break; case ‘2’: /* Diferenciada ( Desktop / Mobile ) */ img.setAttribute(‘src’, popup.image_mobile); img.style.width=`${popup.mobile_ancho}.px`; popup.url=popup.url_mobile; popup.target=popup.target_mobile; showPopup=true; break; case ‘3’: /* Solo Desktop */ popup.url=null; popup.target=null; break; case ‘4’: /* Solo Mobile */ img.setAttribute(‘src’, popup.image_mobile) img.style.width=`${popup.mobile_ancho}.px`; popup.url=popup.url_mobile; popup.target=popup.target_mobile; showPopup=true; break; default: break; } }else{ switch (popup.banners_versiones_id) { case ‘1’: /* Compartida ( Desktop y Mobile ) */ img.setAttribute(‘src’, popup.image); img.style.height=`${popup.banner_alto}.px`; img.style.width=`${popup.banner_ancho}.px`; popup.url=popup.url; popup.target=popup.target; showPopup=true; break; case ‘2’: /* Diferenciada ( Desktop / Mobile ) */ img.setAttribute(‘src’, popup.image); img.style.height=`${popup.banner_alto}.px`; img.style.width=`${popup.banner_ancho}.px`; popup.url=popup.url; popup.target=popup.target; showPopup=true; break; case ‘3’: /* Solo Desktop */ img.setAttribute(‘src’, popup.image); img.style.height=`${popup.banner_alto}.px`; img.style.width=`${popup.banner_ancho}.px`; popup.url=popup.url; popup.target=popup.target; showPopup=true; break; case ‘4’: /* Solo Mobile */ popup.url=null; popup.target=null; break; default: break; } } if(showPopup){ if(popup.url_mobile || popup.url){ var enlace=document.createElement(‘a’); if(popup.target){ enlace.target=popup.target; } enlace.href=popup.url; enlace.appendChild(img.cloneNode()); img.parentNode.replaceChild(enlace, img); } modalPopup.classList.remove(«hidden»); let button=modalPopup.querySelector(‘button’); button.addEventListener(«click», ()=> { setCookieMinutes(cookieNamePopup, ‘closed’, cookiesBanners.zonaBannerPopup.minutosExpire); }); /**** Tracking Analytics ****/ // Banner //trackImpresion({ event_category: BANNER_DEFAULT_EVENT_CATEGORY, event_label: `${popup.label} | ${popup.id}` }); // Zona trackImpresion({ event_category: `${ZONA_BANNER_NOMBRE} | PopUp | ${popup.zonas_id}`, event_label: `${BANNER_NOMBRE} | ${popup.label} | ${popup.id}` }); modalPopup.addEventListener(«click», ()=> { // banner //trackClick({ event_category: BANNER_DEFAULT_EVENT_CATEGORY, event_label: `${popup.label} | ${popup.id}` }); // zona trackClick({ event_category: `${ZONA_BANNER_NOMBRE} | PopUp | ${popup.zonas_id}`, event_label: `${BANNER_NOMBRE} | ${popup.label} | ${popup.id}` }); modalPopup.classList.add(«hidden»); }); } }
const modalZocalo=document.getElementById(«bannerZocalo»); let zocalo=JSON.parse(modalZocalo.dataset.src); if(!zocalo?.id){ zocalo=zocalo[Math.floor(Math.random()*zocalo.length)]; } const cookieNameZocalo=`zocalo-${zocalo.zonas_id}-${zocalo.id}`; const cookieZocalo=getCookie(cookieNameZocalo); if (!cookieZocalo) { let img=modalZocalo.querySelector(‘img’); let showZocalo=false; if(isMobile){ switch (zocalo.banners_versiones_id) { case ‘1’: /* Compartida ( Desktop y Mobile ) */ img.setAttribute(‘src’, zocalo.image); img.style.width=`${zocalo.banner_ancho}.px`; zocalo.url=zocalo.url; zocalo.target=zocalo.target; showZocalo=true; break; case ‘2’: /* Diferenciada ( Desktop / Mobile ) */ img.setAttribute(‘src’, zocalo.image_mobile); img.style.width=`${zocalo.mobile_ancho}.px`; zocalo.url=zocalo.url_mobile; zocalo.target=zocalo.target_mobile; showZocalo=true; break; case ‘3’: /* Solo Desktop */ zocalo.url=null; zocalo.target=»; break; case ‘4’: /* Solo Mobile */ img.setAttribute(‘src’, zocalo.image_mobile) img.style.width=`${zocalo.mobile_ancho}.px`; zocalo.url=zocalo.url_mobile; zocalo.target=zocalo.target_mobile; showZocalo=true; break; default: break; } }else{ switch (zocalo.banners_versiones_id) { case ‘1’: /* Compartida ( Desktop y Mobile ) */ img.setAttribute(‘src’, zocalo.image); img.style.height=`${zocalo.banner_alto}.px`; img.style.width=`${zocalo.banner_ancho}.px`; zocalo.url=zocalo.url; zocalo.target=zocalo.target; showZocalo=true; break; case ‘2’: /* Diferenciada ( Desktop / Mobile ) */ img.setAttribute(‘src’, zocalo.image); img.style.height=`${zocalo.banner_alto}.px`; img.style.width=`${zocalo.banner_ancho}.px`; zocalo.url=zocalo.url; zocalo.target=zocalo.target; showZocalo=true; break; case ‘3’: /* Solo Desktop */ img.setAttribute(‘src’, zocalo.image); img.style.height=`${zocalo.banner_alto}.px`; img.style.width=`${zocalo.banner_ancho}.px`; zocalo.url=zocalo.url; zocalo.target=zocalo.target; showZocalo=true; break; case ‘4’: /* Solo Mobile */ zocalo.url=null; break; default: break; } } if(showZocalo){ if(zocalo.url){ var enlace=document.createElement(‘a’); if(zocalo.target){ enlace.target=zocalo.target; } enlace.href=zocalo.url; enlace.appendChild(img.cloneNode()); img.parentNode.replaceChild(enlace, img); } modalZocalo.classList.remove(«hidden»); let button=modalZocalo.querySelector(‘button’); button.addEventListener(«click», ()=> { setCookieMinutes(cookieNameZocalo, ‘closed’, cookiesBanners.zonaBannerZocalo.minutosExpire); }); /**** Tracking Analytics ****/ // Banner //trackImpresion({ event_category: BANNER_DEFAULT_EVENT_CATEGORY, event_label: `${zocalo.label} | ${zocalo.id}` }); // Zona trackImpresion({ event_category: `${ZONA_BANNER_NOMBRE} | Zocalo | ${zocalo.zonas_id}`, event_label: `${BANNER_NOMBRE} | ${zocalo.label} | ${zocalo.id}` }); modalZocalo.addEventListener(«click», ()=> { // banner // trackClick({ event_category: BANNER_DEFAULT_EVENT_CATEGORY, event_label: `${zocalo.label} | ${zocalo.id}` }); // zona trackClick({ event_category: `${ZONA_BANNER_NOMBRE} | Zocalo | ${zocalo.zonas_id}`, event_label: `${BANNER_NOMBRE} | ${zocalo.label} | ${zocalo.id}` }); modalZocalo.classList.add(«hidden»); }); } }









