Skip to content

Commit 02ed060

Browse files
szhaaaronmarkham
authored andcommitted
[DOC] fix installation selector wrong history (apache#16381)
* fix installation selector wrong history * updates to script * nudge CI
1 parent 9ad337f commit 02ed060

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

docs/static_site/src/assets/js/options.js

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
5-
* regarding copyright ownership. The ASF licenses this file
5+
* regarding copyright ownership. The ASF licenses this file
66
* to you under the Apache License, Version 2.0 (the
77
* "License"); you may not use this file except in compliance
88
* with the License. You may obtain a copy of the License at
@@ -17,7 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
/* Installation page display functions for install selector */
20+
/* Installation page display functions for install selector.
21+
This utility allows direct links to specific install instructions.
22+
*/
2123

2224
$(document).ready(function () {
2325
function label(lbl) {
@@ -27,13 +29,13 @@ $(document).ready(function () {
2729
}
2830

2931
function urlSearchParams(searchString) {
30-
let urlDict = new Map();
32+
let searchDict = new Map();
3133
let searchParams = searchString.substring(1).split("&");
3234
searchParams.forEach(function (element) {
3335
kvPair = element.split("=");
34-
urlDict.set(kvPair[0], kvPair[1]);
36+
searchDict.set(kvPair[0], kvPair[1]);
3537
});
36-
return urlDict;
38+
return searchDict;
3739
}
3840

3941
function is_a_match(elem, text) {
@@ -43,11 +45,10 @@ $(document).ready(function () {
4345
}
4446
}
4547

46-
function setSelects() {
47-
let urlParams = urlSearchParams(window.location.search);
48+
function setSelects(urlParams) {
4849
if (urlParams.get('version'))
4950
versionSelect = urlParams.get('version');
50-
$('.current-version').html( versionSelect + ' <span class="caret"></span></button>' );
51+
$('.current-version').html( versionSelect + ' <span class="caret"></span>' );
5152
if (urlParams.get('platform'))
5253
platformSelect = label(urlParams.get('platform'));
5354
if (urlParams.get('language'))
@@ -66,8 +67,9 @@ $(document).ready(function () {
6667
$('button.opt').each(function(){is_a_match($(this), environSelect)});
6768

6869
showContent();
69-
if (window.location.href.indexOf("/get_started/") >= 0) {
70-
history.pushState(null, null, '?version=' + versionSelect + '&platform=' + platformSelect + '&language=' + languageSelect + '&environ=' + environSelect + '&processor=' + processorSelect);
70+
let queryString = '?version=' + versionSelect + '&platform=' + platformSelect + '&language=' + languageSelect + '&environ=' + environSelect + '&processor=' + processorSelect
71+
if (window.location.href.indexOf("/get_started") >= 0) {
72+
history.pushState(null, null, queryString);
7173
}
7274
}
7375

@@ -80,8 +82,7 @@ $(document).ready(function () {
8082
});
8183
}
8284

83-
showContent();
84-
setSelects();
85+
setSelects(urlSearchParams(window.location.search));
8586

8687
function setContent() {
8788
var el = $(this);
@@ -90,27 +91,17 @@ $(document).ready(function () {
9091
el.addClass('active');
9192
if ($(this).hasClass("versions")) {
9293
$('.current-version').html($(this).text());
93-
if (window.location.search.indexOf("version") < 0) {
94-
if (window.location.search.length > 0) {
95-
var url = 'index.html' + window.location.search.concat('&version=' + $(this).text());
96-
} else {
97-
var url = 'index.html?version=' + $(this).text();
98-
}
99-
history.pushState(null, null, url);
100-
} else {
101-
history.pushState(null, null, 'index.html' + window.location.search.replace(urlParams.get('version'), $(this).text()));
102-
}
94+
urlParams.set("version", $(this).text());
10395
} else if ($(this).hasClass("platforms")) {
104-
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('platform'), '='+label($(this).text())));
96+
urlParams.set("platform", label($(this).text()));
10597
} else if ($(this).hasClass("languages")) {
106-
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('language'), '='+label($(this).text())));
98+
urlParams.set("language", label($(this).text()));
10799
} else if ($(this).hasClass("processors")) {
108-
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('processor'), '='+label($(this).text())));
100+
urlParams.set("processor", label($(this).text()));
109101
} else if ($(this).hasClass("environs")) {
110-
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('environ'), '='+label($(this).text())));
102+
urlParams.set("environ", label($(this).text()));
111103
}
112-
113-
showContent();
104+
setSelects(urlParams);
114105
}
115106

116107
$('.opt-group').on('click', '.opt', setContent);

0 commit comments

Comments
 (0)