Skip to content

Commit

Permalink
Jump to bibl target when in URL hash
Browse files Browse the repository at this point in the history
  • Loading branch information
cboulanger committed Nov 30, 2024
1 parent aeacf8e commit e3ef87b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Empty file modified .github/workflows/annotate-errors
100644 → 100755
Empty file.
33 changes: 31 additions & 2 deletions xslt/training-to-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,38 @@
tabs[i+1] = new Tabby(`[data-tab-${i+1}]`);
}
hljs.highlightAll();


// function to show code that is hidden in tabs
function revealTabBasedOnHash() {
let scrollElem;
if(window.location.hash) {
const hash = window.location.hash.substring(1);
// bibl elements might be in a hidden tab
if (hash.includes("bibl")) {
const tabElement = document.querySelector(`[data-bibl-ids*="${hash}"]`);
if (tabElement) {
const tabIndex = tabElement.dataset.tabIndex;
tabs[tabIndex].toggle(tabElement.id);
scrollElem = tabElement;
} else {
console.error(`Cannot find tab containing #${hash}`)
}
} else {
scrollElem = document.querySelector(`#${hash}`)
}
if (scrollElem) {
scrollElem.scrollIntoView({behavior: 'smooth', block: 'nearest', inline: 'start'});
}
}
}

// Trigger at page load and whenever hash changes
document.addEventListener("DOMContentLoaded", revealTabBasedOnHash);
window.addEventListener("hashchange", revealTabBasedOnHash);

// add links
function addLinks() {
console.log("Adding links to 'source' attributes...")
const spans = document.querySelectorAll('span')
spans.forEach((span, idx) => {
if (span.textContent.trim() == 'xml:id') {
Expand All @@ -103,7 +132,7 @@
console.error(`Cannot find tab containing #${biblId}`)
} else {
const tabIndex = tabElement.dataset.tabIndex;
span.innerHTML = `"<a href="#${biblId}" onclick="tabs[${tabIndex}].toggle('${tabElement.id}')">#${biblId}</a>"`;
span.innerHTML = `"<a href="#${biblId}">#${biblId}</a>"`;
}
}
}
Expand Down

0 comments on commit e3ef87b

Please sign in to comment.