From b8c1726f267ce24b773f04c7d161c62f6fbc05fb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 2 Dec 2018 19:11:32 +0100 Subject: [PATCH] Show 'loading content' when loading content --- src/librustdoc/html/render.rs | 96 +++++++++++++----------------- src/librustdoc/html/static/main.js | 13 ++-- 2 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2ffd4dd7e57..b84fa7d581f 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3016,6 +3016,22 @@ fn item_trait( // Trait documentation document(w, cx, it)?; + fn write_small_section_header( + w: &mut fmt::Formatter, + id: &str, + title: &str, + extra_content: &str, + ) -> fmt::Result { + write!(w, " +

\ + {1}\ +

{2}", id, title, extra_content) + } + + fn write_loading_content(w: &mut fmt::Formatter, extra_content: &str) -> fmt::Result { + write!(w, "{}Loading content...", extra_content) + } + fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item) -> fmt::Result { let name = m.name.as_ref().unwrap(); @@ -3036,74 +3052,45 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean:: } if !types.is_empty() { - write!(w, " -

- Associated Types -

-
- ")?; + write_small_section_header(w, "associated-types", "Associated Types", + "
")?; for t in &types { trait_item(w, cx, *t, it)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; } if !consts.is_empty() { - write!(w, " -

- Associated Constants -

-
- ")?; + write_small_section_header(w, "associated-const", "Associated Constants", + "
")?; for t in &consts { trait_item(w, cx, *t, it)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; } // Output the documentation for each function individually if !required.is_empty() { - write!(w, " -

- Required Methods -

-
- ")?; + write_small_section_header(w, "required-methods", "Required methods", + "
")?; for m in &required { trait_item(w, cx, *m, it)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; } if !provided.is_empty() { - write!(w, " -

- Provided Methods -

-
- ")?; + write_small_section_header(w, "provided-methods", "Provided methods", + "
")?; for m in &provided { trait_item(w, cx, *m, it)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; } // If there are methods directly on this trait object, render them here. render_assoc_items(w, cx, it, it.def_id, AssocItemRender::All)?; let cache = cache(); - let impl_header = "\ -

\ - Implementors\ -

\ -
\ - "; - - let synthetic_impl_header = "\ -

\ - Auto implementors\ -

\ -
\ - "; let mut synthetic_types = Vec::new(); @@ -3140,11 +3127,7 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean:: concrete.sort_by(compare_impl); if !foreign.is_empty() { - write!(w, " -

- Implementations on Foreign Types -

- ")?; + write_small_section_header(w, "foreign-impls", "Implementations on Foreign Types", "")?; for implementor in foreign { let assoc_link = AssocItemLink::GotoSource( @@ -3155,33 +3138,38 @@ fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean:: RenderMode::Normal, implementor.impl_item.stable_since(), false, None)?; } + write_loading_content(w, "")?; } - write!(w, "{}", impl_header)?; + write_small_section_header(w, "implementors", "Implementors", + "
")?; for implementor in concrete { render_implementor(cx, implementor, w, &implementor_dups)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; if t.auto { - write!(w, "{}", synthetic_impl_header)?; + write_small_section_header(w, "synthetic-implementors", "Auto implementors", + "
")?; for implementor in synthetic { synthetic_types.extend( collect_paths_for_type(implementor.inner_impl().for_.clone()) ); render_implementor(cx, implementor, w, &implementor_dups)?; } - write!(w, "
")?; + write_loading_content(w, "
")?; } } else { // even without any implementations to write in, we still want the heading and list, so the // implementors javascript file pulled in below has somewhere to write the impls into - write!(w, "{}", impl_header)?; - write!(w, "")?; + write_small_section_header(w, "implementors", "Implementors", + "
")?; + write_loading_content(w, "
")?; if t.auto { - write!(w, "{}", synthetic_impl_header)?; - write!(w, "")?; + write_small_section_header(w, "synthetic-implementors", "Auto implementors", + "
")?; + write_loading_content(w, "
")?; } } write!(w, r#""#, diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 1348cd72b9d..51714c35d6f 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1961,7 +1961,7 @@ if (!DOMTokenList.prototype.remove) { } var relatedDoc; - var action; + var action = mode; if (hasClass(toggle.parentNode, "impl") === false) { relatedDoc = toggle.parentNode.nextElementSibling; if (hasClass(relatedDoc, "stability")) { @@ -1997,7 +1997,7 @@ if (!DOMTokenList.prototype.remove) { } if ((!relatedDoc && hasClass(docblock, "docblock") === false) || - (pageId && relatedDoc.getElementById(pageId))) { + (pageId && document.getElementById(pageId))) { return; } @@ -2026,7 +2026,7 @@ if (!DOMTokenList.prototype.remove) { } } - function collapser(e) { + function collapser(e, collapse) { // inherent impl ids are like "impl" or impl-'. // they will never be hidden by default. var n = e.parentElement; @@ -2045,7 +2045,9 @@ if (!DOMTokenList.prototype.remove) { var impl_list = document.getElementById("implementations-list"); if (impl_list !== null) { - onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), collapser); + onEachLazy(impl_list.getElementsByClassName("collapse-toggle"), function(e) { + collapser(e, collapse); + }); } } } @@ -2415,6 +2417,9 @@ if (!DOMTokenList.prototype.remove) { } if (main) { + onEachLazy(main.getElementsByClassName("loading-content"), function(e) { + e.remove(); + }); onEachLazy(main.childNodes, function(e) { if (e.tagName === "H2" || e.tagName === "H3") { e.nextElementSibling.style.display = "block";