|
34 | 34 | langPickerElement.removeChild(currentLangElement.parentNode); |
35 | 35 | } |
36 | 36 |
|
37 | | - const toggleFunction = function () { |
| 37 | + var toggleFunction = function () { |
38 | 38 | langPickerElement.classList.toggle('hidden'); |
39 | | - const isAriaExpanded = |
| 39 | + var isAriaExpanded = |
40 | 40 | langPickerTogglerElement.getAttribute('aria-expanded') === 'true'; |
41 | 41 | langPickerTogglerElement.setAttribute('aria-expanded', !isAriaExpanded); |
42 | 42 | }; |
|
54 | 54 | } |
55 | 55 | }); |
56 | 56 | })(); |
| 57 | + |
57 | 58 | (function () { |
58 | | - const themeAttr = 'data-theme'; |
59 | 59 | var darkThemeSwitcherElement = document.querySelector('.dark-theme-switcher'); |
60 | 60 |
|
61 | 61 | darkThemeSwitcherElement.addEventListener('click', function () { |
|
68 | 68 | }); |
69 | 69 |
|
70 | 70 | function setTheme(theme) { |
71 | | - document.querySelector('html').setAttribute(themeAttr, theme); |
| 71 | + document.documentElement.setAttribute('data-theme', theme); |
72 | 72 | window.localStorage.setItem('theme', theme); |
73 | 73 | } |
74 | 74 |
|
75 | 75 | function getTheme() { |
76 | 76 | return window.localStorage.getItem('theme'); |
77 | 77 | } |
78 | 78 | })(); |
| 79 | + |
79 | 80 | (function () { |
80 | 81 | var scrollToTop = document.querySelector('#scroll-to-top'); |
81 | 82 |
|
|
91 | 92 | window.scrollTo(0, 0); |
92 | 93 | }); |
93 | 94 | })(); |
94 | | -(function () { |
95 | | - var contributorCard = document.querySelector('.contributor-card'); |
96 | | - |
97 | | - if (!contributorCard) { |
98 | | - return; |
99 | | - } |
100 | | - |
101 | | - var contributorAvatar = contributorCard.querySelector('#contributor-avatar'); |
102 | | - var contributorUsername = contributorCard.querySelector( |
103 | | - '#contributor-username' |
104 | | - ); |
105 | | - var contributorContributions = contributorCard.querySelector( |
106 | | - '#contributor-contributions' |
107 | | - ); |
108 | | - var loadingSpinner = contributorCard.querySelector('.spinner-border'); |
109 | | - |
110 | | - if (window.IntersectionObserver) { |
111 | | - var observer = new window.IntersectionObserver( |
112 | | - function (entries) { |
113 | | - entries.forEach(function (entry) { |
114 | | - if (entry.intersectionRatio > 0.5) { |
115 | | - // In viewport, fetch a random contributor |
116 | | - fetchRandomContributor(); |
117 | | - |
118 | | - observer.unobserve(entry.target); |
119 | | - } |
120 | | - }); |
121 | | - }, |
122 | | - { threshold: 0.5 } |
123 | | - ); |
124 | | - |
125 | | - observer.observe(document.querySelector('footer')); |
126 | | - } else { |
127 | | - // Does not support IntersectionObserver |
128 | | - fetchRandomContributor(); |
129 | | - } |
130 | | - |
131 | | - function fetchRandomContributor() { |
132 | | - var maxContributors; |
133 | | - var fetchDate; |
134 | | - var needToRefetch = false; |
135 | | - |
136 | | - if (window.localStorage) { |
137 | | - maxContributors = window.localStorage.getItem('max_contributors'); |
138 | | - fetchDate = parseInt(window.localStorage.getItem('fetch_date'), 10); |
139 | | - } |
140 | | - |
141 | | - // If fetch date is a month old (2592000000 ms === 30 days) |
142 | | - if (Date.now() - fetchDate >= 2592000000) { |
143 | | - needToRefetch = true; |
144 | | - } |
145 | | - |
146 | | - // If localStorage and data is less than 1 month old, fetch 1 time |
147 | | - if (maxContributors && !needToRefetch) { |
148 | | - getContributor( |
149 | | - Math.floor(Math.random() * Math.floor(parseInt(maxContributors))) + 1 |
150 | | - ); |
151 | | - } else { |
152 | | - getMaxContributors(function (randomPage, lastPage) { |
153 | | - getContributor(randomPage); |
154 | | - |
155 | | - if (window.localStorage) { |
156 | | - window.localStorage.setItem('max_contributors', lastPage); |
157 | | - } |
158 | | - }); |
159 | | - } |
160 | | - } |
161 | 95 |
|
162 | | - function getMaxContributors(callback) { |
163 | | - var xhr = new window.XMLHttpRequest(); |
164 | | - xhr.open( |
165 | | - 'GET', |
166 | | - 'https://api.github.com/repos/nodejs/node/contributors?per_page=1', |
167 | | - true |
168 | | - ); |
169 | | - |
170 | | - xhr.onreadystatechange = function () { |
171 | | - if (xhr.readyState === 4) { |
172 | | - if (xhr.status === 200) { |
173 | | - // Get Headers Links last page to generate a random contributor |
174 | | - var links = linkParser(xhr.getResponseHeader('Link')); |
175 | | - var randomPage = |
176 | | - Math.floor( |
177 | | - Math.random() * Math.floor(parseInt(links.last.page, 10)) |
178 | | - ) + 1; |
179 | | - |
180 | | - if (window.localStorage) { |
181 | | - window.localStorage.setItem('fetch_date', Date.now()); |
182 | | - } |
183 | | - callback(randomPage, links.last.page); |
184 | | - } else { |
185 | | - return contributorCard.parentNode.removeChild(contributorCard); |
186 | | - } |
187 | | - } |
188 | | - }; |
189 | | - |
190 | | - xhr.send(); |
191 | | - } |
192 | | - |
193 | | - function getContributor(randomPage) { |
194 | | - var xhr = new window.XMLHttpRequest(); |
195 | | - xhr.open( |
196 | | - 'GET', |
197 | | - 'https://api.github.com/repos/nodejs/node/contributors?per_page=1&page=' + |
198 | | - randomPage, |
199 | | - true |
200 | | - ); |
201 | | - |
202 | | - xhr.onreadystatechange = function () { |
203 | | - if (xhr.readyState === 4) { |
204 | | - if (xhr.status === 200) { |
205 | | - var contributor = JSON.parse(xhr.responseText)[0]; |
206 | | - |
207 | | - // Remove loading spinner and show avatar |
208 | | - loadingSpinner.parentNode.removeChild(loadingSpinner); |
209 | | - contributorAvatar.classList.remove('hidden'); |
210 | | - // Set new values |
211 | | - contributorAvatar.src = contributor.avatar_url + '&s=80'; |
212 | | - contributorAvatar.parentElement.href = contributor.html_url; |
213 | | - contributorUsername.textContent = contributor.login; |
214 | | - contributorUsername.href = contributor.html_url; |
215 | | - contributorContributions.textContent = |
216 | | - contributor.contributions + ' contributions'; |
217 | | - contributorContributions.parentElement.href = |
218 | | - 'https://github.com/nodejs/node/commits?author=' + |
219 | | - contributor.login; |
220 | | - } else { |
221 | | - return contributorCard.parentNode.removeChild(contributorCard); |
222 | | - } |
223 | | - } |
224 | | - }; |
225 | | - |
226 | | - xhr.send(); |
227 | | - } |
228 | | - |
229 | | - function linkParser(linkHeader) { |
230 | | - var regex = /<([^?]+\?per_page=1&[a-z]+=([\d]+))>;[\s]*rel="([a-z]+)"/g; |
231 | | - var array = []; |
232 | | - var object = {}; |
233 | | - |
234 | | - while ((array = regex.exec(linkHeader)) !== null) { |
235 | | - object[array[3]] = { |
236 | | - url: array[1], |
237 | | - page: array[2] |
238 | | - }; |
239 | | - } |
240 | | - |
241 | | - return object; |
242 | | - } |
243 | | -})(); |
244 | 96 | (function () { |
245 | 97 | 'use strict'; |
| 98 | + |
246 | 99 | var userAgent = navigator.userAgent; |
247 | 100 | var osMatch = userAgent.match(/(Win|Mac|Linux)/); |
248 | 101 | var os = (osMatch && osMatch[1]) || ''; |
|
298 | 151 | winText.textContent = winText.textContent.replace(/x(86|64)/, arch); |
299 | 152 | } |
300 | 153 | })(); |
301 | | -(function () { |
302 | | - // This function is used to replace the anchor |
303 | | - // link of Edit on GitHub |
304 | 154 |
|
| 155 | +// This function is used to replace the anchor link of Edit on GitHub |
| 156 | +(function () { |
305 | 157 | var editOnGitHubElement = document.getElementById('editOnGitHubLink'); |
306 | 158 | var editOnGitHubUrlElement = document.getElementById('editOnGitHubUrl'); |
307 | 159 |
|
|
0 commit comments