forked from barryclark/jekyll-now
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpopup.html
More file actions
82 lines (65 loc) · 2.38 KB
/
popup.html
File metadata and controls
82 lines (65 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<div class="bottom-panel" id="bottom-panel">
<div class="popup-wrapper" id="popup-wrapper"></div>
</div>
<script>
function getFootnoteContent(index) {
const id = "fn:" + index;
const fn = document.getElementById(id);
return fn.innerHTML.trim();
};
function footnotePopup(showIndex, showCloseBtn) {
const popupWrapper = document.querySelector("#popup-wrapper");
// Set whether to display index and/or close button. Default is true for both
if (showIndex === undefined) {
showIndex = true;
}
if (showCloseBtn === undefined) {
showCloseBtn = true;
}
// Create main container that will hold footnote content
const popupContent = popupWrapper.appendChild(document.createElement("div"));
popupContent.id = "popup-content";
let popupIndex = null;
if (showIndex) {
popupIndex = popupWrapper.insertBefore(document.createElement("div"), popupContent);
popupIndex.id = "popup-index";
}
let popupCloseButton = null;
if (showCloseBtn) {
popupCloseButton = popupWrapper.appendChild(document.createElement("div"));
popupCloseButton.innerHTML = "[x]";
popupCloseButton.id = "popup-close";
}
// Remove redundant [return] links from footnote list (optional)
const fnReturns = document.querySelectorAll("a.footnote-return");
fnReturns.forEach(function(fnReturn) {
const parent = fnReturn.parentNode;
parent.removeChild(fnReturn);
});
const fnRefs = document.querySelectorAll("sup[id^='fnref:']");
fnRefs.forEach(function(fnRef) {
fnRef.addEventListener("mouseover", handler("refs", fnRef));
});
window.addEventListener("mouseout", handler("close"));
if (showCloseBtn) {
popupCloseButton.addEventListener("click", handler("close"));
}
function handler(type, node) {
return function(event) {
if (type === "close") {
popupWrapper.style.display = "none";
}
if (type === "refs") {
event.preventDefault();
const index = node.id.substring(6);
if (showIndex) {
popupIndex.innerHTML = index + ".";
}
popupContent.innerHTML = getFootnoteContent(index);
popupWrapper.style.display = "flex";
}
};
};
};
footnotePopup(true, false);
</script>