Skip to content

Commit 85dcf2e

Browse files
Improve modal display and add JS events
1 parent aca1bd7 commit 85dcf2e

File tree

3 files changed

+89
-18
lines changed

3 files changed

+89
-18
lines changed

src/librustdoc/html/render.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -2266,15 +2266,10 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22662266
AbiSpace(f.abi),
22672267
it.name.as_ref().unwrap(),
22682268
f.generics).len();
2269-
let mut extra = render_spotlight_traits(it)?;
2270-
if !extra.is_empty() {
2271-
extra.insert_str(0, "<div class=\"important-traits\">ⓘ<div class=\"content hidden\">");
2272-
extra.push_str("</div></div>");
2273-
};
2274-
write!(w, "<pre class='rust fn'>")?;
2269+
write!(w, "{}<pre class='rust fn'>", render_spotlight_traits(it)?)?;
22752270
render_attributes(w, it)?;
22762271
write!(w, "{vis}{constness}{unsafety}{abi}fn \
2277-
{name}{generics}{decl}{where_clause}</pre>{extra}",
2272+
{name}{generics}{decl}{where_clause}</pre>",
22782273
vis = VisSpace(&it.visibility),
22792274
constness = ConstnessSpace(f.constness),
22802275
unsafety = UnsafetySpace(f.unsafety),
@@ -2286,8 +2281,7 @@ fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22862281
decl: &f.decl,
22872282
name_len,
22882283
indent: 0,
2289-
},
2290-
extra = extra)?;
2284+
})?;
22912285
document(w, cx, it)
22922286
}
22932287

@@ -3269,8 +3263,9 @@ fn spotlight_decl(decl: &clean::FnDecl) -> Result<String, fmt::Error> {
32693263
if impl_.trait_.def_id().and_then(|d| c.traits.get(&d))
32703264
.map_or(false, |t| t.is_spotlight) {
32713265
if out.is_empty() {
3272-
out.push_str("<span class=\"docblock autohide\">");
3273-
out.push_str(&format!("<h3>Important traits for {}</h3>", impl_.for_));
3266+
out.push_str(
3267+
&format!("<h3 class=\"important\">Important traits for {}</h3>",
3268+
impl_.for_));
32743269
out.push_str("<code class=\"content\">");
32753270
}
32763271

src/librustdoc/html/static/main.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
var help = document.getElementById("help");
216216
switch (getVirtualKey(ev)) {
217217
case "Escape":
218+
hideModal();
218219
var search = document.getElementById("search");
219220
if (!hasClass(help, "hidden")) {
220221
displayHelp(false, ev);
@@ -228,6 +229,7 @@
228229
case "s":
229230
case "S":
230231
displayHelp(false, ev);
232+
hideModal();
231233
ev.preventDefault();
232234
focusSearchBar();
233235
break;
@@ -240,6 +242,7 @@
240242

241243
case "?":
242244
if (ev.shiftKey) {
245+
hideModal();
243246
displayHelp(true, ev);
244247
}
245248
break;
@@ -1715,9 +1718,21 @@
17151718

17161719
function showModal(content) {
17171720
var modal = document.createElement('div');
1721+
modal.id = "important";
17181722
addClass(modal, 'modal');
1719-
modal.innerHTML = '<div class="modal-content">' + content + "</div>";
1723+
modal.innerHTML = '<div class="modal-content"><div class="close" id="modal-close">✕</div>' +
1724+
'<div class="whiter"></div><span class="docblock">' + content +
1725+
'</span></div>';
17201726
document.getElementsByTagName('body')[0].appendChild(modal);
1727+
document.getElementById('modal-close').onclick = hideModal;
1728+
modal.onclick = hideModal;
1729+
}
1730+
1731+
function hideModal() {
1732+
var modal = document.getElementById("important");
1733+
if (modal) {
1734+
modal.parentNode.removeChild(modal);
1735+
}
17211736
}
17221737

17231738
onEach(document.getElementsByClassName('important-traits'), function(e) {

src/librustdoc/html/static/rustdoc.css

+67-6
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ h2 {
8989
h3 {
9090
font-size: 1.3em;
9191
}
92-
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
92+
h1, h2, h3:not(.impl):not(.method):not(.type):not(.tymethod):not(.important), h4:not(.method):not(.type):not(.tymethod):not(.associatedconstant) {
9393
font-weight: 500;
9494
margin: 20px 0 15px 0;
9595
padding-bottom: 6px;
@@ -955,11 +955,14 @@ pre.rust {
955955
font-size: 16px;
956956
}
957957

958+
.important-traits {
959+
cursor: pointer;
960+
}
961+
958962
h4 > .important-traits {
959963
position: absolute;
960964
left: -44px;
961965
top: 2px;
962-
cursor: pointer;
963966
}
964967

965968
.modal {
@@ -976,12 +979,70 @@ h4 > .important-traits {
976979
display: block;
977980
max-width: 60%;
978981
min-width: 200px;
979-
background-color: white;
980-
padding: 5px;
981-
top: 10%;
982+
background-color: #eee;
983+
padding: 8px;
984+
top: 40%;
982985
position: absolute;
983986
left: 50%;
984-
transform: translate(-50%, -50%);
987+
transform: translate(-50%, -40%);
985988
border: 1px solid #999;
986989
border-radius: 4px;
990+
border-top-right-radius: 0;
991+
}
992+
993+
.modal-content > .docblock {
994+
margin: 0;
995+
}
996+
997+
h3.important {
998+
margin: 0;
999+
margin-bottom: 13px;
1000+
font-size: 19px;
1001+
}
1002+
1003+
.modal-content > .docblock > code.content {
1004+
margin: 0;
1005+
padding: 0;
1006+
font-size: 20px;
1007+
}
1008+
1009+
.modal-content > .close {
1010+
position: absolute;
1011+
font-weight: 900;
1012+
right: -25px;
1013+
top: -1px;
1014+
font-size: 18px;
1015+
background-color: #eee;
1016+
width: 25px;
1017+
padding-right: 2px;
1018+
border-top-right-radius: 5px;
1019+
border-bottom-right-radius: 5px;
1020+
text-align: center;
1021+
border: 1px solid #999;
1022+
border-right: 0;
1023+
cursor: pointer;
1024+
}
1025+
1026+
.modal-content > .close:hover {
1027+
background-color: #ff1f1f;
1028+
color: white;
1029+
}
1030+
1031+
.modal-content > .whiter {
1032+
height: 25px;
1033+
position: absolute;
1034+
width: 3px;
1035+
background-color: #eee;
1036+
right: -2px;
1037+
top: 0px;
1038+
}
1039+
1040+
.modal-content > .close:hover + .whiter {
1041+
background-color: #ff1f1f;
1042+
}
1043+
1044+
#main > div.important-traits {
1045+
position: absolute;
1046+
left: -24px;
1047+
margin-top: 16px;
9871048
}

0 commit comments

Comments
 (0)