Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix installation selector wrong history
Browse files Browse the repository at this point in the history
  • Loading branch information
szha committed Oct 10, 2019
1 parent cfe9e50 commit 1321b67
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions docs/static_site/src/assets/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
Expand All @@ -27,13 +27,13 @@ $(document).ready(function () {
}

function urlSearchParams(searchString) {
let urlDict = new Map();
let searchDict = new Map();
let searchParams = searchString.substring(1).split("&");
searchParams.forEach(function (element) {
kvPair = element.split("=");
urlDict.set(kvPair[0], kvPair[1]);
});
return urlDict;
return searchDict;
}

function is_a_match(elem, text) {
Expand All @@ -43,11 +43,10 @@ $(document).ready(function () {
}
}

function setSelects() {
let urlParams = urlSearchParams(window.location.search);
function setSelects(urlParams) {
if (urlParams.get('version'))
versionSelect = urlParams.get('version');
$('.current-version').html( versionSelect + ' <span class="caret"></span></button>' );
$('.current-version').html( versionSelect + ' <span class="caret"></span>' );
if (urlParams.get('platform'))
platformSelect = label(urlParams.get('platform'));
if (urlParams.get('language'))
Expand All @@ -66,8 +65,10 @@ $(document).ready(function () {
$('button.opt').each(function(){is_a_match($(this), environSelect)});

showContent();
let queryString = '?version=' + versionSelect + '&platform=' + platformSelect + '&language=' + languageSelect + '&environ=' + environSelect + '&processor=' + processorSelect;
window.location.search = queryString;
if (window.location.href.indexOf("/get_started/") >= 0) {
history.pushState(null, null, '?version=' + versionSelect + '&platform=' + platformSelect + '&language=' + languageSelect + '&environ=' + environSelect + '&processor=' + processorSelect);
history.pushState(null, null, queryString);
}
}

Expand All @@ -80,8 +81,7 @@ $(document).ready(function () {
});
}

showContent();
setSelects();
setSelects(urlSearchParams(window.location.search));

function setContent() {
var el = $(this);
Expand All @@ -90,27 +90,17 @@ $(document).ready(function () {
el.addClass('active');
if ($(this).hasClass("versions")) {
$('.current-version').html($(this).text());
if (window.location.search.indexOf("version") < 0) {
if (window.location.search.length > 0) {
var url = 'index.html' + window.location.search.concat('&version=' + $(this).text());
} else {
var url = 'index.html?version=' + $(this).text();
}
history.pushState(null, null, url);
} else {
history.pushState(null, null, 'index.html' + window.location.search.replace(urlParams.get('version'), $(this).text()));
}
urlParams.set("version", $(this).text());
} else if ($(this).hasClass("platforms")) {
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('platform'), '='+label($(this).text())));
urlParams.set("platform", label($(this).text()));
} else if ($(this).hasClass("languages")) {
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('language'), '='+label($(this).text())));
urlParams.set("language", label($(this).text()));
} else if ($(this).hasClass("processors")) {
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('processor'), '='+label($(this).text())));
urlParams.set("processor", label($(this).text()));
} else if ($(this).hasClass("environs")) {
history.pushState(null, null, 'index.html' + window.location.search.replace('='+urlParams.get('environ'), '='+label($(this).text())));
urlParams.set("environ", label($(this).text()));
}

showContent();
setSelects(urlParams);
}

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

0 comments on commit 1321b67

Please sign in to comment.