mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-20 10:05:20 +00:00
Merge pull request #1130 from ae-utbm/navbar-keyboard-navigation
Fix click on navbar
This commit is contained in:
commit
af67c5fc27
36
core/static/bundled/core/navbar-index.ts
Normal file
36
core/static/bundled/core/navbar-index.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { exportToHtml } from "#core:utils/globals";
|
||||||
|
|
||||||
|
exportToHtml("showMenu", () => {
|
||||||
|
const navbar = document.getElementById("navbar-content");
|
||||||
|
const current = navbar.getAttribute("mobile-display");
|
||||||
|
navbar.setAttribute("mobile-display", current === "hidden" ? "revealed" : "hidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener("alpine:init", () => {
|
||||||
|
const menuItems = document.querySelectorAll(".navbar details[name='navbar'].menu");
|
||||||
|
const isDesktop = () => {
|
||||||
|
return window.innerWidth >= 500;
|
||||||
|
};
|
||||||
|
for (const item of menuItems) {
|
||||||
|
item.addEventListener("mouseover", () => {
|
||||||
|
if (isDesktop()) {
|
||||||
|
item.setAttribute("open", "");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
item.addEventListener("mouseout", () => {
|
||||||
|
if (isDesktop()) {
|
||||||
|
item.removeAttribute("open");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
item.addEventListener("click", (event: MouseEvent) => {
|
||||||
|
// Don't close when clicking on desktop mode
|
||||||
|
if ((event.target as HTMLElement).nodeName !== "SUMMARY" || event.detail === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDesktop()) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -18,6 +18,7 @@
|
|||||||
<noscript><link rel="stylesheet" href="{{ static('bundled/fontawesome-index.css') }}"></noscript>
|
<noscript><link rel="stylesheet" href="{{ static('bundled/fontawesome-index.css') }}"></noscript>
|
||||||
|
|
||||||
<script src="{{ url('javascript-catalog') }}"></script>
|
<script src="{{ url('javascript-catalog') }}"></script>
|
||||||
|
<script type="module" src={{ static("bundled/core/navbar-index.ts") }}></script>
|
||||||
<script type="module" src={{ static("bundled/core/components/include-index.ts") }}></script>
|
<script type="module" src={{ static("bundled/core/components/include-index.ts") }}></script>
|
||||||
<script type="module" src="{{ static('bundled/alpine-index.js') }}"></script>
|
<script type="module" src="{{ static('bundled/alpine-index.js') }}"></script>
|
||||||
<script type="module" src="{{ static('bundled/htmx-index.js') }}"></script>
|
<script type="module" src="{{ static('bundled/htmx-index.js') }}"></script>
|
||||||
@ -107,39 +108,6 @@
|
|||||||
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script>
|
<script>
|
||||||
const menuItems = document.querySelectorAll(".navbar details[name='navbar'].menu");
|
|
||||||
const isDesktop = () => {
|
|
||||||
return window.innerWidth >= 500;
|
|
||||||
}
|
|
||||||
for (const item of menuItems){
|
|
||||||
item.addEventListener("mouseover", () => {
|
|
||||||
if (isDesktop()){
|
|
||||||
item.setAttribute("open", "");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
item.addEventListener("mouseout", () => {
|
|
||||||
if (isDesktop()){
|
|
||||||
item.removeAttribute("open");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
item.addEventListener("click", (event) => {
|
|
||||||
// Ignore keyboard clicks
|
|
||||||
if (event.detail === 0){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDesktop()){
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function showMenu() {
|
|
||||||
let navbar = document.getElementById("navbar-content");
|
|
||||||
const current = navbar.getAttribute("mobile-display");
|
|
||||||
navbar.setAttribute("mobile-display", current === "hidden" ? "revealed" : "hidden")
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener("keydown", (e) => {
|
document.addEventListener("keydown", (e) => {
|
||||||
// Looking at the `s` key when not typing in a form
|
// Looking at the `s` key when not typing in a form
|
||||||
if (e.keyCode !== 83 || ["INPUT", "TEXTAREA", "SELECT"].includes(e.target.nodeName)) {
|
if (e.keyCode !== 83 || ["INPUT", "TEXTAREA", "SELECT"].includes(e.target.nodeName)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user