add popovers for footnotes

This commit is contained in:
Valentin Boettcher 2019-01-11 12:43:44 +01:00
parent 9da1b4b2a1
commit 26f6f5e80f
5 changed files with 32 additions and 13 deletions

View file

@ -11,6 +11,7 @@ the [[http://www.gigamonkeys.com/book/][online version]] of Practical Common Lis
- =right-arrow-key= - next chapter - =right-arrow-key= - next chapter
- =left-arrow-key= - previous chapter - =left-arrow-key= - previous chapter
- =HOME/POS1= - index page - =HOME/POS1= - index page
- footnote popvers
** TODO ** TODO
- integrate full index into TOC - integrate full index into TOC

View file

@ -155,3 +155,9 @@ h2::before {
counter-increment: chapter; /* Increment the value of section counter by 1 */ counter-increment: chapter; /* Increment the value of section counter by 1 */
content: counters(chapter, '.') ' '; /* Display the value of section counter */ content: counters(chapter, '.') ' '; /* Display the value of section counter */
} }
.tippy-tooltip.pcl-theme {
background: white;
color: black;
border: solid black;
}

View file

@ -116,10 +116,11 @@ function collectFootnotes() {
let index = parseInt(note.innerText) - 1; let index = parseInt(note.innerText) - 1;
// JS forces me to do that! // JS forces me to do that!
if(footMap[index]) if(!footMap[index])
footMap[index].push(note); footMap[index] = {};
else
footMap[index] = [ note ]; footMap[index][note.parentElement.parentElement.classList.contains('notes') ?
'target' : 'origin'] = note;
} }
return footMap; return footMap;
@ -136,16 +137,25 @@ function linkFootnotes() {
origin.appendChild(link); origin.appendChild(link);
}; };
function createPopover(index, origin, target) {
let content = target.parentElement.innerHTML;
content = content.substring(`<sup>${index+1}</sup>`.length-1);
if(target.parentElement.nextSibling.tagName !== 'P')
content += '&hellip;';
tippy(origin, { content, animateFill: false, animation: 'fade', theme: 'pcl'});
}
let footMap = collectFootnotes(); let footMap = collectFootnotes();
for(let index in footMap) { for(let index in footMap) {
let pair = footMap[index]; let pair = footMap[index];
if(pair && pair.length == 2) { if(pair && 'origin' in pair && 'target' in pair) {
let first = pair[0]; let origin = pair.origin;
let second = pair[1]; let target = pair.target;
createPopover(index, origin, target);
identifyAndLink(index, 1, 2, first, second); identifyAndLink(index, 1, 2, origin, target);
identifyAndLink(index, 2, 1, second, first); identifyAndLink(index, 2, 1, target, origin);
} }
} }
} }

2
js/tippy.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Beautify Practical Common Lisp", "name": "Beautify Practical Common Lisp",
"version": "1.2", "version": "1.3",
"description": "Adds a simple table of contents and syntax highlighting to the web version of Practical Common Lisp by Peter Seibel.", "description": "Adds a simple table of contents and syntax highlighting to the web version of Practical Common Lisp by Peter Seibel.",
@ -19,7 +19,7 @@
"content_scripts": [ "content_scripts": [
{ {
"matches": ["*://*.gigamonkeys.com/book/*.html"], "matches": ["*://*.gigamonkeys.com/book/*.html"],
"js": ["./js/highlight-lisp.js", "./js/tocbot.js","./js/main.js"], "js": ["./js/highlight-lisp.js", "./js/tocbot.js","./js/tippy.js","./js/main.js"],
"css": ["./css/highlight-style.css"] "css": ["./css/highlight-style.css"]
} }
], ],