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

1 line
8.0 KiB
JavaScript
Raw Normal View History

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