1 line
889 B
JavaScript
1 line
889 B
JavaScript
document.addEventListener("DOMContentLoaded",function(){const e=document.querySelector(".wp-block-telex-company-timeline");if(!e)return;const t=e.querySelector(".timeline-sidebar"),r=e.querySelectorAll(".year-link"),n=e.querySelectorAll(".timeline-entry");if(!t||0===r.length||0===n.length)return;r.forEach(t=>{t.addEventListener("click",function(t){t.preventDefault();const r=this.getAttribute("data-year")||this.getAttribute("href").replace("#year-",""),n=e.querySelector(`[data-year="${r}"]`);n&&n.scrollIntoView({behavior:"smooth",block:"start"})})});const o=new IntersectionObserver(t=>{t.forEach(t=>{if(t.isIntersecting){const n=t.target.getAttribute("data-year");r.forEach(e=>e.classList.remove("active"));const o=e.querySelector(`.year-link[data-year="${n}"]`);o&&o.classList.add("active")}})},{root:null,rootMargin:"-20% 0px -70% 0px",threshold:0});n.forEach(e=>{o.observe(e)})}); |