diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs
index 583c9f2b67144..8e3989d33c13f 100644
--- a/src/librustdoc/html/layout.rs
+++ b/src/librustdoc/html/layout.rs
@@ -85,6 +85,9 @@ pub fn render(
autocomplete=\"off\" \
placeholder=\"Click or press ‘S’ to search, ‘?’ for more options…\" \
type=\"search\">\
+ \
\
\
\
@@ -181,9 +184,10 @@ pub fn render(
themes = themes.iter()
.filter_map(|t| t.file_stem())
.filter_map(|t| t.to_str())
- .map(|t| format!(r#""#,
+ .map(|t| format!(r#""#,
page.root_path,
- t.replace(".css", &format!("{}.css", page.resource_suffix))))
+ t,
+ page.resource_suffix))
.collect::(),
suffix=page.resource_suffix,
)
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 651319743aadd..698333b4e173c 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -742,6 +742,8 @@ fn write_shared(cx: &Context,
write(cx.dst.join(&format!("rustdoc{}.css", cx.shared.resource_suffix)),
include_bytes!("static/rustdoc.css"))?;
+ write(cx.dst.join(&format!("settings{}.css", cx.shared.resource_suffix)),
+ include_bytes!("static/settings.css"))?;
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
// then we'll run over the "official" styles.
@@ -761,6 +763,8 @@ fn write_shared(cx: &Context,
write(cx.dst.join(&format!("brush{}.svg", cx.shared.resource_suffix)),
include_bytes!("static/brush.svg"))?;
+ write(cx.dst.join(&format!("wheel{}.svg", cx.shared.resource_suffix)),
+ include_bytes!("static/wheel.svg"))?;
write(cx.dst.join(&format!("light{}.css", cx.shared.resource_suffix)),
include_bytes!("static/themes/light.css"))?;
themes.insert("light".to_owned());
@@ -794,8 +798,7 @@ themePicker.onclick = function() {{
switchTheme(currentTheme, mainTheme, item);
}};
themes.appendChild(but);
-}});
-"#,
+}});"#,
themes.iter()
.map(|s| format!("\"{}\"", s))
.collect::>()
@@ -804,6 +807,8 @@ themePicker.onclick = function() {{
write(cx.dst.join(&format!("main{}.js", cx.shared.resource_suffix)),
include_bytes!("static/main.js"))?;
+ write(cx.dst.join(&format!("settings{}.js", cx.shared.resource_suffix)),
+ include_bytes!("static/settings.js"))?;
{
let mut data = format!("var resourcesSuffix = \"{}\";\n",
@@ -1503,6 +1508,51 @@ impl fmt::Display for AllTypes {
}
}
+#[derive(Debug)]
+struct Settings<'a> {
+ // (id, explanation, default value)
+ settings: Vec<(&'static str, &'static str, bool)>,
+ root_path: &'a str,
+ suffix: &'a str,
+}
+
+impl<'a> Settings<'a> {
+ pub fn new(root_path: &'a str, suffix: &'a str) -> Settings<'a> {
+ Settings {
+ settings: vec![
+ ("item-declarations", "Auto-hide item declarations.", true),
+ ("item-attributes", "Auto-hide item attributes.", true),
+ ],
+ root_path,
+ suffix,
+ }
+ }
+}
+
+impl<'a> fmt::Display for Settings<'a> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f,
+"\
+ Rustdoc settings\
+
\
+{}
\
+",
+ self.settings.iter()
+ .map(|(id, text, enabled)| {
+ format!("\
+
\
+
{}
\
+
", id, if *enabled { " checked" } else { "" }, text)
+ })
+ .collect::(),
+ self.root_path,
+ self.suffix)
+ }
+}
+
impl Context {
/// String representation of how to get back to the root path of the 'doc/'
/// folder in terms of a relative URL.
@@ -1546,6 +1596,8 @@ impl Context {
};
let final_file = self.dst.join(&krate.name)
.join("all.html");
+ let settings_file = self.dst.join("settings.html");
+
let crate_name = krate.name.clone();
item.name = Some(krate.name);
@@ -1567,7 +1619,7 @@ impl Context {
if !root_path.ends_with('/') {
root_path.push('/');
}
- let page = layout::Page {
+ let mut page = layout::Page {
title: "List of all items in this crate",
css_class: "mod",
root_path: "../",
@@ -1590,6 +1642,27 @@ impl Context {
self.shared.css_file_extension.is_some(),
&self.shared.themes),
&final_file);
+
+ // Generating settings page.
+ let settings = Settings::new("./", &self.shared.resource_suffix);
+ page.title = "Rustdoc settings";
+ page.description = "Settings of Rustdoc";
+ page.root_path = "./";
+
+ let mut w = BufWriter::new(try_err!(File::create(&settings_file), &settings_file));
+ let mut themes = self.shared.themes.clone();
+ let sidebar = "Settings
";
+ themes.push(PathBuf::from("settings.css"));
+ let mut layout = self.shared.layout.clone();
+ layout.krate = String::new();
+ layout.logo = String::new();
+ layout.favicon = String::new();
+ try_err!(layout::render(&mut w, &layout,
+ &page, &sidebar, &settings,
+ self.shared.css_file_extension.is_some(),
+ &themes),
+ &settings_file);
+
Ok(())
}
diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index 2546a9410a9f6..1b47ec0ec025e 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -77,19 +77,13 @@
return false;
}
var end = start + className.length;
- if (end < elemClass.length && elemClass[end] !== ' ') {
- return false;
- }
- return true;
+ return !(end < elemClass.length && elemClass[end] !== ' ');
}
if (start > 0 && elemClass[start - 1] !== ' ') {
return false;
}
var end = start + className.length;
- if (end < elemClass.length && elemClass[end] !== ' ') {
- return false;
- }
- return true;
+ return !(end < elemClass.length && elemClass[end] !== ' ');
}
return false;
}
@@ -320,7 +314,7 @@
} else if (ev.target.tagName === 'SPAN' && hasClass(ev.target.parentNode, 'line-numbers')) {
var prev_id = 0;
- var set_fragment = function (name) {
+ var set_fragment = function(name) {
if (browserSupportsHistoryApi()) {
history.replaceState(null, null, '#' + name);
window.hashchange();
@@ -835,7 +829,7 @@
query.search = val;
// searching by type
} else if (val.search("->") > -1) {
- var trimmer = function (s) { return s.trim(); };
+ var trimmer = function(s) { return s.trim(); };
var parts = val.split("->").map(trimmer);
var input = parts[0];
// sort inputs so that order does not matter
@@ -1547,7 +1541,7 @@
startSearch();
// Draw a convenient sidebar of known crates if we have a listing
- if (rootPath === '../') {
+ if (rootPath === '../' || rootPath === "./") {
var sidebar = document.getElementsByClassName('sidebar-elems')[0];
if (sidebar) {
var div = document.createElement('div');
@@ -1566,11 +1560,11 @@
crates.sort();
for (var i = 0; i < crates.length; ++i) {
var klass = 'crate';
- if (crates[i] === window.currentCrate) {
+ if (rootPath !== "./" && crates[i] === window.currentCrate) {
klass += ' current';
}
var link = document.createElement('a');
- link.href = '../' + crates[i] + '/index.html';
+ link.href = rootPath + crates[i] + '/index.html';
link.title = rawSearchIndex[crates[i]].doc;
link.className = klass;
link.textContent = crates[i];
@@ -1947,7 +1941,7 @@
otherMessage = ' Show type declaration';
}
e.parentNode.insertBefore(createToggle(otherMessage), e);
- if (otherMessage) {
+ if (otherMessage && getCurrentValue('rustdoc-item-declarations') !== "false") {
collapseDocs(e.previousSibling.childNodes[0], "toggle");
}
}
@@ -2017,7 +2011,9 @@
onEach(document.getElementById('main').getElementsByTagName('pre'), function(e) {
onEach(e.getElementsByClassName('attributes'), function(i_e) {
i_e.parentNode.insertBefore(createToggleWrapper(), i_e);
- collapseDocs(i_e.previousSibling.childNodes[0], "toggle");
+ if (getCurrentValue("rustdoc-item-attributes") !== "false") {
+ collapseDocs(i_e.previousSibling.childNodes[0], "toggle");
+ }
});
});
diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css
index 4c6c8dcfddafc..d6b3ab26af8ae 100644
--- a/src/librustdoc/html/static/rustdoc.css
+++ b/src/librustdoc/html/static/rustdoc.css
@@ -548,8 +548,16 @@ a {
.block a.current.crate { font-weight: 500; }
+.search-container {
+ position: relative;
+}
+.search-container > .top-button {
+ position: absolute;
+ right: 0;
+ top: 10px;
+}
.search-input {
- width: 100%;
+ width: calc(100% - 34px);
/* Override Normalize.css: we have margins and do
not want to overflow - the `moz` attribute is necessary
until Firefox 29, too early to drop at this point */
@@ -1224,7 +1232,14 @@ kbd {
outline: none;
}
-#theme-picker {
+#settings-menu {
+ position: absolute;
+ right: 0;
+ top: 10px;
+ outline: none;
+}
+
+#theme-picker, #settings-menu {
padding: 4px;
width: 27px;
height: 29px;
diff --git a/src/librustdoc/html/static/settings.css b/src/librustdoc/html/static/settings.css
new file mode 100644
index 0000000000000..34835f3f22d57
--- /dev/null
+++ b/src/librustdoc/html/static/settings.css
@@ -0,0 +1,73 @@
+/**
+ * Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+ * file at the top-level directory of this distribution and at
+ * http://rust-lang.org/COPYRIGHT.
+ *
+ * Licensed under the Apache License, Version 2.0 or the MIT license
+ * , at your
+ * option. This file may not be copied, modified, or distributed
+ * except according to those terms.
+ */
+
+.setting-line {
+ padding: 5px;
+}
+
+.setting-line > div {
+ max-width: calc(100% - 74px);
+ display: inline-block;
+ vertical-align: top;
+ font-size: 17px;
+ padding-top: 2px;
+}
+
+.toggle {
+ position: relative;
+ display: inline-block;
+ width: 45px;
+ height: 27px;
+ margin-right: 20px;
+}
+
+.toggle input {
+ display: none;
+}
+
+.slider {
+ position: absolute;
+ cursor: pointer;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background-color: #ccc;
+ -webkit-transition: .3s;
+ transition: .3s;
+}
+
+.slider:before {
+ position: absolute;
+ content: "";
+ height: 19px;
+ width: 19px;
+ left: 4px;
+ bottom: 4px;
+ background-color: white;
+ -webkit-transition: .3s;
+ transition: .3s;
+}
+
+input:checked + .slider {
+ background-color: #2196F3;
+}
+
+input:focus + .slider {
+ box-shadow: 0 0 1px #2196F3;
+}
+
+input:checked + .slider:before {
+ -webkit-transform: translateX(19px);
+ -ms-transform: translateX(19px);
+ transform: translateX(19px);
+}
\ No newline at end of file
diff --git a/src/librustdoc/html/static/settings.js b/src/librustdoc/html/static/settings.js
new file mode 100644
index 0000000000000..cc7c60082fb41
--- /dev/null
+++ b/src/librustdoc/html/static/settings.js
@@ -0,0 +1,41 @@
+/*!
+ * Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+ * file at the top-level directory of this distribution and at
+ * http://rust-lang.org/COPYRIGHT.
+ *
+ * Licensed under the Apache License, Version 2.0 or the MIT license
+ * , at your
+ * option. This file may not be copied, modified, or distributed
+ * except according to those terms.
+ */
+
+(function () {
+ function changeSetting(settingName, isEnabled) {
+ updateLocalStorage('rustdoc-' + settingName, isEnabled);
+ }
+
+ function getSettingValue(settingName) {
+ return getCurrentValue('rustdoc-' + settingName);
+ }
+
+ function setEvents() {
+ var elems = document.getElementsByClassName("slider");
+ if (!elems || elems.length === 0) {
+ return;
+ }
+ for (var i = 0; i < elems.length; ++i) {
+ var toggle = elems[i].previousElementSibling;
+ var settingId = toggle.id;
+ var settingValue = getSettingValue(settingId);
+ if (settingValue !== null) {
+ toggle.checked = settingValue === "true";
+ }
+ toggle.onchange = function() {
+ changeSetting(this.id, this.checked);
+ };
+ }
+ }
+
+ setEvents();
+})();
diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css
index 93971a205bf35..da4be7db5aa92 100644
--- a/src/librustdoc/html/static/themes/dark.css
+++ b/src/librustdoc/html/static/themes/dark.css
@@ -362,12 +362,13 @@ kbd {
box-shadow-color: #c6cbd1;
}
-#theme-picker {
+#theme-picker, #settings-menu {
border-color: #e0e0e0;
background: #f0f0f0;
}
-#theme-picker:hover, #theme-picker:focus {
+#theme-picker:hover, #theme-picker:focus,
+#settings-menu:hover, #settings-menu:focus {
border-color: #ffb900;
}
diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css
index e13818b4bd278..12af01d2e2498 100644
--- a/src/librustdoc/html/static/themes/light.css
+++ b/src/librustdoc/html/static/themes/light.css
@@ -356,12 +356,13 @@ kbd {
box-shadow-color: #c6cbd1;
}
-#theme-picker {
+#theme-picker, #settings-menu {
border-color: #e0e0e0;
background-color: #fff;
}
-#theme-picker:hover, #theme-picker:focus {
+#theme-picker:hover, #theme-picker:focus,
+#settings-menu:hover, #settings-menu:focus {
border-color: #717171;
}
diff --git a/src/librustdoc/html/static/wheel.svg b/src/librustdoc/html/static/wheel.svg
new file mode 100644
index 0000000000000..44381a401a82f
--- /dev/null
+++ b/src/librustdoc/html/static/wheel.svg
@@ -0,0 +1 @@
+
\ No newline at end of file