// MOBILE MENU const rMenu=()=>{ if (document.getElementById('rMenu') && window.addEventListener) { // check for top menu & browser support const menuFly=document.querySelectorAll('.rMenu>UL>LI'); const closeFly=()=>menuFly.forEach(fly=>fly.classList.remove('keyed')); const menuTogs=document.querySelectorAll('LI.hasFly>A'); const closeMenuTogs=()=>menuTogs.forEach(tog=>tog.parentElement.classList.remove('open')); const closeAll=(event)=>{ document.documentElement.classList.remove('menuOn'); closeFly(); closeMenuTogs(); } // close menu if click or focus away from menu document.addEventListener('click', function(event) { if (!event.target.closest('#rMenu') && !event.target.closest('#rMenuBtn')) { closeAll(event) } }, true); document.addEventListener('focus', function(event) { if (!event.target.closest('#rMenu')) { closeAll(event) } }, true); // menu toggle if (document.getElementById('rMenuBtn')) { document.getElementById('rMenuBtn').addEventListener('click', function(event) { event.preventDefault(); if (document.querySelector('.menuOn')) { closeAll(event); } else { document.documentElement.classList.add('menuOn') } }, false); } // loop through flyouts for keyboard access menuFly.forEach(fly=>{ if (fly.classList.contains('hasFly')) { fly.tabIndex=0; fly.addEventListener('focus', function(event) { event.preventDefault(); closeFly(); this.firstElementChild.setAttribute('aria-expanded', 'true'); this.classList.add('keyed'); }, false); } else { fly.firstChild.addEventListener('focus', function(event) { event.preventDefault(); closeFly(); }, false); } }); // loop through toggle links menuTogs.forEach(tog=>{ tog.tabIndex=-1; tog.addEventListener('click', function(event) { event.preventDefault(); if (this.parentElement.classList.contains('open')) { closeMenuTogs(); this.setAttribute('aria-expanded', 'false'); } else { closeMenuTogs(); this.setAttribute('aria-expanded', 'true'); this.parentElement.classList.add('open'); } }, false); }); } } // SERIES SIDEBARS const sbTime=Math.floor($.now()/18e5); // half hour turnovers const sbPub=window.location.pathname.split('/')[3]=='ssb'?'ssb':window.location.pathname.split('/')[4]; let sbEdition=window.location.pathname.replace('.html','').split('/')[5]; const iuSidebars=()=>{ $.getJSON('/policy/json/research.json?v'+sbTime, function(data) { data=data.filter(a=>a.Type=='International Update'); let countries=[...new Set(data.filter(a=>a.Countries!=null).map(pub=>pub.Countries).flat())]; countries=countries.filter(a=>!a.match('European Commission|OECD|World Bank')); countries.sort((a, b)=>aa.Url>b.Url?-1:1); if (sbEdition=='index') { sbEdition=data[0].Url.substr(26,7) } const date=new Date(data[0].Released); date.setMonth(date.getMonth()+1); $('#js-exp').html(date.toLocaleString('en-US', {month:'long',year:'numeric'})); let issues=[], issueDate=''; data.forEach(a=>{ if (a.Url.substr(26,7)!=sbEdition) { issueDate=a.Title.replace('International Update, ',''); issues.push(``); } }); let countryList=[]; countries.forEach(c=>{ countryList.push(``)}); $('#js-ed').html(`
See also the Country Index for all Research and Analysis.
`); }); } const ssbSidebars=()=>{ const months=['','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] $.getJSON('/policy/json/research.json?v'+sbTime, function(data) { data=[... new Set(data.filter(a=>a.Type.match('Social Security Bulletin')).map(a=>a.Released+a.Issue))]; data.sort((a,b)=>a>b?-1:1); data=data.map(a=>{ return {'Released':a.substring(0,10),'Issue':a.substring(10)} }); const date=new Date(data[0].Released); date.setMonth(date.getMonth()+3); $('#js-exp').html(date.toLocaleString('en-US', {month:'long',year:'numeric'})); let issues=[], dates=[]; data.forEach(a=>{ issues.push(``); const date=a.Released.substring(0,4)+' '+months[Number(a.Released.substring(5,7))]; dates.push(``); }); $('#otherIssues').html(``); $('#otherDates').html(``); }); } const statSidebars=()=>{ let editions=[], final=''; $.getJSON('/policy/json/statistics.json?v'+sbTime, function(pub) { pub=pub.find(a=>a.Url.split('/')[2]==sbPub); if ($('#js-exp')) {$('#js-exp').html(pub.Expected);} if (pub.Editions.length>0) { if (sbPub=='ssi_monthly'||sbPub=='stat_snapshot') { const months=['','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] const seriesURL=sbPub=='ssi_monthly'?'/index':''; const seriesChoose=sbPub=='ssi_monthly'?'':'index'; pub.Editions.forEach(e=>{ let mm=months.indexOf(e.split(' ')[0]), numEdition=''; if (mm>0) { // if e contains a month name, which some SSIM do not if (mm<10) { mm='0'+mm } numEdition=e.split(' ')[1]+'-'+mm; } else { numEdition=e; // for annual SSIMs } if (numEdition!=sbEdition) { editions.push(``) } }); if (sbEdition=='index') { editions.shift() } final=``; } else { pub.Editions.forEach(e=>{ const thisURL=e=='2015 (Expanded Edition)'?'2015ee':e; const thisText=e=='2015 (Expanded Edition)'?'2015 (Expanded)':e; if (thisURL!==sbEdition) { editions.push(`${thisText} `); } }); if (sbEdition == 'index') { editions.shift() } final=`${editions.join('')}
`; } $('#js-ed').html(final); } }); } $(function () { rMenu(); if (sbPub=='intl_update') { iuSidebars() } else if (sbPub=='ssb') { ssbSidebars() } else if ($('body').hasClass('js-sb')) { statSidebars() } });