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

Toggleable Sidebar #34

Open
wants to merge 2 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions lib/mccole/resources/mccole.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

--extra-vertical-space: 1ex;
--slide-padding: 2em;
--sidebar-width: 300px;

--stamp-brown: #5F483C;
--stamp-red: #8B000F;
Expand Down Expand Up @@ -64,6 +65,11 @@ body {
font-family: "Lucida Grande", Arial, sans-serif;
}

/* don't change header line-height */
h1, h2, h3 {
line-height: normal;
}

/*
* Code sections.
*/
Expand All @@ -73,20 +79,45 @@ code {
}

/*
* Two-column display with nav bar on the left.
* Toggle-able nav bar on the left.
*/

div.bordered {
border-left: solid var(--mediumborder) var(--lightgray);
.sidebar {
position: fixed;
left: 0;
top: 0;
bottom: 0;
width: var(--sidebar-width);
padding: 1rem;
box-sizing: border-box;
overflow-y: auto;
background-color: var(--faintgray);
transition: transform 0.2s;
}

.sidebar-hidden .sidebar {
transform: translateX(calc(0px - var(--sidebar-width)));
}

div.contents {
transition: transform 0.2s;
padding: 1rem;
}

.sidebar-visible .contents {
transform: translateX(var(--sidebar-width));
}

.sidebar-hidden .contents {
transform: none;
}

div.row {
display: grid;
grid-template-columns: 25% 75%;
button.sidebar-toggle {
padding: 2px 8px;
}

div.column {
padding: 1rem;
.logo {
width: 30px;
}

/*
Expand Down
55 changes: 34 additions & 21 deletions lib/mccole/templates/contents.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
<p>
<img src="@root/logo.svg" alt="site logo" style="width: 10%" />
<!-- Hide / unhide sidebar before it is displayed -->
<script type="text/javascript">
var html = document.querySelector('html');
var sidebar = 'hidden';
if (document.body.clientWidth >= 1080) {
sidebar = 'visible';
}
html.classList.add("sidebar-" + sidebar);
</script>


<div class="sidebar">
<p>
<img src="@root/logo.svg" alt="site logo" class="logo" />
<a href="@root/">{{ site.title }}</a>
</p>
<ol class="toc-chapter">
{% for slug, title in site.mccole.titles.chapters %}
<li{% if slug in site.todo %} class="todo"{% endif %}>
<a href="@root/{{ slug }}/">
{% if slug == node.slug %}<strong>{% endif %}{{ title }}{% if slug == node.slug %}</strong>{% endif %}
</a>
</li>
{% endfor %}
</ol>
<ol class="toc-appendix">
{% for slug, title in site.mccole.titles.appendices %}
<li{% if slug in site.todo %} class="todo"{% endif %}>
<a href="@root/{{ slug }}/">
{% if slug == node.slug %}<strong>{% endif %}{{ title }}{% if slug == node.slug %}</strong>{% endif %}
</a>
</li>
{% endfor %}
</ol>
</p>
<ol class="toc-chapter">
{% for slug, title in site.mccole.titles.chapters %}
<li{% if slug in site.todo %} class="todo"{% endif %}>
<a href="@root/{{ slug }}/">
{% if slug == node.slug %}<strong>{% endif %}{{ title }}{% if slug == node.slug %}</strong>{% endif %}
</a>
</li>
{% endfor %}
</ol>
<ol class="toc-appendix">
{% for slug, title in site.mccole.titles.appendices %}
<li{% if slug in site.todo %} class="todo"{% endif %}>
<a href="@root/{{ slug }}/">
{% if slug == node.slug %}<strong>{% endif %}{{ title }}{% if slug == node.slug %}</strong>{% endif %}
</a>
</li>
{% endfor %}
</ol>
</div>
22 changes: 16 additions & 6 deletions lib/mccole/templates/node.ibis
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
{% include "head.html" %}
<body>
<div class="row">
<div class="column">
{% include "contents.html" %}
</div>
<div id="printable" class="column bordered{% if node.slug in site.todo %} todo{% endif %}">
{% include "contents.html" %}
<div id="printable" class="contents {% if node.slug in site.todo %} todo{% endif %}">
<main>
{% include "title.html" %}
<button class="sidebar-toggle">☰</button>
{% include "title.html" %}
{% include "syllabus.html" %}
{% include "definitions.html" %}
{% include "definitions.html" %}
{{ node.html }}
</main>
</div>
</div>
<!-- Hide / unhide sidebar on clicking the toggle -->
<script type="text/javascript">
document
.querySelector('.sidebar-toggle')
.addEventListener('click', function toggleSidebar() {
var html = document.querySelector('html');
html.classList.toggle('sidebar-hidden');
html.classList.toggle('sidebar-visible');
});
</script>

</body>
</html>