diff options
author | 2023-07-12 14:47:11 -0700 | |
---|---|---|
committer | 2023-07-12 14:47:11 -0700 | |
commit | c651955a95322e0e587fc9734237ae2805e76dd5 (patch) | |
tree | affa859cf26e8f6e32465e53fabbaed134656316 | |
parent | downloads: fix JS typos (diff) | |
download | www-c651955a95322e0e587fc9734237ae2805e76dd5.tar.gz www-c651955a95322e0e587fc9734237ae2805e76dd5.tar.bz2 www-c651955a95322e0e587fc9734237ae2805e76dd5.zip |
downloads: fix edge cases with loadTabByHash
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rw-r--r-- | downloads/index.html | 67 |
1 files changed, 35 insertions, 32 deletions
diff --git a/downloads/index.html b/downloads/index.html index e29dc7b..eb47f8f 100644 --- a/downloads/index.html +++ b/downloads/index.html @@ -4,42 +4,45 @@ nav1-show: true nav1-weight: 9 title: 'Downloads' -inlinejs: "$(loadTabByHash());" +#inlinejs: "$(loadTabByHash());" +inlinejs: "loadTabByHash()" --- <script> - // Select the right tab based on the hash. - // TODO: we also want to be able to change the hash based on some clicks - function loadTabByHash() { - var h = window.location.hash; - // If arch is unselected, or invalid, use amd64. - var VALID_ARCHES = ['amd64','alpha','arm','arm64','hppa','ia64','loong','mips','m68k','ppc','riscv','s390','sparc','x86']; - var DEFAULT_ARCH = 'amd64'; - // If it was an advanced anchor/hash in the URL, drop it for validation. - h = h.replace(/-advanced$/,''); - // Validate arch now (without the leading '#' or trailing -advanced. - if(!VALID_ARCHES.include(h.substring(1))) { - h = '#' + DEFAULT_ARCH; - }; - // If an advanced variant exists, we want to show it. - // The browser will do the correct thing for "#amd64" vs "#amd64-advanced", - // when both of them exist. - var h1 = '#other-arches a[href="' + h + '-advanced"]'; - var h2 = '#other-arches a[href="' + h + '"]'; - var h3 = '#other-arches a:first'; - // Find the first one and show it. - for(selector in [h1,h2,h3]) { - var _h = $(_h); - if(_h.length > 0) { - _h.tab('show'); - break; - } +// Select the right tab based on the hash. +// TODO: we also want to be able to change the hash based on some clicks +function loadTabByHash() { + var VALID_ARCHES = ['amd64', 'alpha', 'arm', 'arm64', 'hppa', 'ia64', 'loong', 'mips', 'm68k', 'ppc', 'riscv', 's390', 'sparc', 'x86']; + var DEFAULT_ARCH = 'amd64'; + var h = window.location.hash; + // If arch is unselected, or invalid, use amd64. + // If it was an advanced anchor/hash in the URL, drop it for validation. + h = h.replace(/-advanced$/,''); + // Validate arch now (without the leading '#' or trailing -advanced. + if (!VALID_ARCHES.includes(h.substring(1))) { + h = '#' + DEFAULT_ARCH; + } + // If an advanced variant exists, we want to show it. + // The browser will do the correct thing for "#amd64" vs "#amd64-advanced", + // when both of them exist. + var h1 = '#other-arches a[href="' + h + '-advanced"]'; + var h2 = '#other-arches a[href="' + h + '"]'; + var h3 = '#other-arches a:first'; + // Find the first one and show it. + var s, h_; + for (const s of [h1, h2, h3]) { + h_ = $(s); + //console.log("Loading "+ s + " " + h_); + if(h_.length > 0) { + h_.tab('show'); + break; } } - window.addEventListener( - "hashchange", - () => { loadTabByHash(); }, - false - ); +} +window.addEventListener( + "hashchange", + () => { loadTabByHash(); }, + false +); </script> <div class="row"> <div class="col-xs-12 col-md-6"> |