Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
njzjz authored Oct 27, 2024
1 parent 948e2d5 commit 2a5ddb6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions deepmodeling_sphinx/banner.css
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ under MIT license
display: block;
float: left;
z-index: 10;
text-decoration: none;
}

.header-logo::after {
Expand Down
48 changes: 32 additions & 16 deletions deepmodeling_sphinx/banner.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
/* The initial version is taken from
https://github.com/pytorch/pytorch_sphinx_theme
under MIT license
rewrite to remove jQuery by ChatGPT
*/
window.mobileMenu = {
bind: function () {
$("[data-behavior='open-mobile-menu']").on("click", function (e) {
e.preventDefault();
$(".mobile-main-menu").addClass("open");
$("body").addClass("no-scroll");
document.querySelectorAll("[data-behavior='open-mobile-menu']").forEach(function (element) {
element.addEventListener("click", function (e) {
e.preventDefault();
document.querySelector(".mobile-main-menu").classList.add("open");
document.body.classList.add("no-scroll");

mobileMenu.listenForResize();
mobileMenu.listenForResize();
});
});

$("[data-behavior='close-mobile-menu']").on("click", function (e) {
e.preventDefault();
mobileMenu.close();
document.querySelectorAll("[data-behavior='close-mobile-menu']").forEach(function (element) {
element.addEventListener("click", function (e) {
e.preventDefault();
mobileMenu.close();
});
});
},

listenForResize: function () {
$(window).on("resize.ForMobileMenu", function () {
if ($(this).width() > 768) {
function resizeHandler() {
if (window.innerWidth > 768) {
mobileMenu.close();
}
});
}

window.addEventListener("resize", resizeHandler);

// Store the handler so it can be removed later
this.resizeHandler = resizeHandler;
},

close: function () {
$(".mobile-main-menu").removeClass("open");
$("body").removeClass("no-scroll");
$(window).off("resize.ForMobileMenu");
},
document.querySelector(".mobile-main-menu").classList.remove("open");
document.body.classList.remove("no-scroll");

// Remove the resize event listener
if (this.resizeHandler) {
window.removeEventListener("resize", this.resizeHandler);
this.resizeHandler = null;
}
}
};
$(document).ready(function () {

document.addEventListener("DOMContentLoaded", function () {
mobileMenu.bind();
});

0 comments on commit 2a5ddb6

Please sign in to comment.