mirror of
https://github.com/vale981/practical-cl-beautified
synced 2025-03-04 09:11:37 -05:00
fix whitespace
This commit is contained in:
parent
d8127607bf
commit
76ca2e68fa
1 changed files with 62 additions and 64 deletions
126
js/main.js
126
js/main.js
|
@ -3,22 +3,22 @@ let chapters = [];
|
|||
|
||||
// get chapter for navigation
|
||||
function loadChapters(callback) {
|
||||
let sending = browser.runtime.sendMessage({
|
||||
msg: "getChapters"
|
||||
});
|
||||
return sending;
|
||||
let sending = browser.runtime.sendMessage({
|
||||
msg: "getChapters"
|
||||
});
|
||||
return sending;
|
||||
}
|
||||
|
||||
// Inject the Table of Contents
|
||||
function createTOC() {
|
||||
let TOC = document.getElementById('toc') || document.createElement('nav'),
|
||||
headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
headings = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
|
||||
|
||||
// fix headings
|
||||
for(let heading of headings) {
|
||||
heading.id = heading.parentNode.getAttribute('name');
|
||||
heading.id = heading.parentNode.getAttribute('name');
|
||||
}
|
||||
|
||||
|
||||
TOC.id = 'toc';
|
||||
TOC.classList.add('toc', 'toc-right');
|
||||
TOC.innerHTML = '';
|
||||
|
@ -26,14 +26,14 @@ function createTOC() {
|
|||
document.body.insertBefore(TOC, document.body.childNodes[0]);
|
||||
|
||||
tocbot.init({
|
||||
// Where to render the table of contents.
|
||||
tocSelector: '#toc',
|
||||
// Where to grab the headings to build the table of contents.
|
||||
contentSelector: 'body',
|
||||
// Which headings to grab inside of the contentSelector element.
|
||||
headingSelector: 'h2, h3',
|
||||
// smooth it out
|
||||
scrollSmooth: true
|
||||
// Where to render the table of contents.
|
||||
tocSelector: '#toc',
|
||||
// Where to grab the headings to build the table of contents.
|
||||
contentSelector: 'body',
|
||||
// Which headings to grab inside of the contentSelector element.
|
||||
headingSelector: 'h2, h3',
|
||||
// smooth it out
|
||||
scrollSmooth: true
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ function wrapInner(parent, wrapper, className) {
|
|||
|
||||
function wrapPre() {
|
||||
for(let el of document.querySelectorAll('pre')) {
|
||||
wrapInner(el, 'code', 'lisp');
|
||||
wrapInner(el, 'code', 'lisp');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,8 +59,8 @@ function findCurrentChapter() {
|
|||
let file = document.URL.split('/').pop().replace(/\#.*$/, '');
|
||||
let currentChapter = -1;
|
||||
for(let chapter in chapters) {
|
||||
if(chapters[chapter].url === file)
|
||||
currentChapter = chapter;
|
||||
if(chapters[chapter].url === file)
|
||||
currentChapter = chapter;
|
||||
}
|
||||
return parseInt(currentChapter);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ function goToPrevious() {
|
|||
if(!chapters) return;
|
||||
let currentChapter = findCurrentChapter();
|
||||
if(currentChapter > 0) {
|
||||
document.location.href = chapters[currentChapter-1].url;
|
||||
document.location.href = chapters[currentChapter-1].url;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ function gotoNext() {
|
|||
if(!chapters) return;
|
||||
let currentChapter = findCurrentChapter();
|
||||
if(currentChapter < chapters.length - 1) {
|
||||
document.location.href = chapters[currentChapter+1].url;
|
||||
document.location.href = chapters[currentChapter+1].url;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,24 +87,24 @@ function gotoNext() {
|
|||
// set up the navigation shortcuts
|
||||
function setUpNav() {
|
||||
document.addEventListener('keypress', (event) => {
|
||||
switch(event.keyCode) {
|
||||
case 37:
|
||||
goToPrevious();
|
||||
break;
|
||||
case 39:
|
||||
gotoNext();
|
||||
break;
|
||||
case 36:
|
||||
document.location.href = 'index.html';
|
||||
break;
|
||||
}
|
||||
switch(event.keyCode) {
|
||||
case 37:
|
||||
goToPrevious();
|
||||
break;
|
||||
case 39:
|
||||
gotoNext();
|
||||
break;
|
||||
case 36:
|
||||
document.location.href = 'index.html';
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setUpNumbering() {
|
||||
let chapter = findCurrentChapter();
|
||||
if (chapter >= 0) {
|
||||
document.documentElement.style['counter-reset'] = 'chapter ' + (chapter + 1);
|
||||
document.documentElement.style['counter-reset'] = 'chapter ' + (chapter + 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -113,14 +113,14 @@ function collectFootnotes() {
|
|||
|
||||
// collect al footnotes into pairs
|
||||
for(let note of document.querySelectorAll('sup')) {
|
||||
let index = parseInt(note.innerText) - 1;
|
||||
|
||||
// JS forces me to do that!
|
||||
if(!footMap[index])
|
||||
footMap[index] = {};
|
||||
let index = parseInt(note.innerText) - 1;
|
||||
|
||||
footMap[index][note.parentElement.parentElement.classList.contains('notes') ?
|
||||
'target' : 'origin'] = note;
|
||||
// JS forces me to do that!
|
||||
if(!footMap[index])
|
||||
footMap[index] = {};
|
||||
|
||||
footMap[index][note.parentElement.parentElement.classList.contains('notes') ?
|
||||
'target' : 'origin'] = note;
|
||||
}
|
||||
|
||||
return footMap;
|
||||
|
@ -128,36 +128,36 @@ function collectFootnotes() {
|
|||
|
||||
function linkFootnotes() {
|
||||
function identifyAndLink(index, originid, targetid, origin, target) {
|
||||
origin.id = `foot${index}${originid}`;
|
||||
let link = document.createElement('a');
|
||||
target.id = `foot${index}${targetid}`;
|
||||
link.href = '#' + target.id;
|
||||
link.innerText = (index + 1);
|
||||
origin.innerHTML = '';
|
||||
origin.appendChild(link);
|
||||
origin.id = `foot${index}${originid}`;
|
||||
let link = document.createElement('a');
|
||||
target.id = `foot${index}${targetid}`;
|
||||
link.href = '#' + target.id;
|
||||
link.innerText = (index + 1);
|
||||
origin.innerHTML = '';
|
||||
origin.appendChild(link);
|
||||
};
|
||||
|
||||
function createPopover(index, origin, target) {
|
||||
let content = target.parentElement.innerHTML;
|
||||
content = content.substring(`<sup>${index+1}</sup>`.length);
|
||||
if(target.parentElement && target.parentElement.nextSibling && target.parentElement.nextSibling.tagName !== 'P')
|
||||
content += '…';
|
||||
|
||||
tippy(origin, { content, animateFill: false, animation: 'fade', theme: 'pcl'});
|
||||
let content = target.parentElement.innerHTML;
|
||||
content = content.substring(`<sup>${index+1}</sup>`.length);
|
||||
if(target.parentElement && target.parentElement.nextSibling && target.parentElement.nextSibling.tagName !== 'P')
|
||||
content += '…';
|
||||
|
||||
tippy(origin, { content, animateFill: false, animation: 'fade', theme: 'pcl'});
|
||||
}
|
||||
|
||||
|
||||
let footMap = collectFootnotes();
|
||||
|
||||
for(let index in footMap) {
|
||||
index = parseInt(index); // I love you JavaScript :/
|
||||
let pair = footMap[index];
|
||||
if(pair && 'origin' in pair && 'target' in pair) {
|
||||
let origin = pair.origin;
|
||||
let target = pair.target;
|
||||
createPopover(index, origin, target);
|
||||
identifyAndLink(index, 1, 2, origin, target);
|
||||
identifyAndLink(index, 2, 1, target, origin);
|
||||
}
|
||||
index = parseInt(index); // I love you JavaScript :/
|
||||
let pair = footMap[index];
|
||||
if(pair && 'origin' in pair && 'target' in pair) {
|
||||
let origin = pair.origin;
|
||||
let target = pair.target;
|
||||
createPopover(index, origin, target);
|
||||
identifyAndLink(index, 1, 2, origin, target);
|
||||
identifyAndLink(index, 2, 1, target, origin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,5 +174,3 @@ HighlightLisp.highlight_auto();
|
|||
HighlightLisp.paren_match();
|
||||
createTOC();
|
||||
setUpNav();
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue