Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions cwms-data-api/src/main/webapp/css/HEC.header.css
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,14 @@ a {
color: #f1f1f1;
}

.overlay .closebtn {
.overlay .closeBtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}

.closebtn:hover::before {
.closeBtn:hover::before {
content: "";
}

Expand Down Expand Up @@ -455,7 +455,7 @@ a {

.top-level-menu {
list-style: none;
display: block;
display: flex;
padding: 0;
color: #d0d0d0;
font-size: 13.6px;
Expand Down Expand Up @@ -484,6 +484,11 @@ a {
line-height: initial;
}

/* Bootstrap/tailwind-esq classes */
.ml-auto {
margin-left: auto;
}

/* Menu Link Styles */

.top-level-menu a
Expand Down Expand Up @@ -598,7 +603,7 @@ a {
display: inline-block;
}

.overlay .closebtn {
.overlay .closeBtn {
font-size: 40px;
top: -5px;
right: 5px;
Expand Down
51 changes: 29 additions & 22 deletions cwms-data-api/src/main/webapp/js/header.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
window.addEventListener("load", function() {
var coll_mob = document.getElementsByClassName("collapsible-mobile");
for (let col_m_idx = 0; col_m_idx < coll_mob.length; col_m_idx++) {
// Setup the page's collapses
let coll_mob = document.getElementsByClassName("collapsible-mobile");
for (let col_m_idx = 0; col_m_idx < coll_mob.length; col_m_idx++) {
coll_mob[col_m_idx].addEventListener("click", function (e) {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display == "none") {
content.style.display = "block";
} else {
content.style.display = "none";
}
this.classList.toggle("active");
const content = this.nextElementSibling;
if (content.style.display == "none") {
content.style.display = "block";
} else {
content.style.display = "none";
}
});
}
}, false);
}
const burgerBtn = document.getElementById("burgerBtn");
if (burgerBtn) {
burgerBtn.addEventListener("click", openNav);
}
const closeBtn = document.querySelector(".closeBtn");
if (closeBtn) {
closeBtn.addEventListener("click", closeNav);
}

// Mobile Burger Bar
function openNav() {
var mobileNav = document.getElementById("mobileNav");
mobileNav.classList.add("open");
var child = document.getElementById("mobileNavContent");
mobileNav.style.right = child.clientWidth - child.offsetWidth + "px";
var open = document.getElementById("burgerBtn");
open.style.display = "none";
var child = document.getElementById("overlay-content");
const mobileNav = document.getElementById("mobileNav");
mobileNav.classList.add("open");
const child = document.getElementById("mobileNavContent");
mobileNav.style.right = child.clientWidth - child.offsetWidth + "px";
const BURGER_BTN = document.getElementById("burgerBtn");
BURGER_BTN.style.display = "none";
}

function closeNav() {
mobileNav.classList.remove("open");
var open = document.getElementById("burgerBtn");
open.style.display = null;
const mobileNav = document.getElementById("mobileNav")
mobileNav.classList.remove("open");
const BURGER_BTN = document.getElementById("burgerBtn");
BURGER_BTN.style.display = null;
}
53 changes: 40 additions & 13 deletions cwms-data-api/src/main/webapp/js/util.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
function load (id, url) {
var con = document.getElementById(id)
var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function (e) {
if (xhr.readyState == 4 && xhr.status == 200) {
con.innerHTML = xhr.responseText;
}
}

xhr.open("GET", url, true);
xhr.setRequestHeader('Content-type', 'text/html');
xhr.send();
function load(id, url) {
var con = document.getElementById(id);
var xhr = new XMLHttpRequest();

xhr.onreadystatechange = function () {
// Check if the request is complete and was successful
if (xhr.readyState == 4 && xhr.status == 200) {
con.innerHTML = xhr.responseText;

// Reinitialize any scripts in the loaded content
// This is necessary because innerHTML does not execute scripts
// We create new script elements and replace the old ones
// to ensure they are executed.
const scripts = con.querySelectorAll("script");
scripts.forEach((oldScript) => {
const newScript = document.createElement("script");

// Add attributes from the old script to the new one
Array.from(oldScript.attributes).forEach(attr =>
newScript.setAttribute(attr.name, attr.value)
);

// If the old script has inline code, set it as the text content of the new script
if (oldScript.innerHTML) {
newScript.textContent = oldScript.innerHTML;
}

// Replace the old script with the new one
oldScript.parentNode.replaceChild(newScript, oldScript);
});
}
else if (xhr.readyState == 4) {
console.error("Error loading content from " + url + ": " + xhr.statusText);
con.innerHTML = "<p>Error loading content. Please try again later.</p>";
}
};

xhr.open("GET", url, true);
xhr.setRequestHeader("Content-type", "text/html");
xhr.send();
}
28 changes: 24 additions & 4 deletions cwms-data-api/src/main/webapp/templates/HEC.header.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,39 @@
<ul class="top-level-menu">
<li><a href="./swagger-docs">Swagger Docs</a></li>
<li><a href="./swagger-ui.html">Swagger UI</a></li>
<li><a>Client Libraries <i class="fas fa-caret-down"></i></a>
<ul class="second-level-menu">
<li><a href="https://github.com/HydrologicEngineeringCenter/cwms-python"><i class="fab fa-python"></i> Python</a></li>
<li><a href="#"><i class="fab fa-js-square"></i> JavaScript <i class="fas fa-caret-right"></i></a>
<ul class="third-level-menu">
<li><a href="https://hydrologicengineeringcenter.github.io/cwms-data-api-client-javascript/"> User Docs</a></li>
<li><a href="https://github.com/hydrologicengineeringcenter/cwms-data-api-client-javascript"><i class="fab fa-github"></i> Github</a></li>
</ul>
</li>
</ul>
</li>
<li class="ml-auto"><a href="https://hydrologicengineeringcenter.github.io/cwms-data-api-client-java/"><i class="fab fa-github"></i> CDA GitHub</a></li>
<li id="sphinx-docs" />
</ul>
</div>
<div id="mobile-menu">
<span class="burger-bar" id="burgerBtn" onclick="openNav()">&#9776;</span>
<span class="burger-bar" id="burgerBtn">&#9776;</span>
</div>
</div>
<div id="mobileNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a href="javascript:void(0)" class="closeBtn">&times;</a>
<div id="mobileNavContent" class="overlay-content">
<a class="home mobile-top-level-menu" href="./swagger-docs">Swagger Docs</a>
<a class="home mobile-top-level-menu" href="./swagger-ui.html">Swagger UI</a>
</div>
<a class="home mobile-top-level-menu" href="https://hydrologicengineeringcenter.github.io/cwms-data-api-client-java/"><i class="fab fa-github"></i> CDA GitHub</a>
<div title="Click to Expand" class="collapsible-mobile mobile-top-level-menu active">
Client Libraries <i class="fas fa-caret-down"></i>
</div>
<div class="content-mobile" style="display: block;">
<a class="menu-item" href="https://github.com/HydrologicEngineeringCenter/cwms-python"><i class="fab fa-python"></i> Python</a>
<a class="menu-item" href="https://hydrologicengineeringcenter.github.io/cwms-data-api-client-javascript/"><i class="fab fa-js-square"></i> JavaScript - User Docs</a>
<a class="menu-item" href="https://github.com/HydrologicEngineeringCenter/cwms-data-api-client-javascript"><i class="fab fa-github"></i> JavaScript - Github</a>
</div>
</div>
</div>
</div>
Expand All @@ -48,7 +68,7 @@
</div>

<!-- Burger Bar Control -->
<script defer type="text/javascript" src="./js/header.js"></script>
<script defer type="text/javascript" src="./js/header.js?_=2"></script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of the ?_=2?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sure if someone has loaded the header recently and has it cached that it will force the browser to refetch the file (ignore cache). I've also used v=2 to try to make that more clear in other sites, but I wasn't intending on starting versioning for that file as someone may miss this little detail between updates.

Instead I use _ to suggest this parameter value is not important to being passed in.

Although technically I don't think this JavaScript was being executed/fetched in the current site so in this case it might not actually do anything!

We could certainly get more into this topic, but it won't matter when the site goes to using vite as it uses a new css/file hash for each build. (Files are hashed on the output of the bundler rollup): https://vite.dev/guide/build.html#advanced-base-options

Read more on the cache busting I did above with _= here: (they use ver)
https://www.keycdn.com/support/what-is-cache-busting#using-cache-busting-with-a-cdn

<script type="text/javascript">
// Setup the page's collapses
let coll_legend = document.getElementsByClassName("collapsible-legend");
Expand Down
Loading