kollapsminoriteten/wp-content/plugins/the-events-calendar/common/build/js/ian-client.js

1 line
8.0 KiB
JavaScript
Raw Normal View History

2025-12-12 13:13:07 +01:00
(()=>{var e;e=window.commonIan||(window.commonIan={}),window.addEventListener("load",(function(t){e.icon=document.querySelector('[data-tec-ian-trigger="iconIan"]'),e.sidebar=document.querySelector('[data-tec-ian-trigger="sideIan"]'),e.notifications=document.querySelector('[data-tec-ian-trigger="notifications"]'),e.readAll=document.querySelector('[data-tec-ian-trigger="readAllIan"]'),e.optin=document.querySelector('[data-tec-ian-trigger="optinIan"]'),e.close=document.querySelector('[data-tec-ian-trigger="closeIan"]'),e.empty=document.querySelector('[data-tec-ian-trigger="emptyIan"]'),e.loader=document.querySelector('[data-tec-ian-trigger="loaderIan"]'),e.consent=e.notifications.dataset.consent,e.feed={read:[],unread:[]};const n=n=>{switch(i(),n.target.dataset.tecIanTrigger){case"iconIan":n.preventDefault(),n.stopPropagation(),e.sidebar.classList.toggle("is-hidden"),e.icon.classList.toggle("active");break;case"closeIan":n.preventDefault(),n.stopPropagation(),e.sidebar.classList.add("is-hidden"),e.icon.classList.remove("active");break;case"optinIan":n.preventDefault(),n.stopPropagation(),s();break;case"dismissIan":n.preventDefault(),n.stopPropagation(),c(n.target.dataset.id,n.target.dataset.slug);break;case"readIan":n.preventDefault(),n.stopPropagation(),t.stopPropagation(),l(n.target.dataset.id,n.target.dataset.slug);break;case"readAllIan":n.preventDefault(),n.stopPropagation(),p();break;default:console.log("e.composedPath",n.composedPath())}},a=()=>{const e=document.querySelector(".wrap .ian-header");let t={top:0,height:0};e&&(t=e.getBoundingClientRect());let n=document.getElementById("tribe-settings-tabs");n&&(n=window.innerWidth>500?n:document.querySelector(".tec-settings-header-wrap"),t=n.getBoundingClientRect());const a=document.getElementById("tec-admin-page-header");return a&&(t=a.getBoundingClientRect()),t.top+t.height},i=()=>{const t=a();e.sidebar.style.top=`${t}px`};let d=!1;const o=()=>{const t=window.innerWidth>782?32:window.innerWidth>600?46:0;window.scrollY,a()<=t?e.sidebar.style.top=t+"px":i(),d=!1},s=async()=>{e.optin.classList.add("disable"),e.loader.classList.remove("is-hidden");const t=new FormData;t.append("action","ian_optin"),t.append("nonce",e.nonce);try{(await fetch(e.ajaxUrl,{method:"POST",credentials:"same-origin",body:t}).then((e=>e.json()))).success&&r()}catch(e){console.error("Error during opt-in:",e)}finally{e.optin.classList.remove("disable"),e.loader.classList.add("is-hidden")}},r=async t=>{e.notifications.classList.remove("is-hidden"),t||e.loader.classList.remove("is-hidden");const n=new FormData;n.append("action","ian_get_feed"),n.append("nonce",e.nonce),n.append("plugin",g());try{const t=await fetch(e.ajaxUrl,{method:"POST",credentials:"same-origin",body:n}).then((e=>e.json()));if(e.loader.classList.add("is-hidden"),t.success)if(e.optin&&e.optin.remove(),0===t.data.length)e.feed={read:[],unread:[]},e.notifications.classList.add("is-hidden"),e.empty.classList.remove("is-hidden");else{let n="",a="";Object.entries(t.data).forEach((([e,t])=>{t.read?(n+=t.html,commonIan.feed.read.push(t)):(a+=t.html,commonIan.feed.unread.push(t))}));const i=`<div class="ian-sidebar__separator"><div>${e.readTxt}</div><span></span></div>`;e.notifications.innerHTML=a+i+n}m()}catch(e){console.error("Error fetching Ian feed:",e)}finally{e.loader.classList.add("is-hidden")}},c=async(t,n)=>{e.loader.classList.remove("is-hidden");const a=document.getElementById(`notification_${t}`);a.classList.add("fade-out");const i=new FormData;i.append("action","ian_dismiss"),i.append("slug",n),i.append("id",t),i.append("nonce",a.dataset.nonce);try{const n=await fetch(e.ajaxUrl,{method:"POST",credentials:"same-origin",body:i}).then((e=>e.json()));if(e.loader.classList.add("is-hidden"),n.success){a.remove();const{read:n,unread:i}=e.feed,d=e=>e.filter((e=>e.id!==parseInt(t)));e.feed.read=d(n),e.feed.unread=d(i),m()}else console.error("Failed to dismiss notification:",n.message||"Unknown error")}catch(e){console.error("Error dismissing notification:",e)}finally{e.loader.classList.add("is-hidden")}},l=async(t,n)=>{e.reading=t,e.loader