[web-php] master: Only "linked" parameters should have pointer cursor (#742)
| From: | Christoph M. Becker via GitHub | Date: | Thu, 10 Aug 2023 12:08:49 +0000 |
| Subject: | [web-php] master: Only "linked" parameters should have pointer cursor (#742) | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-30958@lists.php.net to get a copy of this message | ||
Author: Christoph M. Becker (cmb69)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2023-08-10T12:55:25+01:00
Commit: https://github.com/php/web-php/commit/84635938036c813a2337dfbfd97ffa8b0fe10ba6
Raw diff: https://github.com/php/web-php/commit/84635938036c813a2337dfbfd97ffa8b0fe10ba6.diff
Only "linked" parameters should have pointer cursor (#742)
If a parameter has no target to scroll to, it should not suggest
otherwise by changing the cursor to a pointer. Since the scrolling is
done via JS, we should also change the cursor via JS.[1]
While we're at it, we also fix the potential JS error where we call the
.offset() method on an empty jQuery object.
[1] <https://github.com/php/doc-en/issues/2071#issuecomment-1354497367>
Changed paths:
M js/common.js
M styles/theme-base.css
Diff:
diff --git a/js/common.js b/js/common.js
index 02076387ef..052c34e743 100644
--- a/js/common.js
+++ b/js/common.js
@@ -368,16 +368,29 @@ $(document).ready(function () {
$(this).append("<a class='genanchor' href='#" +
$(this).parent().attr("id") + "'> ¶</a>");
});
- $('.refentry code.parameter').click(function (event) {
- var id = $(this).text().replace(/^&?(\.\.\.)?\$?/g, '');
- var offsetTop = $('.parameters,
.options').find('.parameter').filter(function () {
- return $(this).text().trim() === id; // https://bugs.php.net/bug.php?id=74493
- }).offset().top - 52;
- $.scrollTo({
- top: offsetTop,
- left: 0
- }, 400);
- });
+ function findParameter(elt) {
+ var id = $(elt).text().replace(/^&?(\.\.\.)?\$?/g, '');
+ return $('.parameters, .options').find('.parameter').filter(function ()
{
+ return $(elt).text().trim() === id; // https://bugs.php.net/bug.php?id=74493
+ }).first();
+ }
+
+ $('.refentry code.parameter')
+ .each(function () {
+ var param = findParameter(this);
+ if (param.length) {
+ $(this).css('cursor', 'pointer');
+ }
+ })
+ .click(function () {
+ var param = findParameter(this);
+ if (param.length) {
+ $.scrollTo({
+ top: param.offset().top - 52,
+ left: 0
+ }, 400);
+ }
+ });
$('h1[id], h2[id], h3[id], h4[id]').each(function () {
var $this = $(this);
diff --git a/styles/theme-base.css b/styles/theme-base.css
index ae95208f24..756f4fbd3b 100644
--- a/styles/theme-base.css
+++ b/styles/theme-base.css
@@ -1220,9 +1220,6 @@ header.title {
/* {{{ General styles (p, parameters, initializers, ...) */
-.refsect1 .parameter {
- cursor:pointer;
-}
.refsect1 dt {
height:1.5rem;
}