|
| 1 | +;(function () { |
| 2 | + var langPickerTogglerElement = document.querySelector('.lang-picker-toggler') |
| 3 | + var langPickerElement = document.querySelector('.lang-picker') |
| 4 | + var langElements = langPickerElement.querySelectorAll('button') |
| 5 | + // Get the current URL language |
| 6 | + var currentLang = window.location.pathname.split('/')[1] || 'en' |
| 7 | + var currentLangElement = null |
| 8 | + |
| 9 | + Array.prototype.forEach.call(langElements, function (el) { |
| 10 | + if (el.getAttribute('data-lang') !== currentLang) { |
| 11 | + el.addEventListener('click', function (e) { |
| 12 | + var newLocale = (e.target && e.target.dataset && e.target.dataset.lang) || 'en' |
| 13 | + window.location.replace(window.location.pathname.replace(/\/[a-zA-Z-]+/, '/' + newLocale)) |
| 14 | + }) |
| 15 | + } else { |
| 16 | + currentLangElement = el |
| 17 | + } |
| 18 | + }) |
| 19 | + |
| 20 | + langPickerTogglerElement.setAttribute('title', currentLangElement.textContent) |
| 21 | + |
| 22 | + // Remove the current selected language item, because we don't need to choose it |
| 23 | + // any more unless we want to switch to a new language |
| 24 | + langPickerElement.removeChild(currentLangElement.parentNode) |
| 25 | + |
| 26 | + langPickerTogglerElement.addEventListener('click', function () { |
| 27 | + langPickerElement.classList.toggle('hidden') |
| 28 | + |
| 29 | + if (langPickerTogglerElement.getAttribute('aria-expanded') === 'true') { |
| 30 | + langPickerTogglerElement.setAttribute('aria-expanded', 'false') |
| 31 | + } else { |
| 32 | + langPickerTogglerElement.setAttribute('aria-expanded', 'true') |
| 33 | + } |
| 34 | + }) |
| 35 | +})() |
| 36 | + |
| 37 | +;(function () { |
| 38 | + var scrollToTop = document.getElementById('scroll-to-top'); |
| 39 | + |
| 40 | + (window.onscroll = function () { |
| 41 | + window.requestAnimationFrame(function () { |
| 42 | + scrollToTop.style.display = window.pageYOffset > window.innerHeight ? 'block' : 'none' |
| 43 | + }) |
| 44 | + })() |
| 45 | + |
| 46 | + scrollToTop.addEventListener('click', function (e) { |
| 47 | + e.preventDefault() |
| 48 | + window.scrollTo(0, 0) |
| 49 | + }) |
| 50 | +})() |
| 51 | + |
| 52 | +;(function (d, n) { |
| 53 | + 'use strict' |
| 54 | + |
| 55 | + var osMatch = n.platform.match(/(Win|Mac|Linux)/) |
| 56 | + var os = (osMatch && osMatch[1]) || '' |
| 57 | + var arch = n.userAgent.match(/x86_64|Win64|WOW64/) || |
| 58 | + n.cpuClass === 'x64' ? 'x64' : 'x86' |
| 59 | + var text = 'textContent' in d ? 'textContent' : 'innerText' |
| 60 | + var buttons = d.querySelectorAll('.home-downloadbutton') |
| 61 | + var downloadHead = d.getElementById('home-downloadhead') |
| 62 | + var dlLocal |
| 63 | + |
| 64 | + function versionIntoHref (nodeList, filename) { |
| 65 | + var linkEls = Array.prototype.slice.call(nodeList) |
| 66 | + var version |
| 67 | + var el |
| 68 | + |
| 69 | + for (var i = 0; i < linkEls.length; i++) { |
| 70 | + version = linkEls[i].getAttribute('data-version') |
| 71 | + el = linkEls[i] |
| 72 | + |
| 73 | + // Windows 64-bit files for 0.x.x need to be prefixed with 'x64/' |
| 74 | + if (os === 'Win' && (version[1] === '0' && arch === 'x64')) { |
| 75 | + el.href += arch + '/' |
| 76 | + } |
| 77 | + |
| 78 | + el.href += filename.replace('%version%', version) |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + if (downloadHead && buttons) { |
| 83 | + dlLocal = downloadHead.getAttribute('data-dl-local') |
| 84 | + switch (os) { |
| 85 | + case 'Mac': |
| 86 | + versionIntoHref(buttons, 'node-%version%.pkg') |
| 87 | + downloadHead[text] = dlLocal + ' macOS (x64)' |
| 88 | + break |
| 89 | + case 'Win': |
| 90 | + versionIntoHref(buttons, 'node-%version%-' + arch + '.msi') |
| 91 | + downloadHead[text] = dlLocal + ' Windows (' + arch + ')' |
| 92 | + break |
| 93 | + case 'Linux': |
| 94 | + versionIntoHref(buttons, 'node-%version%-linux-x64.tar.xz') |
| 95 | + downloadHead[text] = dlLocal + ' Linux (x64)' |
| 96 | + break |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + // Windows button on download page |
| 101 | + var winButton = d.getElementById('windows-downloadbutton') |
| 102 | + if (winButton && os === 'Win') { |
| 103 | + var winText = winButton.getElementsByTagName('p')[0] |
| 104 | + winButton.href = winButton.href.replace(/x(86|64)/, arch) |
| 105 | + winText[text] = winText[text].replace(/x(86|64)/, arch) |
| 106 | + } |
| 107 | +})(document, navigator) |
| 108 | + |
| 109 | +/* eslint-disable */ |
| 110 | +/* Load Modernizr dynamically for IE10/11 and add test classes for sticky footer with flexbox */ |
| 111 | +;(function(d,e,m,s){ |
| 112 | + if (!/(MSIE|Trident)/.test(navigator.userAgent)){return;} |
| 113 | + m=d.createElement(e); |
| 114 | + s=d.getElementsByTagName(e)[0];m.async=1;m.src='/static/js/modernizr.custom.js'; |
| 115 | + m.onload=function(){Modernizr.addTest('flexboxtweener', Modernizr.testAllProps('flexAlign'));}; |
| 116 | + s.parentNode.insertBefore(m,s); |
| 117 | +})(document,'script'); |
0 commit comments