PublishingJS:TheNewSocial: Difference between revisions

From H&D Publishing Wiki
No edit summary
No edit summary
Line 1: Line 1:
const origin = window.location.origin
const origin = window.location.origin
const title = "TheNewSocial"
const title = "TheNewSocial"
const wikilink_rel = "mw:WikiLink"


document.onreadystatechange = function () {
document.onreadystatechange = function () {
Line 8: Line 9:
make_case_studies_collapsible()
make_case_studies_collapsible()
make_principles_collapsible()
make_principles_collapsible()
 
hashify_all_wikilinks()


Line 36: Line 37:
}
}


function make_principles_collapsible() {
function hashify_all_wikilinks() {
const principles = $( '#Principles > section' )
const wikilinks = $( `a[rel="${ wikilink_rel }"]` )
for ( const principle of principles ) {
console.log( wikilinks )
const target_anchor = principle.querySelector('h3 > a')
if ( !target_anchor.href.includes('#') ) {
target_anchor.href = target_anchor.href.replace( `${ origin }/html/`, '#' )
}
}
}
}
// 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/`, '#' )
// }
// }
// }

Revision as of 11:23, 26 April 2023

const origin = window.location.origin
const title = "TheNewSocial"
const wikilink_rel = "mw:WikiLink"

document.onreadystatechange = function () {

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

}





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 hashify_all_wikilinks() {
	const wikilinks = $( `a[rel="${ wikilink_rel }"]` )
	console.log( wikilinks )
}

// 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/`, '#' )
// 		}
// 	}
// }