Skip to content
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

Add support for mobile screen sizes on Darkfish #1025

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rdoc/generator/template/darkfish/_head.rhtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<meta charset="<%= @options.charset %>">
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title><%= h @title %></title>

Expand Down
26 changes: 26 additions & 0 deletions lib/rdoc/generator/template/darkfish/_sidebar_toggle.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<button id="navigation-toggle" class="navigation-toggle" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
<!--
Copyright (c) 2021 Luca Burgio
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right way to attach the license.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, maybe we could use U+2630 (☰) as an icon.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or U+2261(≡)?


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<svg width="20px" height="24px" stroke-width="1.5" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" color="#000000">
<path d="M3 5h18M3 12h18M3 19h18" stroke="#000000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</button>
4 changes: 3 additions & 1 deletion lib/rdoc/generator/template/darkfish/class.rhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<body id="top" role="document" class="<%= klass.type %>">
<nav role="navigation">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<div id="project-navigation">
<%= render '_sidebar_navigation.rhtml' %>
<%= render '_sidebar_search.rhtml' %>
Expand Down
76 changes: 62 additions & 14 deletions lib/rdoc/generator/template/darkfish/css/rdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ body {
font-weight: 300;

/* Layout */
display: grid;
grid-template-columns: auto 1fr;
display: flex;
flex-wrap: wrap;
}

body > :last-child {
grid-column: 1 / 3;
width: 100%;
}

h1 span,
Expand Down Expand Up @@ -203,24 +203,38 @@ nav {
font-family: Helvetica, sans-serif;
font-size: 14px;
border-right: 1px solid #ccc;
position: sticky;
position: fixed;
top: 0;
overflow: auto;
z-index: 10;

/* Layout */
width: 260px; /* fallback */
width: max(50px, 20vw);
min-width: 50px;
max-width: 80vw;
height: calc(100vh - 100px); /* reduce the footer height */
resize: horizontal;
width: 300px;
min-height: 100vh;
background: white;
}

@media (min-width: 1024px) {
nav {
min-height: unset;
height: calc(100vh - 100px); /* reduce the footer height */
}
}

main {
display: block;
margin: 1em;
margin: 3em 1em 1em;
min-width: 340px;
font-size: 16px;
width: 100%;
max-width: 64em;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this could be even smaller.

}

@media (min-width: 1024px) {
main {
margin-left: auto;
margin-right: auto;
}
}

main h1,
Expand All @@ -232,8 +246,10 @@ main h6 {
font-family: Helvetica, sans-serif;
}

.table-of-contents main {
margin-left: 2em;
@media (min-width: 1024px) {
.table-of-contents main {
margin-left: 20em;
}
}

#validator-badges {
Expand Down Expand Up @@ -280,6 +296,39 @@ nav p {
list-style: none;
}

.navigation-toggle {
position: fixed;
left: 4px;
top: 6px;
z-index: 100;

background: transparent;
border: none;
cursor: pointer;
margin-left: 7px;
padding: 4px;
}
.navigation-toggle[aria-expanded="true"] {
left: 260px;
}

/* Adds a suble gradient to help the toggle stand out from the background */
.navigation-toggle::before {
content: "";
background: linear-gradient(180deg, rgba(250,250,250,1) 40%, rgba(250,250,250,0.8) 70%, rgba(250,250,250,0) 100%);
display: block;
z-index: -1;
pointer-events: none;
position: fixed;
top: 0;
height: 50px;
width: 100vw;
}

.navigation-toggle[aria-expanded="true"]::before {
height: 0;
}

#project-navigation .nav-section {
margin: 0;
border-top: 0;
Expand Down Expand Up @@ -684,4 +733,3 @@ pre {
}

/* @end */

4 changes: 3 additions & 1 deletion lib/rdoc/generator/template/darkfish/index.rhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<body id="top" role="document" class="file">
<nav role="navigation">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<div id="project-navigation">
<%= render '_sidebar_navigation.rhtml' %>

Expand Down
17 changes: 17 additions & 0 deletions lib/rdoc/generator/template/darkfish/js/darkfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,25 @@ function hookFocus() {
});
}

function hookSidebar() {
var navigation = document.querySelector('#navigation');
var navigationToggle = document.querySelector('#navigation-toggle');

navigationToggle.addEventListener('click', function() {
navigation.hidden = !navigation.hidden;
navigationToggle.ariaExpanded = navigationToggle.ariaExpanded !== 'true';
});

var isSmallViewport = window.matchMedia("(max-width: 1024px)").matches;
if (isSmallViewport) {
navigation.hidden = true;
navigationToggle.ariaExpanded = false;
}
}

document.addEventListener('DOMContentLoaded', function() {
hookSourceViews();
hookSearch();
hookFocus();
hookSidebar();
});
5 changes: 3 additions & 2 deletions lib/rdoc/generator/template/darkfish/page.rhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<body id="top" role="document" class="file">
<nav role="navigation">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<div id="project-navigation">
<%= render '_sidebar_navigation.rhtml' %>
<%= render '_sidebar_search.rhtml' %>
Expand All @@ -15,4 +17,3 @@
<main role="main" aria-label="Page <%=h file.full_name%>">
<%= file.description %>
</main>

5 changes: 3 additions & 2 deletions lib/rdoc/generator/template/darkfish/servlet_not_found.rhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<body role="document">
<nav role="navigation">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<%= render '_sidebar_navigation.rhtml' %>

<%= render '_sidebar_search.rhtml' %>
Expand All @@ -15,4 +17,3 @@

<p><%= message %>
</main>

4 changes: 3 additions & 1 deletion lib/rdoc/generator/template/darkfish/servlet_root.rhtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<body role="document">
<nav role="navigation">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<div id="project-navigation">
<div id="home-section" class="nav-section">
<h2>
Expand Down
9 changes: 9 additions & 0 deletions lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<body id="top" class="table-of-contents">
<%= render '_sidebar_toggle.rhtml' %>

<nav id="navigation" role="navigation">
<div id="project-navigation">
<%= render '_sidebar_navigation.rhtml' %>

<%= render '_sidebar_search.rhtml' %>
</div>
</nav>
Comment on lines +4 to +10
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this needs more content, but I needed a sidebar on this page. Otherwise, it's harder to return to the Home page.

<main role="main">
<h1 class="class"><%= h @title %></h1>

Expand Down