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

[DOC] fix installation selector wrong history #16381

Merged
merged 3 commits into from
Oct 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 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 @@ -17,7 +17,9 @@
* under the License.
*/

/* Installation page display functions for install selector */
/* Installation page display functions for install selector.
This utility allows direct links to specific install instructions.
*/

$(document).ready(function () {
function label(lbl) {
Expand All @@ -27,13 +29,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]);
searchDict.set(kvPair[0], kvPair[1]);
});
return urlDict;
return searchDict;
}

function is_a_match(elem, text) {
Expand All @@ -43,11 +45,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 +67,9 @@ $(document).ready(function () {
$('button.opt').each(function(){is_a_match($(this), environSelect)});

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

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

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

function setContent() {
var el = $(this);
Expand All @@ -90,27 +91,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