Skip to content

Commit b65fa84

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 f2b7e83 commit b65fa84

File tree

5 files changed

+52
-151
lines changed

5 files changed

+52
-151
lines changed

src/librustdoc/html/render.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -3604,14 +3604,10 @@ fn spotlight_decl(decl: &clean::FnDecl) -> String {
36043604
if !out.is_empty() {
36053605
out.insert_str(
36063606
0,
3607-
&format!(
3608-
"<span class=\"important-traits\"><div class='tooltip'>ⓘ\
3609-
<span class='tooltiptext'>Important traits for {}</span></div>\
3610-
<div class=\"content hidden\">",
3611-
trait_
3612-
),
3607+
"<span class=\"important-traits\"><span class=\"important-traits-tooltip\">ⓘ<div class='important-traits-tooltiptext'><span class=\"docblock\">"
3608+
36133609
);
3614-
out.push_str("</code></div></span>");
3610+
out.push_str("</code></span></div></span></span>");
36153611
}
36163612

36173613
out.into_inner()

src/librustdoc/html/static/main.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -2624,28 +2624,13 @@ function defocusSearchBar() {
26242624
});
26252625
}());
26262626

2627-
function showModal(content) {
2628-
var modal = document.createElement("div");
2629-
modal.id = "important";
2630-
addClass(modal, "modal");
2631-
modal.innerHTML = "<div class=\"modal-content\"><div class=\"close\" id=\"modal-close\">✕" +
2632-
"</div><div class=\"whiter\"></div><span class=\"docblock\">" + content +
2633-
"</span></div>";
2634-
document.getElementsByTagName("body")[0].appendChild(modal);
2635-
document.getElementById("modal-close").onclick = hideModal;
2636-
modal.onclick = hideModal;
2637-
}
2638-
2639-
function hideModal() {
2640-
var modal = document.getElementById("important");
2641-
if (modal) {
2642-
modal.parentNode.removeChild(modal);
2643-
}
2627+
function showImportantTraits(content) {
2628+
let list = content.classList
26442629
}
26452630

26462631
onEachLazy(document.getElementsByClassName("important-traits"), function(e) {
26472632
e.onclick = function() {
2648-
showModal(e.lastElementChild.innerHTML);
2633+
e.getElementsByClassName('important-traits-tooltiptext')[0].classList.toggle("force-tooltip")
26492634
};
26502635
});
26512636

src/librustdoc/html/static/rustdoc.css

+40-64
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,6 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
10781078
font-size: 16px;
10791079
}
10801080

1081-
.important-traits:hover .tooltiptext {
1082-
display: inline;
1083-
}
1084-
10851081
.tooltip .tooltiptext::after {
10861082
content: " ";
10871083
position: absolute;
@@ -1097,9 +1093,46 @@ h3 > .collapse-toggle, h4 > .collapse-toggle {
10971093
font-size: 20px;
10981094
}
10991095

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

11051138
pre.rust {
@@ -1489,69 +1522,12 @@ h4 > .important-traits {
14891522
}
14901523
}
14911524

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

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

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

+3-31
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

+3-31
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)