Skip to content
Merged
Changes from 3 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
56 changes: 24 additions & 32 deletions docs/_spec/public/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,38 @@
function currentChapter() {
var path = document.location.pathname;
var idx = path.lastIndexOf("/") + 1;
var chap = path.substring(idx, idx + 2);
return parseInt(chap, 10);
return parseInt(document.location.pathname.split('/').pop().substr(0, 2), 10);
}

function heading(i, heading, $heading) {
var currentLevel = parseInt(heading.tagName.substring(1));
var result = "";
const currentLevel = parseInt(heading.tagName.substring(1));
const headerCounts = this.headerCounts;

if (currentLevel === this.headerLevel) {
this.headerCounts[this.headerLevel] += 1;
return "" + this.headerCounts[this.headerLevel] + " " + $heading.text();
headerCounts[this.headerLevel]++;
} else if (currentLevel < this.headerLevel) {
while(currentLevel < this.headerLevel) {
this.headerCounts[this.headerLevel] = 1;
this.headerLevel -= 1;
while (currentLevel < this.headerLevel) {
headerCounts[this.headerLevel] = 1;
this.headerLevel--;
}
this.headerCounts[this.headerLevel] += 1;
return "" + this.headerCounts[this.headerLevel]+ " " + $heading.text();
headerCounts[this.headerLevel]++;
} else {
while(currentLevel > this.headerLevel) {
this.headerLevel += 1;
this.headerCounts[this.headerLevel] = 1;
while (currentLevel > this.headerLevel) {
this.headerLevel++;
headerCounts[this.headerLevel] = 1;
}
return "" + this.headerCounts[this.headerLevel]+ " " + $heading.text();
}
return `${headerCounts[this.headerLevel]} ${$heading.text()}`;
}

// ignore when using wkhtmltopdf, or it won't work...
if(window.jekyllEnv !== 'spec-pdf') {
$('#toc').toc(
{
'selectors': 'h1,h2,h3',
'smoothScrolling': false,
'chapter': currentChapter(),
'headerLevel': 1,
'headerCounts': [-1, currentChapter() - 1, 1, 1],
'headerText': heading
}
);
if (window.jekyllEnv !== 'spec-pdf') {
$('#toc').toc({
selectors: 'h1,h2,h3',
smoothScrolling: false,
chapter: currentChapter(),
headerLevel: 1,
headerCounts: [-1, currentChapter() - 1, 1, 1],
headerText: heading
});
}

// no language auto-detect so that EBNF isn't detected as scala
Expand All @@ -64,8 +58,6 @@ document.addEventListener("DOMContentLoaded", function() {
});

$("#chapters a").each(function (index) {
if (document.location.pathname.endsWith($(this).attr("href")))
$(this).addClass("chapter-active");
else
$(this).removeClass("chapter-active");
const href = $(this).attr("href");
$(this).toggleClass("chapter-active", document.location.pathname.endsWith(href));
});