|
8 | 8 |
|
9 | 9 | // Scroll code block to the given code location
|
10 | 10 | function scrollToLoc(elt, loc) {
|
11 |
| - const lines = elt.querySelector('.line-numbers'); |
| 11 | + const lines = elt.querySelector(".line-numbers"); |
12 | 12 | let scrollOffset;
|
13 | 13 |
|
14 | 14 | // If the block is greater than the size of the viewer,
|
|
32 | 32 | function updateScrapedExample(example) {
|
33 | 33 | const locs = JSON.parse(example.attributes.getNamedItem("data-locs").textContent);
|
34 | 34 | let locIndex = 0;
|
35 |
| - const highlights = Array.prototype.slice.call(example.querySelectorAll('.highlight')); |
36 |
| - const link = example.querySelector('.scraped-example-title a'); |
| 35 | + const highlights = Array.prototype.slice.call(example.querySelectorAll(".highlight")); |
| 36 | + const link = example.querySelector(".scraped-example-title a"); |
37 | 37 |
|
38 | 38 | if (locs.length > 1) {
|
39 | 39 | // Toggle through list of examples in a given file
|
40 | 40 | const onChangeLoc = changeIndex => {
|
41 |
| - removeClass(highlights[locIndex], 'focus'); |
| 41 | + removeClass(highlights[locIndex], "focus"); |
42 | 42 | changeIndex();
|
43 | 43 | scrollToLoc(example, locs[locIndex][0]);
|
44 |
| - addClass(highlights[locIndex], 'focus'); |
| 44 | + addClass(highlights[locIndex], "focus"); |
45 | 45 |
|
46 | 46 | const url = locs[locIndex][1];
|
47 | 47 | const title = locs[locIndex][2];
|
|
50 | 50 | link.innerHTML = title;
|
51 | 51 | };
|
52 | 52 |
|
53 |
| - example.querySelector('.prev') |
54 |
| - .addEventListener('click', () => { |
| 53 | + example.querySelector(".prev") |
| 54 | + .addEventListener("click", () => { |
55 | 55 | onChangeLoc(() => {
|
56 | 56 | locIndex = (locIndex - 1 + locs.length) % locs.length;
|
57 | 57 | });
|
58 | 58 | });
|
59 | 59 |
|
60 |
| - example.querySelector('.next') |
61 |
| - .addEventListener('click', () => { |
| 60 | + example.querySelector("next") |
| 61 | + .addEventListener("click", () => { |
62 | 62 | onChangeLoc(() => {
|
63 | 63 | locIndex = (locIndex + 1) % locs.length;
|
64 | 64 | });
|
65 | 65 | });
|
66 | 66 | }
|
67 | 67 |
|
68 |
| - const expandButton = example.querySelector('.expand'); |
| 68 | + const expandButton = example.querySelector(".expand"); |
69 | 69 | if (expandButton) {
|
70 |
| - expandButton.addEventListener('click', () => { |
| 70 | + expandButton.addEventListener("click", () => { |
71 | 71 | if (hasClass(example, "expanded")) {
|
72 | 72 | removeClass(example, "expanded");
|
73 | 73 | scrollToLoc(example, locs[0][0]);
|
|
81 | 81 | scrollToLoc(example, locs[0][0]);
|
82 | 82 | }
|
83 | 83 |
|
84 |
| - const firstExamples = document.querySelectorAll('.scraped-example-list > .scraped-example'); |
| 84 | + const firstExamples = document.querySelectorAll(".scraped-example-list > .scraped-example"); |
85 | 85 | onEachLazy(firstExamples, updateScrapedExample);
|
86 |
| - onEachLazy(document.querySelectorAll('.more-examples-toggle'), toggle => { |
| 86 | + onEachLazy(document.querySelectorAll(".more-examples-toggle"), toggle => { |
87 | 87 | // Allow users to click the left border of the <details> section to close it,
|
88 | 88 | // since the section can be large and finding the [+] button is annoying.
|
89 |
| - onEachLazy(toggle.querySelectorAll('.toggle-line, .hide-more'), button => { |
90 |
| - button.addEventListener('click', () => { |
| 89 | + onEachLazy(toggle.querySelectorAll(".toggle-line, .hide-more"), button => { |
| 90 | + button.addEventListener("click", () => { |
91 | 91 | toggle.open = false;
|
92 | 92 | });
|
93 | 93 | });
|
94 | 94 |
|
95 |
| - const moreExamples = toggle.querySelectorAll('.scraped-example'); |
96 |
| - toggle.querySelector('summary').addEventListener('click', () => { |
| 95 | + const moreExamples = toggle.querySelectorAll(".scraped-example"); |
| 96 | + toggle.querySelector("summary").addEventListener("click", () => { |
97 | 97 | // Wrapping in setTimeout ensures the update happens after the elements are actually
|
98 | 98 | // visible. This is necessary since updateScrapedExample calls scrollToLoc which
|
99 | 99 | // depends on offsetHeight, a property that requires an element to be visible to
|
|
0 commit comments