Add sidebar resizing

This commit is contained in:
gentoo90 2018-12-12 21:31:01 +02:00
parent 1052ee92e1
commit 3d37e24c14
3 changed files with 46 additions and 8 deletions

View File

@ -435,6 +435,7 @@ function playpen_text(playpen) {
var sidebar = document.getElementById("sidebar"); var sidebar = document.getElementById("sidebar");
var sidebarLinks = document.querySelectorAll('#sidebar a'); var sidebarLinks = document.querySelectorAll('#sidebar a');
var sidebarToggleButton = document.getElementById("sidebar-toggle"); var sidebarToggleButton = document.getElementById("sidebar-toggle");
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
var firstContact = null; var firstContact = null;
function showSidebar() { function showSidebar() {
@ -474,6 +475,21 @@ function playpen_text(playpen) {
} }
}); });
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
function initResize(e) {
window.addEventListener('mousemove', resize, false);
window.addEventListener('mouseup', stopResize, false);
}
function resize(e) {
document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px');
}
//on mouseup remove windows functions mousemove & mouseup
function stopResize(e) {
window.removeEventListener('mousemove', resize, false);
window.removeEventListener('mouseup', stopResize, false);
}
document.addEventListener('touchstart', function (e) { document.addEventListener('touchstart', function (e) {
firstContact = { firstContact = {
x: e.touches[0].clientX, x: e.touches[0].clientX,

View File

@ -78,7 +78,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
display: flex; display: flex;
margin: 0 5px; margin: 0 5px;
} }
.no-js .left-buttons { .no-js .left-buttons {
display: none; display: none;
} }
@ -145,7 +145,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
display: none; display: none;
} }
.mobile-nav-chapters { .mobile-nav-chapters {
font-size: 2.5em; font-size: 2.5em;
text-align: center; text-align: center;
text-decoration: none; text-decoration: none;
@ -301,8 +301,6 @@ ul#searchresults span.teaser em {
top: 0; top: 0;
bottom: 0; bottom: 0;
width: var(--sidebar-width); width: var(--sidebar-width);
overflow-y: auto;
padding: 10px 10px;
font-size: 0.875em; font-size: 0.875em;
box-sizing: border-box; box-sizing: border-box;
-webkit-overflow-scrolling: touch; -webkit-overflow-scrolling: touch;
@ -316,6 +314,27 @@ ul#searchresults span.teaser em {
.sidebar code { .sidebar code {
line-height: 2em; line-height: 2em;
} }
.sidebar .sidebar-scrollbox {
overflow-y: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 10px 10px;
}
.sidebar .sidebar-resize-handle {
position: absolute;
cursor: col-resize;
width: 0;
right: 0;
top: 0;
bottom: 0;
}
.js .sidebar .sidebar-resize-handle {
cursor: col-resize;
width: 5px;
}
.sidebar-hidden .sidebar { .sidebar-hidden .sidebar {
transform: translateX(calc(0px - var(--sidebar-width))); transform: translateX(calc(0px - var(--sidebar-width)));
} }
@ -366,7 +385,7 @@ a:hover {
background-color: var(--sidebar-spacer); background-color: var(--sidebar-spacer);
} }
@media (-moz-touch-enabled: 1), (pointer: coarse) { @media (-moz-touch-enabled: 1), (pointer: coarse) {
.chapter li a { padding: 5px 0; } .chapter li a { padding: 5px 0; }
.spacer { margin: 10px 0; } .spacer { margin: 10px 0; }
} }

View File

@ -61,7 +61,7 @@
<!-- Set the theme before any content is loaded, prevents flash --> <!-- Set the theme before any content is loaded, prevents flash -->
<script type="text/javascript"> <script type="text/javascript">
var theme; var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; } if (theme === null || theme === undefined) { theme = default_theme; }
document.body.className = theme; document.body.className = theme;
document.querySelector('html').className = theme + ' js'; document.querySelector('html').className = theme + ' js';
@ -80,7 +80,10 @@
</script> </script>
<nav id="sidebar" class="sidebar" aria-label="Table of contents"> <nav id="sidebar" class="sidebar" aria-label="Table of contents">
{{#toc}}{{/toc}} <div class="sidebar-scrollbox">
{{#toc}}{{/toc}}
</div>
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
</nav> </nav>
<div id="page-wrapper" class="page-wrapper"> <div id="page-wrapper" class="page-wrapper">
@ -110,7 +113,7 @@
{{/if}} {{/if}}
</div> </div>
<h1 class="menu-title">{{ book_title }}</h1> <h1 class="menu-title">{{ book_title }}</h1>
<div class="right-buttons"> <div class="right-buttons">
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book"> <a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">