Skip to content

Commit

Permalink
Explanatory comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
DogukanUrker committed Jan 21, 2024
1 parent af313cd commit dffe2a9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
54 changes: 45 additions & 9 deletions static/standardUI/js/navbar.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
/**
* Toggles the visibility of the hamburger dropdown menu
* @param {Event} event - The click event that triggered the function
*/
function hamburger(event) {
/**
* The element that contains the hamburger dropdown menu
* @type {HTMLElement}
*/
const hamburgerDropdown = document.getElementById("hamburgerDropdown");

/**
* Toggles the class "show" on the hamburger dropdown menu
*/
hamburgerDropdown.classList.toggle("show");
}

/**
* Redirects the user to the search results page when the search button is clicked
*/
function search() {
const input = document.querySelector("#searchInput").value;
if (input === "" || input.trim() === "") {
/**
* The input element for the search query
* @type {HTMLInputElement}
*/
const input = document.querySelector("#searchInput");

/**
* The value of the search query
* @type {string}
*/
const inputValue = input.value;

/**
* The URL for the search results page
* @type {string}
*/
const searchUrl = `/search/${encodeURIComponent(escape(inputValue))}`;

if (inputValue === "" || inputValue.trim() === "") {
// do nothing
} else {
window.location.href = `/search/${encodeURIComponent(
escape(input.trim())
)}`;
window.location.href = searchUrl;
}
}

function hamburger() {
document.getElementById("hamburgerDropdown").classList.toggle("show");
}

/**
* Closes the hamburger dropdown menu when a click event occurs outside of the menu
* @param {Event} event - The click event that triggered the function
*/
window.onclick = function(event) {
if (!event.target.matches(".hamburgerBtn")) {
var dropdowns = document.getElementsByClassName("hamburgerContent");
Expand Down
22 changes: 5 additions & 17 deletions static/tailwindUI/js/navbar.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
/**
*
* @param {string} input
*/
function search() {
const input = document.querySelector("#searchInput").value;
if (input === "" || input.trim() === "") {
// do litteraly nothing
} else {
window.location.href = `/search/${encodeURIComponent(
escape(input.trim())
)}`;
}
}

function hamburger() {
document.getElementById("hamburgerDropdown").classList.toggle("show");
}

window.onclick = function(event) {
if (!event.target.matches(".hamburgerBtn")) {
var dropdowns = document.getElementsByClassName("hamburgerContent");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains("show")) {
openDropdown.classList.remove("show");
}
}
}
};

0 comments on commit dffe2a9

Please sign in to comment.