Skip to content

Commit 734afb4

Browse files
committed
Make spotlight show on hover
This makes the spotlight show on hover instead of click. Clicks can be used to persist it, which is also what's used on mobile.
1 parent c90fb71 commit 734afb4

File tree

5 files changed

+53
-156
lines changed

5 files changed

+53
-156
lines changed

src/librustdoc/html/render.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,11 +2613,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait)
26132613
let name = m.name.as_ref().unwrap();
26142614
let item_type = m.type_();
26152615
let id = cx.derive_id(format!("{}.{}", item_type, name));
2616-
write!(
2617-
w,
2618-
"<h3 id='{id}' class='method'><code>",
2619-
id = id,
2620-
);
2616+
write!(w, "<h3 id='{id}' class='method'><code>", id = id,);
26212617
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl);
26222618
write!(w, "</code>");
26232619
render_stability_since(w, m, t);
@@ -3612,14 +3608,10 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
36123608
if !out.is_empty() {
36133609
out.insert_str(
36143610
0,
3615-
&format!(
3616-
"<span class=\"important-traits\"><div class='tooltip'>ⓘ\
3617-
<span class='tooltiptext'>Important traits for {}</span></div>\
3618-
<div class=\"content hidden\">",
3619-
trait_
3620-
),
3611+
"<span class=\"important-traits\"><span class=\"important-traits-tooltip\">ⓘ<div class='important-traits-tooltiptext'><span class=\"docblock\">"
3612+
36213613
);
3622-
out.push_str("</code></div></span>");
3614+
out.push_str("</code></span></div></span></span>");
36233615
}
36243616

36253617
out.into_inner()

src/librustdoc/html/static/main.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,28 +2639,13 @@ function defocusSearchBar() {
26392639
});
26402640
}());
26412641

2642-
function showModal(content) {
2643-
var modal = document.createElement("div");
2644-
modal.id = "important";
2645-
addClass(modal, "modal");
2646-
modal.innerHTML = "<div class=\"modal-content\"><div class=\"close\" id=\"modal-close\">✕" +
2647-
"</div><div class=\"whiter\"></div><span class=\"docblock\">" + content +
2648-
"</span></div>";
2649-
document.getElementsByTagName("body")[0].appendChild(modal);
2650-
document.getElementById("modal-close").onclick = hideModal;
2651-
modal.onclick = hideModal;
2652-
}
2653-
2654-
function hideModal() {
2655-
var modal = document.getElementById("important");
2656-
if (modal) {
2657-
modal.parentNode.removeChild(modal);
2658-
}
2642+
function showImportantTraits(content) {
2643+
let list = content.classList
26592644
}
26602645

26612646
onEachLazy(document.getElementsByClassName("important-traits"), function(e) {
26622647
e.onclick = function() {
2663-
showModal(e.lastElementChild.innerHTML);
2648+
e.getElementsByClassName('important-traits-tooltiptext')[0].classList.toggle("force-tooltip")
26642649
};
26652650
});
26662651

src/librustdoc/html/static/rustdoc.css

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,6 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
10821082
font-size: 16px;
10831083
}
10841084

1085-
.important-traits:hover .tooltiptext {
1086-
display: inline;
1087-
}
1088-
10891085
.tooltip .tooltiptext::after {
10901086
content: " ";
10911087
position: absolute;
@@ -1101,9 +1097,46 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
11011097
font-size: 20px;
11021098
}
11031099

