diff --git a/docs/_spec/public/scripts/main.js b/docs/_spec/public/scripts/main.js index 9ade9c770f1e..c74c8d0ff9a1 100644 --- a/docs/_spec/public/scripts/main.js +++ b/docs/_spec/public/scripts/main.js @@ -1,34 +1,29 @@ 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)); + if (currentLevel === this.headerLevel) { - this.headerCounts[this.headerLevel] += 1; - return "" + this.headerCounts[this.headerLevel] + " " + $heading.text(); + this.headerCounts[this.headerLevel]++; } else if (currentLevel < this.headerLevel) { - while(currentLevel < this.headerLevel) { + while (currentLevel < this.headerLevel) { this.headerCounts[this.headerLevel] = 1; - this.headerLevel -= 1; + this.headerLevel--; } - this.headerCounts[this.headerLevel] += 1; - return "" + this.headerCounts[this.headerLevel]+ " " + $heading.text(); + this.headerCounts[this.headerLevel]++; } else { - while(currentLevel > this.headerLevel) { - this.headerLevel += 1; + while (currentLevel > this.headerLevel) { + this.headerLevel++; this.headerCounts[this.headerLevel] = 1; } - return "" + this.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') { +if (window.jekyllEnv !== 'spec-pdf') { $('#toc').toc( { 'selectors': 'h1,h2,h3', @@ -64,8 +59,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)); });