From 4cbaf3fb6056e7ee0a50071e9dfd7beb5766cc98 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 8 Sep 2019 11:03:54 +0300 Subject: [PATCH 1/3] Move inline JS to static/js/main.js. --- layouts/partials/footer.hbs | 15 +---------- layouts/partials/header.hbs | 35 -------------------------- static/js/main.js | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 49 deletions(-) create mode 100644 static/js/main.js diff --git a/layouts/partials/footer.hbs b/layouts/partials/footer.hbs index 7ac63a11d5a9..5c467f371d6d 100644 --- a/layouts/partials/footer.hbs +++ b/layouts/partials/footer.hbs @@ -27,20 +27,7 @@ - + {{!-- Load Modernizr dynamically for IE10/11 and add test classes for sticky footer with flexbox --}} diff --git a/static/js/main.js b/static/js/main.js new file mode 100644 index 000000000000..3129585dca85 --- /dev/null +++ b/static/js/main.js @@ -0,0 +1,50 @@ +;(function () { + var langPickerTogglerElement = document.querySelector('.lang-picker-toggler') + var langPickerElement = document.querySelector('.lang-picker') + var langElements = langPickerElement.querySelectorAll('button') + // Get the current URL language + var currentLang = window.location.pathname.split('/')[1] || 'en' + var currentLangElement = null + + Array.prototype.forEach.call(langElements, function (el) { + if (el.getAttribute('data-lang') !== currentLang) { + el.addEventListener('click', function (e) { + var newLocale = (e.target && e.target.dataset && e.target.dataset.lang) || 'en' + window.location.replace(window.location.pathname.replace(/\/[a-zA-Z-]+/, '/' + newLocale)) + }) + } else { + currentLangElement = el + } + }) + + langPickerTogglerElement.setAttribute('title', currentLangElement.textContent) + + // Remove the current selected language item, because we don't need to choose it + // any more unless we want to switch to a new language + langPickerElement.removeChild(currentLangElement.parentNode) + + langPickerTogglerElement.addEventListener('click', function () { + langPickerElement.classList.toggle('hidden') + + if (langPickerTogglerElement.getAttribute('aria-expanded') === 'true') { + langPickerTogglerElement.setAttribute('aria-expanded', 'false') + } else { + langPickerTogglerElement.setAttribute('aria-expanded', 'true') + } + }) +})() + +;(function () { + var scrollToTop = document.getElementById('scroll-to-top'); + + (window.onscroll = function () { + window.requestAnimationFrame(function () { + scrollToTop.style.display = window.pageYOffset > window.innerHeight ? 'block' : 'none' + }) + })() + + scrollToTop.addEventListener('click', function (e) { + e.preventDefault() + window.scrollTo(0, 0) + }) +})() From a33a56432c90d8d767a97bb527e44eb58b369183 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 29 Sep 2019 10:41:15 +0300 Subject: [PATCH 2/3] Move download.js to main.js --- layouts/download-current.hbs | 1 - layouts/download.hbs | 1 - layouts/index.hbs | 2 -- static/js/download.js | 56 ----------------------------------- static/js/main.js | 57 ++++++++++++++++++++++++++++++++++++ 5 files changed, 57 insertions(+), 60 deletions(-) delete mode 100644 static/js/download.js diff --git a/layouts/download-current.hbs b/layouts/download-current.hbs index 90da6f584a7b..5a2e9cb57281 100644 --- a/layouts/download-current.hbs +++ b/layouts/download-current.hbs @@ -21,6 +21,5 @@ {{> footer }} - diff --git a/layouts/download.hbs b/layouts/download.hbs index 81a896a0ec8e..055e483e7755 100644 --- a/layouts/download.hbs +++ b/layouts/download.hbs @@ -21,6 +21,5 @@ {{> footer }} - diff --git a/layouts/index.hbs b/layouts/index.hbs index 6ab6073d7c8b..02b7625f8b81 100644 --- a/layouts/index.hbs +++ b/layouts/index.hbs @@ -77,7 +77,5 @@ {{> footer className="no-margin-top" }} - - diff --git a/static/js/download.js b/static/js/download.js deleted file mode 100644 index e437086d5e13..000000000000 --- a/static/js/download.js +++ /dev/null @@ -1,56 +0,0 @@ -;(function (d, n) { - 'use strict' - - var osMatch = n.platform.match(/(Win|Mac|Linux)/) - var os = (osMatch && osMatch[1]) || '' - var arch = n.userAgent.match(/x86_64|Win64|WOW64/) || - n.cpuClass === 'x64' ? 'x64' : 'x86' - var text = 'textContent' in d ? 'textContent' : 'innerText' - var buttons = d.querySelectorAll('.home-downloadbutton') - var downloadHead = d.getElementById('home-downloadhead') - var dlLocal - - function versionIntoHref (nodeList, filename) { - var linkEls = Array.prototype.slice.call(nodeList) - var version - var el - - for (var i = 0; i < linkEls.length; i++) { - version = linkEls[i].getAttribute('data-version') - el = linkEls[i] - - // Windows 64-bit files for 0.x.x need to be prefixed with 'x64/' - if (os === 'Win' && (version[1] === '0' && arch === 'x64')) { - el.href += arch + '/' - } - - el.href += filename.replace('%version%', version) - } - } - - if (downloadHead && buttons) { - dlLocal = downloadHead.getAttribute('data-dl-local') - switch (os) { - case 'Mac': - versionIntoHref(buttons, 'node-%version%.pkg') - downloadHead[text] = dlLocal + ' macOS (x64)' - break - case 'Win': - versionIntoHref(buttons, 'node-%version%-' + arch + '.msi') - downloadHead[text] = dlLocal + ' Windows (' + arch + ')' - break - case 'Linux': - versionIntoHref(buttons, 'node-%version%-linux-x64.tar.xz') - downloadHead[text] = dlLocal + ' Linux (x64)' - break - } - } - - // Windows button on download page - var winButton = d.getElementById('windows-downloadbutton') - if (winButton && os === 'Win') { - var winText = winButton.getElementsByTagName('p')[0] - winButton.href = winButton.href.replace(/x(86|64)/, arch) - winText[text] = winText[text].replace(/x(86|64)/, arch) - } -})(document, navigator) diff --git a/static/js/main.js b/static/js/main.js index 3129585dca85..44e1bbf3e1bb 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -48,3 +48,60 @@ window.scrollTo(0, 0) }) })() + +;(function (d, n) { + 'use strict' + + var osMatch = n.platform.match(/(Win|Mac|Linux)/) + var os = (osMatch && osMatch[1]) || '' + var arch = n.userAgent.match(/x86_64|Win64|WOW64/) || + n.cpuClass === 'x64' ? 'x64' : 'x86' + var text = 'textContent' in d ? 'textContent' : 'innerText' + var buttons = d.querySelectorAll('.home-downloadbutton') + var downloadHead = d.getElementById('home-downloadhead') + var dlLocal + + function versionIntoHref (nodeList, filename) { + var linkEls = Array.prototype.slice.call(nodeList) + var version + var el + + for (var i = 0; i < linkEls.length; i++) { + version = linkEls[i].getAttribute('data-version') + el = linkEls[i] + + // Windows 64-bit files for 0.x.x need to be prefixed with 'x64/' + if (os === 'Win' && (version[1] === '0' && arch === 'x64')) { + el.href += arch + '/' + } + + el.href += filename.replace('%version%', version) + } + } + + if (downloadHead && buttons) { + dlLocal = downloadHead.getAttribute('data-dl-local') + switch (os) { + case 'Mac': + versionIntoHref(buttons, 'node-%version%.pkg') + downloadHead[text] = dlLocal + ' macOS (x64)' + break + case 'Win': + versionIntoHref(buttons, 'node-%version%-' + arch + '.msi') + downloadHead[text] = dlLocal + ' Windows (' + arch + ')' + break + case 'Linux': + versionIntoHref(buttons, 'node-%version%-linux-x64.tar.xz') + downloadHead[text] = dlLocal + ' Linux (x64)' + break + } + } + + // Windows button on download page + var winButton = d.getElementById('windows-downloadbutton') + if (winButton && os === 'Win') { + var winText = winButton.getElementsByTagName('p')[0] + winButton.href = winButton.href.replace(/x(86|64)/, arch) + winText[text] = winText[text].replace(/x(86|64)/, arch) + } +})(document, navigator) From 564d6a083fa932fa09125b55501000b347962fd9 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Tue, 1 Oct 2019 11:47:28 +0300 Subject: [PATCH 3/3] Move IE modernizr loading to main.js too --- layouts/partials/footer.hbs | 11 ----------- static/js/main.js | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/layouts/partials/footer.hbs b/layouts/partials/footer.hbs index 5c467f371d6d..6d9e8e3cb2c2 100644 --- a/layouts/partials/footer.hbs +++ b/layouts/partials/footer.hbs @@ -28,14 +28,3 @@ - -{{!-- Load Modernizr dynamically for IE10/11 and add test classes for sticky footer with flexbox --}} - diff --git a/static/js/main.js b/static/js/main.js index 44e1bbf3e1bb..b03dc876e372 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -105,3 +105,13 @@ winText[text] = winText[text].replace(/x(86|64)/, arch) } })(document, navigator) + +/* eslint-disable */ +/* Load Modernizr dynamically for IE10/11 and add test classes for sticky footer with flexbox */ +;(function(d,e,m,s){ + if (!/(MSIE|Trident)/.test(navigator.userAgent)){return;} + m=d.createElement(e); + s=d.getElementsByTagName(e)[0];m.async=1;m.src='/static/js/modernizr.custom.js'; + m.onload=function(){Modernizr.addTest('flexboxtweener', Modernizr.testAllProps('flexAlign'));}; + s.parentNode.insertBefore(m,s); +})(document,'script');