Skip to content

Commit

Permalink
fix bug when mode is null
Browse files Browse the repository at this point in the history
  • Loading branch information
lperry25 committed Dec 20, 2024
1 parent 2136abf commit d58e5d8
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions _includes/navbar.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Copyright Vespa.ai. All rights reserved.. -->
<script>

function setmodeParam(mode) {
function setModeParam(mode) {
const currentUrl = new URL(window.location.href); // Get the current URL
const urlParams = new URLSearchParams(currentUrl.search);
urlParams.set('mode', mode); // Set or update the query parameter
Expand All @@ -23,7 +23,7 @@
}
}

function handleCurrentmode(currentmode){
function handleCurrentMode(currentmode){
localStorage.setItem('mode', currentmode);
if (currentmode === 'cloud'){
hideElements('selfhosted');
Expand All @@ -33,9 +33,9 @@
showElements('selfhosted')
}
}
function selectmode(mode) {
setmodeParam(mode);
handleCurrentmode(mode);
function selectMode(mode) {
setModeParam(mode);
handleCurrentMode(mode);
}

document.addEventListener('DOMContentLoaded', function() {
Expand All @@ -44,25 +44,26 @@
let currentmode = urlParams.get('mode');
if (!currentmode) {
currentmode = localStorage.getItem('mode');
setmodeParam(currentmode);
if (currentmode) {
setModeParam(currentmode);
} else if (!currentmode) {
// This is temporairly added so that we can test the new mode selector
// The selector will only appear if there is ?mode= in the url or if it is stored in local storage
if (!currentmode) {
document.getElementById('docs-mode').classList.add('hide');
document.getElementById('sidebar').classList.remove('p-t-35');
showElements('cloud');
showElements('selfhosted');
}
}

if(currentmode){
if(currentmode !== null){
document.getElementById('docs-mode').value = currentmode;
handleCurrentmode(currentmode);
handleCurrentMode(currentmode);
}

document.getElementById('docs-mode').addEventListener('change', function() {
const selectedValue = this.value;
selectmode(selectedValue);
selectMode(selectedValue);
});
});

Expand Down

0 comments on commit d58e5d8

Please sign in to comment.