From dd893b4900238a4ea521c311ad00e587365fca80 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Thu, 4 Apr 2024 21:58:57 -0400 Subject: [PATCH 1/4] Optimize main.js --- docs/_spec/public/scripts/main.js | 65 +++++++++++++------------------ 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/docs/_spec/public/scripts/main.js b/docs/_spec/public/scripts/main.js index 9ade9c770f1e..a6946dce03a4 100644 --- a/docs/_spec/public/scripts/main.js +++ b/docs/_spec/public/scripts/main.js @@ -1,52 +1,46 @@ 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; + let result = ""; if (currentLevel === this.headerLevel) { - this.headerCounts[this.headerLevel] += 1; - return "" + this.headerCounts[this.headerLevel] + " " + $heading.text(); + headerCounts[this.headerLevel]++; + result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } 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]++; + result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } 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(); + result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } + return result; } -// 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 hljs.configure({ languages: [] }); -// KaTeX configuration document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body, { delimiters: [ @@ -55,17 +49,12 @@ document.addEventListener("DOMContentLoaded", function() { ], ignoredTags: ['script', 'noscript', 'style', 'textarea'], }); - // syntax highlighting after KaTeX is loaded, - // so that math can be used in code blocks hljs.initHighlighting(); $("pre nobr").addClass("fixws"); - // point when all necessary js is done, so PDF to be rendered window.status = "loaded"; }); $("#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)); }); From 0416fcbbce7d24c18e3d37e01f6a838e77c33aaf Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 7 Apr 2024 08:15:48 -0400 Subject: [PATCH 2/4] Add comments --- docs/_spec/public/scripts/main.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/_spec/public/scripts/main.js b/docs/_spec/public/scripts/main.js index a6946dce03a4..7b216fe4d53f 100644 --- a/docs/_spec/public/scripts/main.js +++ b/docs/_spec/public/scripts/main.js @@ -26,6 +26,7 @@ function heading(i, heading, $heading) { return result; } +// ignore when using wkhtmltopdf, or it won't work... if (window.jekyllEnv !== 'spec-pdf') { $('#toc').toc({ selectors: 'h1,h2,h3', @@ -37,10 +38,12 @@ if (window.jekyllEnv !== 'spec-pdf') { }); } +// no language auto-detect so that EBNF isn't detected as scala hljs.configure({ languages: [] }); +// KaTeX configuration document.addEventListener("DOMContentLoaded", function() { renderMathInElement(document.body, { delimiters: [ @@ -49,8 +52,11 @@ document.addEventListener("DOMContentLoaded", function() { ], ignoredTags: ['script', 'noscript', 'style', 'textarea'], }); + // syntax highlighting after KaTeX is loaded, + // so that math can be used in code blocks hljs.initHighlighting(); $("pre nobr").addClass("fixws"); + // point when all necessary js is done, so PDF to be rendered window.status = "loaded"; }); From d28def4c7d5b0de01f301e53c2a1762e8ccd9695 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Sun, 7 Apr 2024 08:17:28 -0400 Subject: [PATCH 3/4] More optimizations --- docs/_spec/public/scripts/main.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/_spec/public/scripts/main.js b/docs/_spec/public/scripts/main.js index 7b216fe4d53f..e3110b9aa4d0 100644 --- a/docs/_spec/public/scripts/main.js +++ b/docs/_spec/public/scripts/main.js @@ -5,25 +5,22 @@ function currentChapter() { function heading(i, heading, $heading) { const currentLevel = parseInt(heading.tagName.substring(1)); const headerCounts = this.headerCounts; - let result = ""; + if (currentLevel === this.headerLevel) { headerCounts[this.headerLevel]++; - result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } else if (currentLevel < this.headerLevel) { while (currentLevel < this.headerLevel) { headerCounts[this.headerLevel] = 1; this.headerLevel--; } headerCounts[this.headerLevel]++; - result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } else { while (currentLevel > this.headerLevel) { this.headerLevel++; headerCounts[this.headerLevel] = 1; } - result = `${headerCounts[this.headerLevel]} ${$heading.text()}`; } - return result; + return `${headerCounts[this.headerLevel]} ${$heading.text()}`; } // ignore when using wkhtmltopdf, or it won't work... From 1f60b6beae90d27c8bd0476f267a49b580609bd5 Mon Sep 17 00:00:00 2001 From: Aviv Keller <38299977+RedYetiDev@users.noreply.github.com> Date: Tue, 16 Apr 2024 07:20:45 -0400 Subject: [PATCH 4/4] Make suggested changes --- docs/_spec/public/scripts/main.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/_spec/public/scripts/main.js b/docs/_spec/public/scripts/main.js index e3110b9aa4d0..c74c8d0ff9a1 100644 --- a/docs/_spec/public/scripts/main.js +++ b/docs/_spec/public/scripts/main.js @@ -4,35 +4,36 @@ function currentChapter() { function heading(i, heading, $heading) { const currentLevel = parseInt(heading.tagName.substring(1)); - const headerCounts = this.headerCounts; if (currentLevel === this.headerLevel) { - headerCounts[this.headerLevel]++; + this.headerCounts[this.headerLevel]++; } else if (currentLevel < this.headerLevel) { while (currentLevel < this.headerLevel) { - headerCounts[this.headerLevel] = 1; + this.headerCounts[this.headerLevel] = 1; this.headerLevel--; } - headerCounts[this.headerLevel]++; + this.headerCounts[this.headerLevel]++; } else { while (currentLevel > this.headerLevel) { this.headerLevel++; - headerCounts[this.headerLevel] = 1; + this.headerCounts[this.headerLevel] = 1; } } - return `${headerCounts[this.headerLevel]} ${$heading.text()}`; + return `${this.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 - }); + $('#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