1104-
.important-traits .tooltip .tooltiptext {
1105-
border: 1px solid;
1106-
font-weight: normal;
1100+
.important-traits-tooltip {
1101+
display: inline-block;
1102+
cursor: pointer;
1103+
}
1104+
1105+
.important-traits:hover .important-traits-tooltiptext,
1106+
.important-traits .important-traits-tooltiptext.force-tooltip {
1107+
display: inline-block;
1108+
}
1109+
1110+
.important-traits .important-traits-tooltiptext {
1111+
display: none;
1112+
padding: 5px 3px 3px 3px;
1113+
border-radius: 6px;
1114+
margin-left: 5px;
1115+
z-index: 10;
1116+
font-size: 16px;
1117+
cursor: default;
1118+
position: absolute;
1119+
/* Themes will override the color here,
1120+
but it's necessary to make it opaque */
1121+
background-color: #eee;
1122+
border: 1px solid #999;
1123+
}
1124+
1125+
.important-traits-tooltip::after {
1126+
/* The margin on the tooltip does not capture hover events,
1127+
this extends the area of hover enough so that mouse hover is not
1128+
lost when moving the mouse to the tooltip */
1129+
content: "\00a0\00a0\00a0";
1130+
}
1131+
1132+
.important-traits .important, .important-traits .docblock {
1133+
margin: 0;
1134+
}
1135+
1136+
.important-traits .docblock code.content{
1137+
margin: 0;
1138+
padding: 0;
1139+
font-size: 20px;
11071140
}
11081141

11091142
pre.rust {
@@ -1493,69 +1526,12 @@ h4 > .important-traits {
14931526
}
14941527
}
14951528

1496-
.modal {
1497-
position: fixed;
1498-
width: 100vw;
1499-
height: 100vh;
1500-
z-index: 10000;
1501-
top: 0;
1502-
left: 0;
1503-
}
1504-
1505-
.modal-content {
1506-
display: block;
1507-
max-width: 60%;
1508-
min-width: 200px;
1509-
padding: 8px;
1510-
top: 40%;
1511-
position: absolute;
1512-
left: 50%;
1513-
transform: translate(-50%, -40%);
1514-
border: 1px solid;
1515-
border-radius: 4px;
1516-
border-top-right-radius: 0;
1517-
}
1518-
1519-
.modal-content > .docblock {
1520-
margin: 0;
1521-
}
1522-
15231529
h3.important {
15241530
margin: 0;
15251531
margin-bottom: 13px;
15261532
font-size: 19px;
15271533
}
15281534

1529-
.modal-content > .docblock > code.content {
1530-
margin: 0;
1531-
padding: 0;
1532-
font-size: 20px;
1533-
}
1534-
1535-
.modal-content > .close {
1536-
position: absolute;
1537-
font-weight: 900;
1538-
right: -25px;
1539-
top: -1px;
1540-
font-size: 18px;
1541-
width: 25px;
1542-
padding-right: 2px;
1543-
border-top-right-radius: 5px;
1544-
border-bottom-right-radius: 5px;
1545-
text-align: center;
1546-
border: 1px solid;
1547-
border-right: 0;
1548-
cursor: pointer;
1549-
}
1550-
1551-
.modal-content > .whiter {
1552-
height: 25px;
1553-
position: absolute;
1554-
width: 3px;
1555-
right: -2px;
1556-
top: 0px;
1557-
}
1558-
15591535
kbd {
15601536
display: inline-block;
15611537
padding: 3px 5px;

src/librustdoc/html/static/themes/dark.css

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,9 @@ pre.ignore:hover, .information:hover + pre.ignore {
337337
border-color: transparent black transparent transparent;
338338
}
339339

340-
.important-traits .tooltip .tooltiptext {
341-
background-color: white;
342-
color: black;
343-
border-color: black;
340+
.important-traits-tooltiptext {
341+
background-color: #111 !important;
342+
border-color: #777 !important;
344343
}
345344

346345
#titles > div:not(.selected) {
@@ -356,33 +355,6 @@ pre.ignore:hover, .information:hover + pre.ignore {
356355
color: #888;
357356
}
358357

359-
.modal {
360-
background-color: rgba(0,0,0,0.3);
361-
}
362-
363-
.modal-content {
364-
background-color: #272727;
365-
border-color: #999;
366-
}
367-
368-
.modal-content > .close {
369-
background-color: #272727;
370-
border-color: #999;
371-
}
372-
373-
.modal-content > .close:hover {
374-
background-color: #ff1f1f;
375-
color: white;
376-
}
377-
378-
.modal-content > .whiter {
379-
background-color: #272727;
380-
}
381-
382-
.modal-content > .close:hover + .whiter {
383-
background-color: #ff1f1f;
384-
}
385-
386358
@media (max-width: 700px) {
387359
.sidebar-menu {
388360
background-color: #505050;

src/librustdoc/html/static/themes/light.css

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,9 @@ pre.ignore:hover, .information:hover + pre.ignore {
331331
border-color: transparent black transparent transparent;
332332
}
333333

334-
.important-traits .tooltip .tooltiptext {
335-
background-color: white;
336-
color: black;
337-
border-color: black;
334+
.important-traits-tooltiptext {
335+
background-color: #eee !important;
336+
border-color: #999 !important;
338337
}
339338

340339
#titles > div:not(.selected) {
@@ -350,33 +349,6 @@ pre.ignore:hover, .information:hover + pre.ignore {
350349
color: #888;
351350
}
352351

353-
.modal {
354-
background-color: rgba(0,0,0,0.3);
355-
}
356-
357-
.modal-content {
358-
background-color: #eee;
359-
border-color: #999;
360-
}
361-
362-
.modal-content > .close {
363-
background-color: #eee;
364-
border-color: #999;
365-
}
366-
367-
.modal-content > .close:hover {
368-
background-color: #ff1f1f;
369-
color: white;
370-
}
371-
372-
.modal-content > .whiter {
373-
background-color: #eee;
374-
}
375-
376-
.modal-content > .close:hover + .whiter {
377-
background-color: #ff1f1f;
378-
}
379-
380352
@media (max-width: 700px) {
381353
.sidebar-menu {
382354
background-color: #F1F1F1;

0 commit comments

Comments
 (0)