From 2a5ddb69754d514f663e4c2f76227e3103882679 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 27 Oct 2024 06:27:05 -0400 Subject: [PATCH] fix --- deepmodeling_sphinx/banner.css | 1 + deepmodeling_sphinx/banner.js | 48 ++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/deepmodeling_sphinx/banner.css b/deepmodeling_sphinx/banner.css index 6acc7a4..d8b8605 100644 --- a/deepmodeling_sphinx/banner.css +++ b/deepmodeling_sphinx/banner.css @@ -135,6 +135,7 @@ under MIT license display: block; float: left; z-index: 10; + text-decoration: none; } .header-logo::after { diff --git a/deepmodeling_sphinx/banner.js b/deepmodeling_sphinx/banner.js index e3abc8d..f029b38 100644 --- a/deepmodeling_sphinx/banner.js +++ b/deepmodeling_sphinx/banner.js @@ -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(); });