Skip to content

Commit e44ccf9

Browse files
committed
downloads/guis: adjust the Javascript for filtering
This is needed because with a static site, filtering by Operating System should only add a GET parameter, not change the path of the URL. While at it, allow it to work locally: `file://` pages are not allowed to manipulate the browser history... Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 6619da9 commit e44ccf9

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

static/js/application.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ var Dropdowns = {
219219
var eles = $('.dropdown-trigger');
220220
eles.click(function(e) {
221221
e.preventDefault();
222-
222+
223223
$(this).toggleClass('active');
224224
$('#' + $(this).attr('data-panel-id')).toggle();
225-
225+
226226
eles.each((_, ele)=>{
227227
if(ele === this) return
228228
$(ele).removeClass('active');
@@ -250,8 +250,18 @@ var Downloads = {
250250
Downloads.filterGUIS();
251251
},
252252

253-
getOSFilter: function() {
254-
var os = location.href.substring(location.href.lastIndexOf("/") + 1);
253+
getOSFromQueryString: function() {
254+
const query = window.location.search.substring(1);
255+
const needle = `os=`;
256+
return query
257+
.split('&')
258+
.filter(e => e.startsWith(needle))
259+
.map(e => decodeURIComponent(e.substring(needle.length).replace(/\+/g, '%20')))
260+
.pop();
261+
},
262+
263+
getOSFilter: function(os) {
264+
os = os || Downloads.getOSFromQueryString();
255265
return os === 'linux' || os === 'mac' || os === 'windows' || os === 'android' || os === 'ios' ? os : '';
256266
},
257267

@@ -260,8 +270,8 @@ var Downloads = {
260270
return platforms[os];
261271
},
262272

263-
filterGUIS: function() {
264-
var osFilter = Downloads.getOSFilter();
273+
filterGUIS: function(os) {
274+
var osFilter = Downloads.getOSFilter(os);
265275
var capitalizedOS = Downloads.capitalizeOS(osFilter);
266276
$('a.gui-os-filter').not("[data-os='"+osFilter+"']").removeClass('selected');
267277
$('a.gui-os-filter').filter("[data-os='"+osFilter+"']").addClass('selected');
@@ -288,11 +298,15 @@ var Downloads = {
288298
if (window.history && window.history.pushState) {
289299
var url = os === ''
290300
? '/downloads/guis/'
291-
: '/download/gui/'+os;
292-
history.pushState(null, $(this).html(), url);
301+
: `/download/guis?os=${os}`;
302+
try {
303+
history.pushState(null, $(this).html(), url);
304+
} catch (e) {
305+
if (`${e}`.indexOf('The operation is insecure') < 0) console.log(e)
306+
}
293307
}
294308

295-
Downloads.filterGUIS();
309+
Downloads.filterGUIS(os);
296310
});
297311
},
298312

0 commit comments

Comments
 (0)