Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup fix #2657

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions P5/webnav/bootstrap.bundle.min.js

This file was deleted.

1 change: 0 additions & 1 deletion P5/webnav/bootstrap.bundle.min.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions P5/webnav/jquery-3.7.0.min.js

This file was deleted.

251 changes: 0 additions & 251 deletions P5/webnav/jquery.treeview.js

This file was deleted.

52 changes: 36 additions & 16 deletions P5/webnav/popupFootnotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
var footnotePopupContent = null;
var biblFrame = null;

$(document).ready(function(){
//First we create a popup box ready to receive the footnotes.

document.addEventListener("DOMContentLoaded", function() {
footnotePopup = document.createElement('div');
footnotePopup.setAttribute('id', 'footnotePopup');
var closer = document.createElement('div');
closer.setAttribute('class', 'footnotePopupCloser');
closer.setAttribute('onclick', 'this.parentNode.style.display = \'none\'');
closer.onclick = function() {this.parentNode.style.display = "none"};
var x = document.createTextNode('x');
closer.appendChild(x);
footnotePopupContent = document.createElement('div');
Expand All @@ -30,15 +30,18 @@ $(document).ready(function(){
for (var i=0; i<links.length; i++){
if (links[i].hasAttribute("href") && links[i].getAttribute('href').substring(0, 5) == '#Note'){
if (links[i].getAttribute('class') != 'link_return'){
links[i].setAttribute('onclick', 'showPopupFootnote(\'' + links[i].getAttribute('href').substring(1) + '\')');
links[i].setAttribute('href', 'javascript:void(0)');
var dest = links[i].getAttribute('href').substring(1);
links[i].onclick = function (e) {
e.preventDefault();
showPopupFootnote(e.target, dest);
}
}
}
}
addBiblFrame();
});

function showPopupFootnote(footnoteId){
function showPopupFootnote(el, footnoteId){
var footnote = document.getElementById(footnoteId);
if ((footnotePopup == null)||(footnotePopupContent == null)||(footnote == null)){
//If something is missing, we just default to original behaviour and jump to the footnote.
Expand All @@ -49,10 +52,17 @@ function showPopupFootnote(footnoteId){
var cloneFootnote = footnote.cloneNode(true);
//We need to remove the id because it'll be a duplicate.
cloneFootnote.setAttribute('id', '');
// Also remove links back to the text because they are not needed in popups.
cloneFootnote.querySelectorAll("a.link_return").forEach(function(a) {a.parentElement.removeChild(a)});
//Add it to the popup.
clearContent(footnotePopupContent);
footnotePopupContent.appendChild(cloneFootnote);
footnotePopup.style.display = 'block';

// Position the popup near the footnote
const footnoteY = el.getBoundingClientRect().top;
const popupHeight = footnotePopup.getBoundingClientRect().height;
footnotePopup.style.top = (footnoteY - popupHeight - 20) + 'px';
}

function clearContent(targetEl){
Expand All @@ -63,29 +73,32 @@ function clearContent(targetEl){
}

//Bind the escape key so that it hides the popup if it's showing.
$(document).keyup(function(e){
if(e.keyCode === 27)
document.addEventListener("keyup", function(e) {
if(e.keyCode === 27) {
if (document.getElementById('footnotePopup').style.display == 'block'){
document.getElementById('footnotePopup').style.display = 'none';
e.preventDefault();
e.stopPropagation();
}
});
}
})

//These functions set up and handle the display of bibliographical references
//as popups.

//This function finds all links to items in the bibliography and turns them
//into JS calls which retrieve the content which has been imported into
//an iframe, and display it as a popup.
function setupBiblPopups (){
function setupBiblPopups () {
var links = document.getElementsByTagName('a');
for (var i=0; i<links.length; i++){
var href = links[i].getAttribute('href');
if (href && href.substring(0, 9) == 'BIB.html#'){
var biblId = href.substring(9, href.length);
links[i].setAttribute('onclick', 'showPopupBibl(\'' + biblId + '\')');
links[i].setAttribute('href', 'javascript:void(0)');
links[i].onclick = function(e) {
e.preventDefault();
showPopupBibl(e.target, biblId)
}
//}
}
}
Expand All @@ -102,12 +115,12 @@ function addBiblFrame(){
biblFrame.style.display = 'none';
document.getElementsByTagName('body')[0].appendChild(biblFrame);
biblFrame.setAttribute('src', 'BIB.html');
$(biblFrame).ready(setupBiblPopups);
biblFrame.addEventListener("load", setupBiblPopups);
}

//This function shows a bibl popup. It differs slightly from the function for note
//popups, so it is distinct.
function showPopupBibl(biblId){
function showPopupBibl(el, biblId){
var bibl = null;
//We have to be cautious here; some browsers block access to the iframe
//document contents from another document, especially when running locally.
Expand All @@ -125,11 +138,18 @@ function showPopupBibl(biblId){
return;
}
//Otherwise, we populate the popup with the content of the bibl, and show it.
var biblContent = bibl.innerHTML;
var biblContent = bibl.cloneNode(true);
// Also remove links back to the text because they are not needed in popups.
biblContent.querySelectorAll("a.link_return").forEach(function(a) {a.parentElement.removeChild(a)});
//Add it to the popup.
clearContent(footnotePopupContent);
footnotePopupContent.innerHTML = biblContent;
footnotePopupContent.innerHTML = biblContent.innerHTML;
footnotePopup.style.display = 'block';

// Position the popup near the footnote
const footnoteY = el.getBoundingClientRect().top;
const popupHeight = footnotePopup.getBoundingClientRect().height;
footnotePopup.style.top = (footnoteY - popupHeight - 20) + 'px';
}


Loading