rustdoc: remove mobile topbar from source pages instead of hiding it
This commit is contained in:
parent
bba9785dd7
commit
d2e14e2d11
4 changed files with 11 additions and 11 deletions
|
@ -1807,10 +1807,6 @@ in storage.js plus the media query with (min-width: 701px)
|
||||||
top: 0;
|
top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.source .mobile-topbar {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-toggle {
|
.sidebar-menu-toggle {
|
||||||
width: 45px;
|
width: 45px;
|
||||||
/* Rare exception to specifying font sizes in rem. Since this is acting
|
/* Rare exception to specifying font sizes in rem. Since this is acting
|
||||||
|
|
|
@ -735,14 +735,15 @@ function loadCss(cssFileName) {
|
||||||
let oldSidebarScrollPosition = null;
|
let oldSidebarScrollPosition = null;
|
||||||
|
|
||||||
function showSidebar() {
|
function showSidebar() {
|
||||||
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT) {
|
const mobile_topbar = document.querySelector(".mobile-topbar");
|
||||||
|
if (window.innerWidth < window.RUSTDOC_MOBILE_BREAKPOINT && mobile_topbar) {
|
||||||
// This is to keep the scroll position on mobile.
|
// This is to keep the scroll position on mobile.
|
||||||
oldSidebarScrollPosition = window.scrollY;
|
oldSidebarScrollPosition = window.scrollY;
|
||||||
document.body.style.width = `${document.body.offsetWidth}px`;
|
document.body.style.width = `${document.body.offsetWidth}px`;
|
||||||
document.body.style.position = "fixed";
|
document.body.style.position = "fixed";
|
||||||
document.body.style.top = `-${oldSidebarScrollPosition}px`;
|
document.body.style.top = `-${oldSidebarScrollPosition}px`;
|
||||||
document.querySelector(".mobile-topbar").style.top = `${oldSidebarScrollPosition}px`;
|
mobile_topbar.style.top = `${oldSidebarScrollPosition}px`;
|
||||||
document.querySelector(".mobile-topbar").style.position = "relative";
|
mobile_topbar.style.position = "relative";
|
||||||
} else {
|
} else {
|
||||||
oldSidebarScrollPosition = null;
|
oldSidebarScrollPosition = null;
|
||||||
}
|
}
|
||||||
|
@ -751,13 +752,14 @@ function loadCss(cssFileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function hideSidebar() {
|
function hideSidebar() {
|
||||||
if (oldSidebarScrollPosition !== null) {
|
const mobile_topbar = document.querySelector(".mobile-topbar");
|
||||||
|
if (oldSidebarScrollPosition !== null && mobile_topbar) {
|
||||||
// This is to keep the scroll position on mobile.
|
// This is to keep the scroll position on mobile.
|
||||||
document.body.style.width = "";
|
document.body.style.width = "";
|
||||||
document.body.style.position = "";
|
document.body.style.position = "";
|
||||||
document.body.style.top = "";
|
document.body.style.top = "";
|
||||||
document.querySelector(".mobile-topbar").style.top = "";
|
mobile_topbar.style.top = "";
|
||||||
document.querySelector(".mobile-topbar").style.position = "";
|
mobile_topbar.style.position = "";
|
||||||
// The scroll position is lost when resetting the style, hence why we store it in
|
// The scroll position is lost when resetting the style, hence why we store it in
|
||||||
// `oldSidebarScrollPosition`.
|
// `oldSidebarScrollPosition`.
|
||||||
window.scrollTo(0, oldSidebarScrollPosition);
|
window.scrollTo(0, oldSidebarScrollPosition);
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
</div> {#- -#}
|
</div> {#- -#}
|
||||||
<![endif]--> {#- -#}
|
<![endif]--> {#- -#}
|
||||||
{{- layout.external_html.before_content|safe -}}
|
{{- layout.external_html.before_content|safe -}}
|
||||||
|
{%- if page.css_class != "source" -%}
|
||||||
<nav class="mobile-topbar"> {#- -#}
|
<nav class="mobile-topbar"> {#- -#}
|
||||||
<button class="sidebar-menu-toggle">☰</button> {#- -#}
|
<button class="sidebar-menu-toggle">☰</button> {#- -#}
|
||||||
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
|
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
|
||||||
|
@ -86,6 +87,7 @@
|
||||||
</a> {#- -#}
|
</a> {#- -#}
|
||||||
<h2 class="location"></h2> {#- -#}
|
<h2 class="location"></h2> {#- -#}
|
||||||
</nav> {#- -#}
|
</nav> {#- -#}
|
||||||
|
{%- endif -%}
|
||||||
<nav class="sidebar"> {#- -#}
|
<nav class="sidebar"> {#- -#}
|
||||||
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
|
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
|
||||||
<div class="logo-container"> {#- -#}
|
<div class="logo-container"> {#- -#}
|
||||||
|
|
|
@ -42,4 +42,4 @@ assert-false: ".source-sidebar-expanded"
|
||||||
assert: "nav.sidebar"
|
assert: "nav.sidebar"
|
||||||
|
|
||||||
// Check that the topbar is not visible
|
// Check that the topbar is not visible
|
||||||
assert-property: (".mobile-topbar", {"offsetParent": "null"})
|
assert-false: ".mobile-topbar"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue