mirror of
https://github.com/vale981/practical-cl-beautified
synced 2025-03-04 09:11:37 -05:00
add popovers for footnotes
This commit is contained in:
parent
9da1b4b2a1
commit
26f6f5e80f
5 changed files with 32 additions and 13 deletions
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
32
js/main.js
32
js/main.js
|
@ -114,12 +114,13 @@ function collectFootnotes() {
|
||||||
// collect al footnotes into pairs
|
// collect al footnotes into pairs
|
||||||
for(let note of document.querySelectorAll('sup')) {
|
for(let note of document.querySelectorAll('sup')) {
|
||||||
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;
|
||||||
|
@ -135,17 +136,26 @@ function linkFootnotes() {
|
||||||
origin.innerHTML = '';
|
origin.innerHTML = '';
|
||||||
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 += '…';
|
||||||
|
|
||||||
|
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
2
js/tippy.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -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"]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue