PublishingJS:TheNewSocial: Difference between revisions

From H&D Publishing Wiki
No edit summary
No edit summary
Line 23: Line 23:


function make_case_studies_collapsible() {
function make_case_studies_collapsible() {
const nav_links = $('#toc a');
const nav_links = $('#toc a')
window.onhashchange = function() {
window.onhashchange = function() {
    for (let i = 0; i < nav_links.length; i++) {
    for (let i = 0; i < nav_links.length; i++) {
        if (nav_links[i].href.match(/(#.*)/)[1] == window.location.hash) {
        if (nav_links[i].href.match(/(#.*)/)[1] == window.location.hash) {
            nav_links[i].className = 'selected';
            nav_links[i].className = 'selected'
        } else {
        } else {
            nav_links[i].className = '';
            nav_links[i].className = ''
        }
        }
    }
    }
Line 37: Line 37:


function make_principles_collapsible() {
function make_principles_collapsible() {
const principles = $( '#Principles > section > h3 > a' )
const principles = $( '#Principles > section' )
for ( const principle of principles ) {
for ( const principle of principles ) {
if ( !principle.href.includes('#') ) {
const target_anchor = principle.querySelector('h3 > a')
principle.href = principle.href.replace( `${ origin }/html/`, '#' )
if ( !target_anchor.href.includes('#') ) {
target_anchor.href = target_anchor.href.replace( `${ origin }/html/`, '#' )
}
}
}
}
}
}

Revision as of 12:15, 26 April 2023

const origin = window.location.origin
const title = "TheNewSocial"

document.onreadystatechange = function () {

	console.log( 'Hello from PublishingJS namespace!' )
	
	make_case_studies_collapsible()
	make_principles_collapsible()

	

}





function $( selector ) {
	return document.querySelectorAll( selector )
}


function make_case_studies_collapsible() {
	const nav_links = $('#toc a')
	window.onhashchange = function() {
	    for (let i = 0; i < nav_links.length; i++) {
	        if (nav_links[i].href.match(/(#.*)/)[1] == window.location.hash) {
	            nav_links[i].className = 'selected'
	        } else {
	            nav_links[i].className = ''
	        }
	    }
	}
	
}

function make_principles_collapsible() {
	const principles = $( '#Principles > section' )
	for ( const principle of principles ) {
		const target_anchor = principle.querySelector('h3 > a')
		if ( !target_anchor.href.includes('#') ) {
			target_anchor.href = target_anchor.href.replace( `${ origin }/html/`, '#' )
		}
	}
}