Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move inline JS to static/js/main.js. #2543

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion layouts/download-current.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
</div>

{{> footer }}
<script src="/static/js/download.js" async defer></script>
</body>
</html>
1 change: 0 additions & 1 deletion layouts/download.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
</div>

{{> footer }}
<script src="/static/js/download.js" async defer></script>
</body>
</html>
2 changes: 0 additions & 2 deletions layouts/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,5 @@
</div>

{{> footer className="no-margin-top" }}
<script src="/static/js/download.js" async defer></script>

</body>
</html>
26 changes: 1 addition & 25 deletions layouts/partials/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,4 @@

</footer>

<script>
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);
});
</script>

{{!-- Load Modernizr dynamically for IE10/11 and add test classes for sticky footer with flexbox --}}
<script>
(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');
</script>
<script src="/static/js/main.js" async defer></script>
35 changes: 0 additions & 35 deletions layouts/partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,3 @@

</div>
</header>
<script>
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')
}
})
</script>
56 changes: 0 additions & 56 deletions static/js/download.js

This file was deleted.

117 changes: 117 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
;(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)
})
})()

;(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)

/* 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');