Skip to content

Commit 357ebcf

Browse files
authored
Merge pull request #849 from gentoo90/sidebar-resize
Add sidebar resize
2 parents 1a4f38e + 3d8db7f commit 357ebcf

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

src/theme/book.js

+18
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ function playpen_text(playpen) {
435435
var sidebar = document.getElementById("sidebar");
436436
var sidebarLinks = document.querySelectorAll('#sidebar a');
437437
var sidebarToggleButton = document.getElementById("sidebar-toggle");
438+
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
438439
var firstContact = null;
439440

440441
function showSidebar() {
@@ -474,6 +475,23 @@ function playpen_text(playpen) {
474475
}
475476
});
476477

478+
sidebarResizeHandle.addEventListener('mousedown', initResize, false);
479+
480+
function initResize(e) {
481+
window.addEventListener('mousemove', resize, false);
482+
window.addEventListener('mouseup', stopResize, false);
483+
html.classList.add('sidebar-resizing');
484+
}
485+
function resize(e) {
486+
document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px');
487+
}
488+
//on mouseup remove windows functions mousemove & mouseup
489+
function stopResize(e) {
490+
html.classList.remove('sidebar-resizing');
491+
window.removeEventListener('mousemove', resize, false);
492+
window.removeEventListener('mouseup', stopResize, false);
493+
}
494+
477495
document.addEventListener('touchstart', function (e) {
478496
firstContact = {
479497
x: e.touches[0].clientX,

src/theme/css/chrome.css

+31-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
7878
display: flex;
7979
margin: 0 5px;
8080
}
81-
.no-js .left-buttons {
81+
.no-js .left-buttons {
8282
display: none;
8383
}
8484

@@ -145,7 +145,7 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
145145
display: none;
146146
}
147147

148-
.mobile-nav-chapters {
148+
.mobile-nav-chapters {
149149
font-size: 2.5em;
150150
text-align: center;
151151
text-decoration: none;
@@ -301,21 +301,46 @@ ul#searchresults span.teaser em {
301301
top: 0;
302302
bottom: 0;
303303
width: var(--sidebar-width);
304-
overflow-y: auto;
305-
padding: 10px 10px;
306304
font-size: 0.875em;
307305
box-sizing: border-box;
308306
-webkit-overflow-scrolling: touch;
309307
overscroll-behavior-y: contain;
310308
background-color: var(--sidebar-bg);
311309
color: var(--sidebar-fg);
312310
}
313-
.js .sidebar {
311+
.sidebar-resizing {
312+
-moz-user-select: none;
313+
-webkit-user-select: none;
314+
-ms-user-select: none;
315+
user-select: none;
316+
}
317+
.js:not(.sidebar-resizing) .sidebar {
314318
transition: transform 0.3s; /* Animation: slide away */
315319
}
316320
.sidebar code {
317321
line-height: 2em;
318322
}
323+
.sidebar .sidebar-scrollbox {
324+
overflow-y: auto;
325+
position: absolute;
326+
top: 0;
327+
bottom: 0;
328+
left: 0;
329+
right: 0;
330+
padding: 10px 10px;
331+
}
332+
.sidebar .sidebar-resize-handle {
333+
position: absolute;
334+
cursor: col-resize;
335+
width: 0;
336+
right: 0;
337+
top: 0;
338+
bottom: 0;
339+
}
340+
.js .sidebar .sidebar-resize-handle {
341+
cursor: col-resize;
342+
width: 5px;
343+
}
319344
.sidebar-hidden .sidebar {
320345
transform: translateX(calc(0px - var(--sidebar-width)));
321346
}
@@ -368,7 +393,7 @@ ul#searchresults span.teaser em {
368393
background-color: var(--sidebar-spacer);
369394
}
370395

371-
@media (-moz-touch-enabled: 1), (pointer: coarse) {
396+
@media (-moz-touch-enabled: 1), (pointer: coarse) {
372397
.chapter li a { padding: 5px 0; }
373398
.spacer { margin: 10px 0; }
374399
}

src/theme/css/general.css

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ h4, h5 { margin-top: 2em; }
3030

3131
.header + .header h3,
3232
.header + .header h4,
33-
.header + .header h5 {
33+
.header + .header h5 {
3434
margin-top: 1em;
3535
}
3636

@@ -51,7 +51,7 @@ a.header:target h4:before {
5151
.page-wrapper {
5252
box-sizing: border-box;
5353
}
54-
.js .page-wrapper {
54+
.js:not(.sidebar-resizing) .page-wrapper {
5555
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
5656
}
5757

@@ -141,4 +141,3 @@ blockquote {
141141
.tooltipped .tooltiptext {
142142
visibility: visible;
143143
}
144-

src/theme/index.hbs

+6-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<!-- Set the theme before any content is loaded, prevents flash -->
6262
<script type="text/javascript">
6363
var theme;
64-
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
64+
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
6565
if (theme === null || theme === undefined) { theme = default_theme; }
6666
document.body.className = theme;
6767
document.querySelector('html').className = theme + ' js';
@@ -80,7 +80,10 @@
8080
</script>
8181

8282
<nav id="sidebar" class="sidebar" aria-label="Table of contents">
83-
{{#toc}}{{/toc}}
83+
<div class="sidebar-scrollbox">
84+
{{#toc}}{{/toc}}
85+
</div>
86+
<div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
8487
</nav>
8588

8689
<div id="page-wrapper" class="page-wrapper">
@@ -110,7 +113,7 @@
110113
{{/if}}
111114
</div>
112115

113-
<h1 class="menu-title">{{ book_title }}</h1>
116+
<h1 class="menu-title">{{ book_title }}</h1>
114117

115118
<div class="right-buttons">
116119
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">

0 commit comments

Comments
 (0)