37 lines
No EOL
1.9 KiB
JavaScript
37 lines
No EOL
1.9 KiB
JavaScript
// UTILITY BAR
|
|
const utilities=()=>{
|
|
let pageURL='https://www.ssa.gov'+window.location.pathname;
|
|
let sendTitle=document.title.replace(/&/g, '%26').replace(/"/g, '');
|
|
let fileHTML=window.location.pathname.substring(window.location.pathname.lastIndexOf('/')+1);
|
|
let fileAsPDF=fileHTML.replace(/html?/gi,'pdf');
|
|
let fileAsXLS=fileHTML.replace(/html?/gi,'xlsx');
|
|
$('a', '#mail').attr('href', 'mailto:?subject=From the SSA Research, Statistics %26 Policy Analysis website&body='+sendTitle+'%0D'+pageURL);
|
|
$('a', '#print').attr('href', fileAsPDF);
|
|
$('a', '#excel').attr('href', fileAsXLS);
|
|
$('#rspaUtil').css('visibility', 'visible');
|
|
}
|
|
|
|
// AUTO-TOC on stat pub pages
|
|
const tablesTOC=()=>{
|
|
// map captions into new array then table ids into second array
|
|
let chartsList=$('.chartCenter .title').map(function () {
|
|
return $(this).text().replace(/Chart\s([^ ]+)/g,'Chart $1</a> ');
|
|
});
|
|
let tablesList=$('.table[id] caption').map(function () {
|
|
return $(this).text().replace(/\(in\s(thousands|millions)?(\sof\s)?(dollars)?\)/,'').replace('[In thousands of dollars]','').replace(/Table\s([^ ]+)( Expanded)?/g,'Table $1$2</a> ');
|
|
});
|
|
let tableIDs=$('.table').map(function () { return $(this).attr('id') });
|
|
let chartIDs=$('.chartCenter').map(function () { return $(this).children(':first').attr('id') });
|
|
let contentsList='<ul>';
|
|
$.each(chartsList, function(i, value){ contentsList+='<li><a href="#'+chartIDs[i]+'">'+value+'</li>' });
|
|
$.each(tablesList, function(i, value){ contentsList+='<li><a href="#'+tableIDs[i]+'">'+value+'</li>' });
|
|
contentsList += '</ul>';
|
|
if (chartsList.length>0) { $('.chartCenter:first').before(contentsList) }
|
|
else { $('.table:first').before(contentsList) }
|
|
$('.termsToggle').css('visibility', 'visible'); // don't show SUPP 5A term links until TOC loads
|
|
};
|
|
|
|
$(function () {
|
|
utilities();
|
|
if ($('body').hasClass('tablesTOC')) { tablesTOC() }
|
|
}); |