/* The Raisina Post ยท halfway-only sticky article rails. Cards are part of the delivered HTML; this optional script only measures their first-half scroll boundary as the page loads and article height changes. */ export function midpointHeight(height){ const n=Number(height); return Number.isFinite(n)&&n>0?Math.round(n/2):0; } function activate(){ if(typeof window==='undefined'||typeof document==='undefined')return; for(const root of document.querySelectorAll('main.ra-article.rp-context-article')){ const grid=root.querySelector('.ra-story-grid'); const story=grid?.querySelector('article.ra-story-main'); const panels=grid?[...grid.children].filter(x=>x.matches('.rp-context-left,.rp-context-right')):[]; if(!story||!panels.length)continue; const refresh=()=>{ if(!window.matchMedia('(min-width:1260px)').matches){ for(const panel of panels)panel.style.removeProperty('--rp-rail-midpoint-height'); return; } const half=midpointHeight(story.getBoundingClientRect().height); for(const panel of panels)panel.style.setProperty('--rp-rail-midpoint-height',half+'px'); }; refresh(); if(typeof ResizeObserver!=='undefined')new ResizeObserver(refresh).observe(story); window.addEventListener('resize',refresh,{passive:true}); } } if(typeof document!=='undefined'){ if(document.readyState==='loading')document.addEventListener('DOMContentLoaded',activate,{once:true}); else activate(); }