|
1 | 1 | function currentChapter() { |
2 | | - var path = document.location.pathname; |
3 | | - var idx = path.lastIndexOf("/") + 1; |
4 | | - var chap = path.substring(idx, idx + 2); |
5 | | - return parseInt(chap, 10); |
| 2 | + return parseInt(document.location.pathname.split('/').pop().substr(0, 2), 10); |
6 | 3 | } |
7 | 4 |
|
8 | 5 | function heading(i, heading, $heading) { |
9 | | - var currentLevel = parseInt(heading.tagName.substring(1)); |
10 | | - var result = ""; |
| 6 | + const currentLevel = parseInt(heading.tagName.substring(1)); |
| 7 | + |
11 | 8 | if (currentLevel === this.headerLevel) { |
12 | | - this.headerCounts[this.headerLevel] += 1; |
13 | | - return "" + this.headerCounts[this.headerLevel] + " " + $heading.text(); |
| 9 | + this.headerCounts[this.headerLevel]++; |
14 | 10 | } else if (currentLevel < this.headerLevel) { |
15 | | - while(currentLevel < this.headerLevel) { |
| 11 | + while (currentLevel < this.headerLevel) { |
16 | 12 | this.headerCounts[this.headerLevel] = 1; |
17 | | - this.headerLevel -= 1; |
| 13 | + this.headerLevel--; |
18 | 14 | } |
19 | | - this.headerCounts[this.headerLevel] += 1; |
20 | | - return "" + this.headerCounts[this.headerLevel]+ " " + $heading.text(); |
| 15 | + this.headerCounts[this.headerLevel]++; |
21 | 16 | } else { |
22 | | - while(currentLevel > this.headerLevel) { |
23 | | - this.headerLevel += 1; |
| 17 | + while (currentLevel > this.headerLevel) { |
| 18 | + this.headerLevel++; |
24 | 19 | this.headerCounts[this.headerLevel] = 1; |
25 | 20 | } |
26 | | - return "" + this.headerCounts[this.headerLevel]+ " " + $heading.text(); |
27 | 21 | } |
| 22 | + return `${this.headerCounts[this.headerLevel]} ${$heading.text()}`; |
28 | 23 | } |
29 | 24 |
|
30 | 25 | // ignore when using wkhtmltopdf, or it won't work... |
31 | | -if(window.jekyllEnv !== 'spec-pdf') { |
| 26 | +if (window.jekyllEnv !== 'spec-pdf') { |
32 | 27 | $('#toc').toc( |
33 | 28 | { |
34 | 29 | 'selectors': 'h1,h2,h3', |
@@ -64,8 +59,6 @@ document.addEventListener("DOMContentLoaded", function() { |
64 | 59 | }); |
65 | 60 |
|
66 | 61 | $("#chapters a").each(function (index) { |
67 | | - if (document.location.pathname.endsWith($(this).attr("href"))) |
68 | | - $(this).addClass("chapter-active"); |
69 | | - else |
70 | | - $(this).removeClass("chapter-active"); |
| 62 | + const href = $(this).attr("href"); |
| 63 | + $(this).toggleClass("chapter-active", document.location.pathname.endsWith(href)); |
71 | 64 | }); |
0 commit comments