zulip/static/js/portico/header.js

50 lines
2.0 KiB
JavaScript
Raw Normal View History

import $ from "jquery";
$(() => {
$(".portico-header li.logout").on("click", () => {
$("#logout_form").trigger("submit");
return false;
});
2021-08-05 02:14:15 +02:00
$(".dropdown").on("click", (e) => {
const $this = $(e.target);
const dropdown_is_shown = $this.closest("ul .dropdown").hasClass("show");
2021-08-05 02:14:15 +02:00
if (!dropdown_is_shown) {
$this.closest("ul .dropdown").addClass("show");
2021-08-05 02:14:15 +02:00
} else if (dropdown_is_shown) {
$this.closest("ul .dropdown").removeClass("show");
}
});
$(".nav-dropdown").on("mouseover", (e) => {
const $this = $(e.target);
2021-08-05 02:14:15 +02:00
// We switch to a vertical sidebar menu at width <= 1024px
const in_vertical_orientation = window.matchMedia("(max-width: 1024px)").matches;
// We only support mouseover events if we are in a horizontal
// orientation (width > 1024px) and if the primary input mechanism
// can hover over elements.
const hover_supported = window.matchMedia("(hover: hover)").matches;
const dropdown_is_shown = $this.closest("ul .dropdown").hasClass("show");
2021-08-05 02:14:15 +02:00
if (!dropdown_is_shown && !in_vertical_orientation && hover_supported) {
$this.closest("ul .dropdown").addClass("show");
}
});
$(".nav-dropdown").on("mouseout", (e) => {
const $this = $(e.target);
2021-08-05 02:14:15 +02:00
// We switch to a vertical sidebar menu at width <= 1024px
const in_vertical_orientation = window.matchMedia("(max-width: 1024px)").matches;
// We only support mouseout events if we are in a horizontal
// orientation (width > 1024px) and if the primary input mechanism
// can hover over elements.
const hover_supported = window.matchMedia("(hover: hover)").matches;
const dropdown_is_shown = $this.closest("ul .dropdown").hasClass("show");
2021-08-05 02:14:15 +02:00
if (dropdown_is_shown && !in_vertical_orientation && hover_supported) {
$this.closest("ul .dropdown").removeClass("show");
}
});
});