Skip to content

Commit

Permalink
deploy: 1fc560c
Browse files Browse the repository at this point in the history
  • Loading branch information
JoostBuitink committed Nov 13, 2024
1 parent 3995d56 commit 38ad3ab
Show file tree
Hide file tree
Showing 82 changed files with 48,736 additions and 0 deletions.
Empty file added previews/PR448/.nojekyll
Empty file.
783 changes: 783 additions & 0 deletions previews/PR448/404.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions previews/PR448/_static/images/deltares-blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions previews/PR448/_static/images/deltares-white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added previews/PR448/_static/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions previews/PR448/_static/styles.css
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;
}
141 changes: 141 additions & 0 deletions previews/PR448/_static/version.js
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
}
Loading

0 comments on commit 38ad3ab

Please sign in to comment.