Skip to main content

max / makenotwork

1.0 KB · 25 lines History Blame Raw
1 function switchSectionTab(btn, panelId) {
2 document.querySelectorAll('.section-tab').forEach(function(t) { t.classList.remove('is-selected'); });
3 document.querySelectorAll('.section-panel').forEach(function(p) { p.classList.remove('active'); });
4 btn.classList.add('is-selected');
5 var panel = document.getElementById(panelId);
6 if (panel) panel.classList.add('active');
7 history.replaceState(null, '', '#' + panelId);
8 }
9
10 (function() {
11 var hash = window.location.hash.replace('#', '');
12 if (hash) {
13 var panel = document.getElementById(hash);
14 var tab = document.querySelector('[data-tab="' + hash + '"]');
15 if (panel && tab) switchSectionTab(tab, hash);
16 }
17 })();
18
19 // The route answers 303 to a presigned URL, so navigating to it IS the
20 // download (`8fc6b1af`, option (a)). It used to answer JSON describing the
21 // URL, which is why this was a fetch-then-assign.
22 function downloadVersion(versionId) {
23 window.location.href = '/api/versions/' + versionId + '/download';
24 }
25