From 91ef9600db47e4e91a57909077a60ebec1122d1b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 25 Oct 2019 00:35:45 +0200 Subject: reduce size of generated HTML files by moving the popup helper code to the JS --- src/librustdoc/html/static/main.js | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/librustdoc/html/static') diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index d321307b2e0..c896660f537 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -2553,6 +2553,53 @@ function getSearchElement() { } window.addSearchOptions = addSearchOptions; + + function buildHelperPopup() { + var popup = document.createElement("aside"); + addClass(popup, "hidden"); + popup.id = "help"; + + var container = document.createElement("div"); + var shortcuts = [ + ["?", "Show this help dialog"], + ["S", "Focus the search field"], + ["↑", "Move up in search results"], + ["↓", "Move down in search results"], + ["↹", "Switch tab"], + ["⏎", "Go to active search result"], + ["+", "Expand all sections"], + ["-", "Collapse all sections"], + ].map(x => "
" + x[0] + "
" + x[1] + "
").join(""); + var div_shortcuts = document.createElement("div"); + addClass(div_shortcuts, "shortcuts"); + div_shortcuts.innerHTML = "

Keyboard Shortcuts

" + shortcuts + "
"; + + var infos = [ + "Prefix searches with a type followed by a colon (e.g., fn:) to \ + restrict the search to a given type.", + "Accepted types are: fn, mod, struct, \ + enum, trait, type, macro, \ + and const.", + "Search functions by type signature (e.g., vec -> usize or \ + * -> vec)", + "Search multiple things at once by splitting your query with comma (e.g., \ + str,u8 or String,struct:Vec,test)", + "You can look for items with an exact name by putting double quotes around \ + your request: \"string\"", + "Look for items inside another one by searching for a path: vec::Vec", + ].map(x => "

" + x + "

").join(""); + var div_infos = document.createElement("div"); + addClass(div_infos, "infos"); + div_infos.innerHTML = "

Search Tricks

" + infos; + + container.appendChild(div_shortcuts); + container.appendChild(div_infos); + + popup.appendChild(container); + insertAfter(popup, getSearchElement()); + } + + buildHelperPopup(); }()); // Sets the focus on the search bar at the top of the page -- cgit 1.4.1-3-g733a5