-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3995d56
commit 38ad3ab
Showing
82 changed files
with
48,736 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* css styles */ | ||
|
||
.only-on-dark { | ||
display: none; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
.only-on-dark { | ||
display: block; | ||
} | ||
|
||
.only-on-light { | ||
display: none; | ||
} | ||
} | ||
|
||
[aria-label="Deltares-Image"] { | ||
height: 30px; | ||
} | ||
|
||
.navbar-right .fa-github { | ||
font-size: 40px; /* Adjust the value as needed */ | ||
} | ||
|
||
.active-item { | ||
font-weight: bold; | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
function checkPathExists(url) { | ||
return new Promise((resolve, reject) => { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open('HEAD', url, true); | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState === 4) { | ||
if (xhr.status === 200) { | ||
resolve(true); | ||
} else if (xhr.status === 404) { | ||
resolve(false); | ||
} else { | ||
reject(new Error(xhr.statusText)); | ||
} | ||
} | ||
}; | ||
xhr.onerror = function () { | ||
reject(new Error('Network Error')); | ||
}; | ||
xhr.send(); | ||
}); | ||
} | ||
|
||
window.onload = function () { | ||
// Assuming you have a ul element in your HTML like this: | ||
// <ul id="myDropdown"></ul> | ||
|
||
// Fetch the JSON data | ||
fetch("https://raw.githubusercontent.com/Deltares/Wflow.jl/gh-pages/switcher.json") | ||
.then(response => response.json()) | ||
.then(data => { | ||
console.log('Data loaded:', data); // Log the loaded data | ||
|
||
const dropdown = document.querySelector('#nav-menu-version').nextElementSibling; | ||
console.log('Dropdown element:', dropdown); // Log the dropdown element | ||
|
||
// Clear all existing dropdown items | ||
dropdown.innerHTML = ''; | ||
|
||
data.forEach(item => { | ||
console.log('Adding item:', item); // Log the item being added | ||
|
||
// Create a new li element | ||
const li = document.createElement('li'); | ||
|
||
// Create a new a element | ||
const a = document.createElement('a'); | ||
a.className = 'dropdown-item'; | ||
a.href = item.href; // Use the 'url' property as the href | ||
a.textContent = item.name; // Use the 'name' property as the text | ||
|
||
// Add the a element to the li | ||
li.appendChild(a); | ||
|
||
// Add the li to the dropdown | ||
dropdown.appendChild(li); | ||
}); | ||
|
||
console.log('Dropdown after adding items:', dropdown); // Log the dropdown after adding items | ||
|
||
// Get all dropdown items within the specific dropdown menu | ||
var dropdownMenu = document.querySelector('#nav-menu-version').nextElementSibling; | ||
|
||
var dropdownItems = dropdownMenu.querySelectorAll('.dropdown-item'); | ||
|
||
// Get the current page in chunks | ||
var currentPagePath = window.location.pathname.split('/'); | ||
|
||
for (var i = 0; i < dropdownItems.length; i++) { | ||
// Get textcontent | ||
var textContent = dropdownItems[i].textContent; | ||
|
||
// Get the index of the current version | ||
var index = currentPagePath.indexOf(textContent); | ||
|
||
if (index !== -1) { | ||
// Remove the active-item class from all items | ||
for (var j = 0; j < dropdownItems.length; j++) { | ||
dropdownItems[j].classList.remove('active-item'); | ||
} | ||
|
||
dropdownItems[i].classList.add('active-item'); | ||
break | ||
} | ||
} | ||
|
||
console.log('current page path', currentPagePath); | ||
|
||
// Loop through each dropdown item | ||
for (var i = 0; i < dropdownItems.length; i++) { | ||
// Add click event listener to each item | ||
dropdownItems[i].addEventListener('click', function (event) { | ||
// Prevent default action | ||
event.preventDefault(); | ||
|
||
// Get the clicked item's text | ||
var itemText = this.textContent; | ||
var itemHref = this.getAttribute('href') | ||
|
||
// Loop through each dropdown item again to find a match in the current page's path | ||
for (var j = 0; j < dropdownItems.length; j++) { | ||
// Get the dropdown item's text | ||
var dropdownText = dropdownItems[j].textContent; | ||
console.log('Dropdown item:', dropdownText); | ||
|
||
window.location.href = itemHref; | ||
|
||
// The code below is taken from Delft-FIAT, and is in place to switch | ||
// to the same page but on a different version (if that exists). This | ||
// is currently overruled with the line above this comment, which | ||
// redirects to the new URL (home page). | ||
|
||
// // Find the index of the dropdownText in the current page's path | ||
// var index = currentPagePath.indexOf(dropdownText); | ||
// // If the dropdownText is found in the current page's path | ||
// if (index !== -1) { | ||
// // Construct the new URL relative to the dropdownText and append the itemText | ||
// addElements = currentPagePath.slice(index + 1,) | ||
// var newUrl = itemHref + '/' + addElements.join('/') | ||
// console.log('Clicked item:', newUrl); | ||
// window.location.href = itemHref; | ||
// // // Redirect to the new URL | ||
// // checkPathExists(newUrl) | ||
// // .then(exists => { | ||
// // if (exists) { | ||
// // window.location.href = newUrl; | ||
// // } else { | ||
// // console.log('Path does not exist, referring to home page'); | ||
// // window.location.href = itemHref; | ||
// // } | ||
// // }) | ||
|
||
// // Exit the loop | ||
// break; | ||
// } | ||
} | ||
}); | ||
} | ||
|
||
}) | ||
.catch(error => console.error('Error:', error)); // Log any errors | ||
} |
Oops, something went wrong.