This is an automated email from the ASF dual-hosted git repository. twolf pushed a commit to branch dev_3.0 in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
The following commit(s) were added to refs/heads/dev_3.0 by this push: new 355dc5530 [site] Open details when link is clicked 355dc5530 is described below commit 355dc55304e2a326277625655d3d34122fc8369c Author: Thomas Wolf <tw...@apache.org> AuthorDate: Wed Apr 23 10:58:50 2025 +0200 [site] Open details when link is clicked When a link points to a target inside a <details> element that is closed, some browsers (like Firefox) will not open the <details>. This gives a bad user experience: the user clicks a link, but nothing happens (apart from the URL shown in the browser changing). Intercept the link activation and if the target is inside closed <details> elements, open them. That way, the navigation works. --- sshd-site/src/site/resources/js/detailopener.js | 46 +++++++++++++++++++++++++ sshd-site/src/site/site.xml | 5 ++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/sshd-site/src/site/resources/js/detailopener.js b/sshd-site/src/site/resources/js/detailopener.js new file mode 100644 index 000000000..367ec4076 --- /dev/null +++ b/sshd-site/src/site/resources/js/detailopener.js @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const openDetails = (link) => { + let detail = link.closest('details'); + while (detail) { + detail.open = true; + const parent = detail.parentNode; + if (parent) { + detail = parent.closest('details'); + } + } +}; + +document.addEventListener('click', (e) => { + // If the target of an internal link is inside a closed "details" section, open the details. + // Otherwise navigation may not work, and the user has to open the details section manually + // first, which is a lousy user experience. (Some browsers may open the details automatically, + // but others, like Firefox, don't.) + const link = e.target.closest('a'); + if (link) { + const href = link.getAttribute('href'); + if (href && href.startsWith('#')) { + const target = document.getElementById(href.substring(1)); + if (target) { + openDetails(target); + } + } + } +}); diff --git a/sshd-site/src/site/site.xml b/sshd-site/src/site/site.xml index 552c38f99..ebe63574d 100644 --- a/sshd-site/src/site/site.xml +++ b/sshd-site/src/site/site.xml @@ -40,7 +40,10 @@ limitations under the License. <body> <head> - <![CDATA[<link rel="stylesheet" href="./css/custom.css" />]]> + <![CDATA[ + <link rel="stylesheet" href="./css/custom.css" /> + <script src="./js/detailopener.js"></script> +]]> </head> <breadcrumbs>