Skip to content

Commit 91ef960

Browse files
reduce size of generated HTML files by moving the popup helper code to the JS
1 parent 1d28083 commit 91ef960

File tree

2 files changed

+47
-55
lines changed

2 files changed

+47
-55
lines changed

src/librustdoc/html/layout.rs

-55
Original file line numberDiff line numberDiff line change
@@ -106,61 +106,6 @@ pub fn render<T: Print, S: Print>(
106106
<section id=\"main\" class=\"content\">{content}</section>\
107107
<section id=\"search\" class=\"content hidden\"></section>\
108108
<section class=\"footer\"></section>\
109-
<aside id=\"help\" class=\"hidden\">\
110-
<div>\
111-
<h1 class=\"hidden\">Help</h1>\
112-
<div class=\"shortcuts\">\
113-
<h2>Keyboard Shortcuts</h2>\
114-
<dl>\
115-
<dt><kbd>?</kbd></dt>\
116-
<dd>Show this help dialog</dd>\
117-
<dt><kbd>S</kbd></dt>\
118-
<dd>Focus the search field</dd>\
119-
<dt><kbd>↑</kbd></dt>\
120-
<dd>Move up in search results</dd>\
121-
<dt><kbd>↓</kbd></dt>\
122-
<dd>Move down in search results</dd>\
123-
<dt><kbd>↹</kbd></dt>\
124-
<dd>Switch tab</dd>\
125-
<dt><kbd>&#9166;</kbd></dt>\
126-
<dd>Go to active search result</dd>\
127-
<dt><kbd>+</kbd></dt>\
128-
<dd>Expand all sections</dd>\
129-
<dt><kbd>-</kbd></dt>\
130-
<dd>Collapse all sections</dd>\
131-
</dl>\
132-
</div>\
133-
<div class=\"infos\">\
134-
<h2>Search Tricks</h2>\
135-
<p>\
136-
Prefix searches with a type followed by a colon (e.g., \
137-
<code>fn:</code>) to restrict the search to a given type.\
138-
</p>\
139-
<p>\
140-
Accepted types are: <code>fn</code>, <code>mod</code>, \
141-
<code>struct</code>, <code>enum</code>, \
142-
<code>trait</code>, <code>type</code>, <code>macro</code>, \
143-
and <code>const</code>.\
144-
</p>\
145-
<p>\
146-
Search functions by type signature (e.g., \
147-
<code>vec -> usize</code> or <code>* -> vec</code>)\
148-
</p>\
149-
<p>\
150-
Search multiple things at once by splitting your query with comma (e.g., \
151-
<code>str,u8</code> or <code>String,struct:Vec,test</code>)\
152-
</p>\
153-
<p>\
154-
You can look for items with an exact name by putting double quotes around \
155-
your request: <code>\"string\"</code>\
156-
</p>\
157-
<p>\
158-
Look for items inside another one by searching for a path: \
159-
<code>vec::Vec</code>\
160-
</p>\
161-
</div>\
162-
</div>\
163-
</aside>\
164109
{after_content}\
165110
<script>\
166111
window.rootPath = \"{root_path}\";\

src/librustdoc/html/static/main.js

+47
Original file line numberDiff line numberDiff line change
@@ -2553,6 +2553,53 @@ function getSearchElement() {
25532553
}
25542554

25552555
window.addSearchOptions = addSearchOptions;
2556+
2557+
function buildHelperPopup() {
2558+
var popup = document.createElement("aside");
2559+
addClass(popup, "hidden");
2560+
popup.id = "help";
2561+
2562+
var container = document.createElement("div");
2563+
var shortcuts = [
2564+
["?", "Show this help dialog"],
2565+
["S", "Focus the search field"],
2566+
["↑", "Move up in search results"],
2567+
["↓", "Move down in search results"],
2568+
["↹", "Switch tab"],
2569+
["&#9166;", "Go to active search result"],
2570+
["+", "Expand all sections"],
2571+
["-", "Collapse all sections"],
2572+
].map(x => "<dt><kbd>" + x[0] + "</kbd></dt><dd>" + x[1] + "</dd>").join("");
2573+
var div_shortcuts = document.createElement("div");
2574+
addClass(div_shortcuts, "shortcuts");
2575+
div_shortcuts.innerHTML = "<h2>Keyboard Shortcuts</h2><dl>" + shortcuts + "</dl></div>";
2576+
2577+
var infos = [
2578+
"Prefix searches with a type followed by a colon (e.g., <code>fn:</code>) to \
2579+
restrict the search to a given type.",
2580+
"Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, \
2581+
<code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, \
2582+
and <code>const</code>.",
2583+
"Search functions by type signature (e.g., <code>vec -> usize</code> or \
2584+
<code>* -> vec</code>)",
2585+
"Search multiple things at once by splitting your query with comma (e.g., \
2586+
<code>str,u8</code> or <code>String,struct:Vec,test</code>)",
2587+
"You can look for items with an exact name by putting double quotes around \
2588+
your request: <code>\"string\"</code>",
2589+
"Look for items inside another one by searching for a path: <code>vec::Vec</code>",
2590+
].map(x => "<p>" + x + "</p>").join("");
2591+
var div_infos = document.createElement("div");
2592+
addClass(div_infos, "infos");
2593+
div_infos.innerHTML = "<h2>Search Tricks</h2>" + infos;
2594+
2595+
container.appendChild(div_shortcuts);
2596+
container.appendChild(div_infos);
2597+
2598+
popup.appendChild(container);
2599+
insertAfter(popup, getSearchElement());
2600+
}
2601+
2602+
buildHelperPopup();
25562603
}());
25572604

25582605
// Sets the focus on the search bar at the top of the page

0 commit comments

Comments
 (0)