about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-08-31 20:36:27 +0200
committerGitHub <noreply@github.com>2024-08-31 20:36:27 +0200
commit828f7c895a5c44161811b566e9bee6451536297f (patch)
treefa0b8d31ab3974e5147910e00b407173a2708cc8
parentb8b2a6503555fc5ea3b7c6516216c95e7b1a19ed (diff)
parent670a78b3a78ef341da7cdcafde58923a66b82ff9 (diff)
downloadrust-828f7c895a5c44161811b566e9bee6451536297f.tar.gz
rust-828f7c895a5c44161811b566e9bee6451536297f.zip
Rollup merge of #129824 - GuillaumeGomez:code-example-buttons-mobile, r=notriddle
Fix code examples buttons not appearing on click on mobile

When browsing docs on mobile today, I realized that the buttons didn't appear when I tapped on the code example.

One issue: I have no idea how to add a regression test for this case...

r? ``@notriddle``
-rw-r--r--src/librustdoc/html/static/js/main.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js
index 75f2a1418cd..c3e219f2c87 100644
--- a/src/librustdoc/html/static/js/main.js
+++ b/src/librustdoc/html/static/js/main.js
@@ -1878,9 +1878,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm
         if (elem === null) {
             return;
         }
-        const buttons = elem.querySelector(".button-holder");
+        let buttons = elem.querySelector(".button-holder");
         if (buttons === null) {
-            return;
+            // On mobile, you can't hover an element so buttons need to be created on click
+            // if they're not already there.
+            addCopyButton(event);
+            buttons = elem.querySelector(".button-holder");
+            if (buttons === null) {
+                return;
+            }
         }
         buttons.classList.toggle("keep-visible");
     }