-
Notifications
You must be signed in to change notification settings - Fork 13.3k
make the book more mobile friendly #21071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
Can you host a build for review? |
}; | ||
}); | ||
</script> | ||
"#; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an... interesting... approach. I feel like reading from a file proper would make more sense, but I'll admit I'm new to this specific codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I borrowed using a module from the way the CSS is implemented:
https://github.com/rust-lang/rust/blob/master/src/rustbook/css.rs
I agree it is an "interesting" approach, but since it's my first pull request I tried to stick to what I thought was convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aturon what's up with this? Quick hack or something you stand by?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have zero recollection of this -- I suspect it was borrowed from rustdoc. In any case, all of rustbook is a very quick hack and I'm happy for it to be improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aturon Where is the authoritative rustbook source? https://github.com/rust-lang/rust/tree/master/src/rustbook or https://github.com/aturon/rust-book?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're trying to move to
https://github.com/rust-lang/rust/tree/master/src/rustbook
On Tue, Jan 13, 2015 at 10:22 AM, Seth Faxon [email protected]
wrote:
In src/rustbook/javascript.rs
#21071 (diff):+document.addEventListener("DOMContentLoaded", function(event) {
- document.getElementById("toggle-nav").onclick = toggleNav;
- function toggleNav() {
- var toc = document.getElementById("toc");
- var pagewrapper = document.getElementById("page-wrapper");
- if ( "block" === toc.style.display ) {
toc.style.display = "none";
pagewrapper.style.display = "block";
- } else {
toc.style.display = "block";
pagewrapper.style.display = "none";
- }
- };
+});
+</script>
+"#;@aturon https://github.com/aturon Where is the authoritative rustbook
source? https://github.com/rust-lang/rust/tree/master/src/rustbook or
https://github.com/aturon/rust-book?—
Reply to this email directly or view it on GitHub
https://github.com/rust-lang/rust/pull/21071/files#r22882104.
Sorry, not sure what you mean by "host a build for review." |
Build the docs with these changes, and host them on the internet for us to poke at. |
It's fairly hard to review some CSS/JS tweaks in isolation like this. |
Of course, I'm serving the generated Rust Book here: http://home.faxon.org/book/index.html. It's my best guess at replicating what http://doc.rust-lang.org/book/ is doing. When the window size goes below 1060px it will switch to a mobile view and provides a button in the upper left to toggle showing the table of contents. The div that contains the toggle button is always there. If we want it to go away I would probably want to use a .js library. I'm happy to make that change as well, but I would want whoever is currently managing the docs site to weigh in on that. I've tested on Android, iOS, Firefox, Safai, Chrome (Mac) and the latest IE. It behaves the same, just let me know if the behavior is desired :) |
I think the padding is a bit much for the <1060 view. I'm not an expert, but my understanding is that you basically want no padding for mobile. |
I think you can do some magix with css classes to get the hamburger to always do the right thing on mobile/desktop:
This should make the hamburger only visible when the display is small, and only have effects when the view is large. As it stands now, it unreversible makes only one of the TOC and content visible, even when the view is made large again. |
Also is the 1060 value based on anything (some kind of hardware/layout standard?) or just eyeballed as "looks good"? |
You are correct, a 15px padding would be better for the margins on mobile. I'll make that change. The CSS is using media query to toggle showing the hamburger. You should only see the hamburger when the table of contents is hidden in condensed mode. Pressing the hamburger toggle does get into a toggle mode that does not leave when the browser expands. I collapsed the table at 1060px because the existing copy width was set to 750px and the table of contents at 250px. Those widths plus margins = 1060px. And eyeballed as looks good :). Most frameworks collapse around 1000px for a tablet version and again somewhere around 600 or 700px. Since the Rust Book is mostly code in pre elements I wanted to lean towards hiding the nav on tablet to give longer lines of code room to be seen without sidescrolling. |
I might be missing something, but I'm pretty sure that the only JS you need is to toggle a single class onclick. Everything else should be reasonably handled by CSS. e.g.
and
|
@gankro I've update the pull request to toggle a class in order to hide the div, as you laid out. I think the issue I was having was related to setting display none in CSS on an ID rather than on a class. I also updated the page margin to be 15px on mobile. The code on http://home.faxon.org/book/ reflects the changes as well. |
Yeah, nice! This looks good to me with minor indentation fixes. Would prefer someone else with rustbook/doc experience chime in on the string-litteral hack (and other design concerns). |
@gankro Thanks for the feedback, and help! If there is a better way to implement the CSS and JavaScript importing I'm happy to take care of it. |
After you fix the indentation in the JS, feel free to squash the commits. I have a feeling this will get merged as-is, but just want to discuss design with others a bit beforehand. |
0a1ee90
to
35a54c7
Compare
@sfaxon I want to bikeshed this some more, I hope you don't mind :) First off, you should probably set an explicit padding for Why are the bars 90% wide? 100% looks more symmetrical: (I changed the first button's Last but not least, you should probably add a description of what that button does. A title would be nice for people not recognizing that it means "menu"/"navigation". Additionally, a textual representation for screen readers would improve accessibility quite a bit (I guess the text-only pages are otherwise accessible). Bootstrap uses this in their navbar (cf. docs): |
I'm fine with the Rustbook changes here. |
I tried this out on my phone, and the hamburger looks weird. It's got very, very skinny lines. (iPhone 6.) |
Other than that it looks great though! |
I've addressed the CSS and screen reader changes from @killercup (thanks!), pushed changes here and redeployed to http://home.faxon.org/book/index.html for review. If everyone is ok with them I can squash before merging. |
Looks great on my iPhone 5S. Scrolling is a bit weird, though (it has no momentum). It might be nice to try |
I think I'm happy with this, it's at least a strict improvement. So r=me after a squash |
8679f0f
to
9af8a64
Compare
@sfaxon Only reviewers can I already r+'d it myself, though. |
@gankro sorry, I'm not familiar with the r notation. Is that documented somewhere that I didn't see? |
Great PR @sfaxon! We should definitely look to reimplement momentum-based scrolling as per @killercup's suggestion, as it plays a pretty large role in the browsing experience. |
make the book more mobile friendly Reviewed-by: Gankro
make the book more mobile friendly Reviewed-by: Gankro
make the book more mobile friendly Reviewed-by: Gankro
Hi everyone! What's the status on this PR? I noticed the same issues while reading the doc, and was planning to fix them but this seems to take care of it. Is this just waiting to be merged? I do notice that toggling the navigation could be done using CSS3 |
Yes, it's in bors' queue (quite a bit down currently, just search for the 21071). |
make the book more mobile friendly Reviewed-by: Gankro
Helps with mobile friendliness of The Rust Book rust-lang#20850
Helps with mobile friendliness of The Rust Book #20850