From d2f8fc4ac5abfe7da49af35f86c64c8dc4e5d08e Mon Sep 17 00:00:00 2001 From: Rush <84793349+zhuba-Ahhh@users.noreply.github.com> Date: Fri, 14 Jun 2024 00:17:26 +0800 Subject: [PATCH] Fix: Click anywhere on the language switch menu to switch the language (#2144) close: https://github.com/google/comprehensive-rust/issues/2132 --- theme/index.hbs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/theme/index.hbs b/theme/index.hbs index 6b4ece2c..e9fd26aa 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -224,6 +224,18 @@ lang.href = `${full_path_to_root}${lang.id}/${path}`; } } + + // When the user clicks a list item, the page jump is performed, just like clicking the internal tag. + langList.querySelectorAll("li").forEach(function(li) { + li.addEventListener("click", function(event) { + event.preventDefault(); + + let link = this.querySelector("a"); + if (link && window.location.href !== link.href) { + window.location.href = link.href; + } + }); + }); {{#if print_enable}}