Skip to content

Commit dec85fd

Browse files
authored
main.js: return early if buttons aren't present (#3853)
1 parent 36239ee commit dec85fd

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

static/js/main.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,20 @@
180180
;(function () {
181181
'use strict'
182182

183+
var buttons = document.querySelectorAll('.home-downloadbutton')
184+
var downloadHead = document.querySelector('#home-downloadhead')
185+
186+
if (!downloadHead || !buttons) {
187+
return
188+
}
189+
183190
var osMatch = navigator.platform.match(/(Win|Mac|Linux)/)
184191
var os = (osMatch && osMatch[1]) || ''
185192
var arch = navigator.userAgent.match(/x86_64|Win64|WOW64/) ||
186193
navigator.cpuClass === 'x64'
187194
? 'x64'
188195
: 'x86'
189-
var buttons = document.querySelectorAll('.home-downloadbutton')
190-
var downloadHead = document.querySelector('#home-downloadhead')
191-
var dlLocal
196+
var dlLocal = downloadHead.getAttribute('data-dl-local')
192197

193198
function versionIntoHref (nodeList, filename) {
194199
var linkEls = Array.prototype.slice.call(nodeList)
@@ -208,22 +213,19 @@
208213
}
209214
}
210215

211-
if (downloadHead && buttons) {
212-
dlLocal = downloadHead.getAttribute('data-dl-local')
213-
switch (os) {
214-
case 'Mac':
215-
versionIntoHref(buttons, 'node-%version%.pkg')
216-
downloadHead.textContent = dlLocal + ' macOS (x64)'
217-
break
218-
case 'Win':
219-
versionIntoHref(buttons, 'node-%version%-' + arch + '.msi')
220-
downloadHead.textContent = dlLocal + ' Windows (' + arch + ')'
221-
break
222-
case 'Linux':
223-
versionIntoHref(buttons, 'node-%version%-linux-x64.tar.xz')
224-
downloadHead.textContent = dlLocal + ' Linux (x64)'
225-
break
226-
}
216+
switch (os) {
217+
case 'Mac':
218+
versionIntoHref(buttons, 'node-%version%.pkg')
219+
downloadHead.textContent = dlLocal + ' macOS (x64)'
220+
break
221+
case 'Win':
222+
versionIntoHref(buttons, 'node-%version%-' + arch + '.msi')
223+
downloadHead.textContent = dlLocal + ' Windows (' + arch + ')'
224+
break
225+
case 'Linux':
226+
versionIntoHref(buttons, 'node-%version%-linux-x64.tar.xz')
227+
downloadHead.textContent = dlLocal + ' Linux (x64)'
228+
break
227229
}
228230

229231
// Windows button on download page

0 commit comments

Comments
 (0)