mirror of
https://codeberg.org/vlw/vlw.se.git
synced 2025-09-13 21:13:40 +02:00
The PR is a huge refactor of all Reflect and Vegvisir code. I've merged the API and "Front-end" codebases together into the same root, this will allow for both Reflect and Vegvisir to use the same resources. Not only that, but I've also added proper database modeling with actual OOP inheritance for database tables. Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/23
56 lines
No EOL
2.1 KiB
JavaScript
56 lines
No EOL
2.1 KiB
JavaScript
import { Elevent } from "/assets/js/modules/npm/Elevent.mjs";
|
|
|
|
const CLASSNAME_SEARCHBOX_ACTIVE = "searchboxActive";
|
|
|
|
// Set global Vegvisir naviation delay for page transition effect
|
|
globalThis.vegvisir.globalNavigationDelayMs = 100;
|
|
|
|
// Handle search box open/close buttons
|
|
{
|
|
// Open search box
|
|
new Elevent("click", document.querySelector(".searchbox-open"), () => {
|
|
document.querySelector("header").classList.add(CLASSNAME_SEARCHBOX_ACTIVE);
|
|
// Select searchbox inner input element
|
|
document.querySelector("searchbox input").focus();
|
|
});
|
|
|
|
// Close searchbox
|
|
new Elevent("click", document.querySelector(".searchbox-close"), () => {
|
|
// Disable search button interaction while animation is running
|
|
// This is required to prevent conflicts with the :hover "peak" transformation
|
|
const searchButtonElement = document.querySelector("header button.search");
|
|
const transformDuration = parseInt(window.getComputedStyle(searchButtonElement).getPropertyValue("--transform-duration"));
|
|
searchButtonElement.style.setProperty("pointer-events", "none");
|
|
|
|
document.querySelector("header").classList.remove(CLASSNAME_SEARCHBOX_ACTIVE);
|
|
|
|
// Wait for the transform animation to finish
|
|
setTimeout(() => searchButtonElement.style.removeProperty("pointer-events"), transformDuration);
|
|
});
|
|
}
|
|
|
|
// Root shell navigation event handlers
|
|
{
|
|
// On all top shell navigations
|
|
new Elevent(vv.Navigation.EVENTS.STARTED, vv.Navigation.rootShellElement, () => {
|
|
// Close searchbox on top shell navigations
|
|
document.querySelector("header").classList.remove(CLASSNAME_SEARCHBOX_ACTIVE);
|
|
});
|
|
}
|
|
|
|
// Handle search logic
|
|
{
|
|
const searchResultsElement = document.querySelector("search-results");
|
|
|
|
document.querySelector("header input[type='search']").addEventListener("input", (event) => {
|
|
// Debounce user input
|
|
clearTimeout(event.target._throttle);
|
|
event.target._throttle = setTimeout(() => {
|
|
// Navigate search-results element on user input
|
|
new vv.Navigation(`/search?query=${event.target.value}`).navigate(searchResultsElement);
|
|
}, 100);
|
|
});
|
|
}
|
|
|
|
// Scroll page to top on navigation
|
|
document.addEventListener(vegvisir.Navigation.EVENTS.FINISHED, () => window.scrollTo({ top: 0 })); |