Skip to content

Commit d0e61af

Browse files
committed
add sidebar effect
1 parent 17f8e6e commit d0e61af

2 files changed

Lines changed: 110 additions & 1 deletion

File tree

assets/css/documentation.css

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,31 @@ html, body {
4949

5050
#documenter:after {
5151
height: 25px;
52-
}
52+
}
53+
54+
/* SIDEBAR */
55+
@media screen and (max-width: 1055px) {
56+
57+
#documenter-article-toggle-button-sidebar {
58+
display: none;
59+
}
60+
61+
}
62+
63+
@media screen and (min-width: 1056px) {
64+
65+
#documenter-article-toggle-button-sidebar {
66+
display: block; /* or inline-block, depending on your layout */
67+
}
68+
69+
#documenter .docs-sidebar.hidden {
70+
left:-18rem!important;
71+
}
72+
73+
#documenter .docs-main.sidebar-hidden {
74+
width:100%!important;
75+
max-width: 52rem!important;
76+
margin-left: 2rem!important;
77+
padding-right: 0rem!important;
78+
}
79+
}

assets/js/documentation.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,86 @@ function addEventListenerToShowHideTopbar() {
124124
});
125125
}
126126

127+
// SIDEBAR TOGGLE
128+
function addSidebarToggleButton() {
129+
// Select the element with the class "docs-right"
130+
var docsRight = document.querySelector('.docs-right');
131+
132+
// Check if the element exists
133+
if (docsRight) {
134+
// Create the new button element
135+
var button = document.createElement('a');
136+
button.className = 'docs-article-toggle-button-sidebar fa-solid';
137+
button.id = 'documenter-article-toggle-button-sidebar';
138+
button.href = 'javascript:;';
139+
button.title = 'Fold sidebar';
140+
141+
// Check localStorage for button status
142+
var buttonStatus = localStorage.getItem('sidebarButtonStatus');
143+
144+
// Set the button class based on the stored status
145+
if (buttonStatus === 'right') {
146+
button.classList.add('fa-chevron-right');
147+
} else {
148+
button.classList.add('fa-chevron-left'); // Default to left
149+
}
150+
151+
// Insert the button as the first child of the docs-right element
152+
docsRight.insertBefore(button, docsRight.firstChild);
153+
154+
// Event listener
155+
button.addEventListener('click', toggleSidebarButton);
156+
}
157+
}
158+
159+
function toggleSidebarButton() {
160+
161+
if (this.classList.contains('fa-chevron-left')) {
162+
hideSidebar(this)
163+
} else {
164+
showSidebar(this)
165+
}
166+
167+
}
168+
169+
function hideSidebar(button) {
170+
171+
button.classList.remove('fa-chevron-left');
172+
button.classList.add('fa-chevron-right');
173+
174+
localStorage.setItem('sidebarButtonStatus', 'right');
175+
176+
var sidebar = document.querySelector('.docs-sidebar');
177+
if (sidebar) {
178+
sidebar.classList.add('hidden')
179+
}
180+
181+
var content = document.querySelector('.docs-main');
182+
if (content){
183+
content.classList.add('sidebar-hidden')
184+
}
185+
186+
}
187+
188+
function showSidebar(button) {
189+
190+
button.classList.remove('fa-chevron-right');
191+
button.classList.add('fa-chevron-left');
192+
193+
localStorage.setItem('sidebarButtonStatus', 'left');
194+
195+
var sidebar = document.querySelector('.docs-sidebar');
196+
if (sidebar) {
197+
sidebar.classList.remove('hidden')
198+
}
199+
200+
var content = document.querySelector('.docs-main');
201+
if (content){
202+
content.classList.remove('sidebar-hidden')
203+
}
204+
205+
}
206+
127207
//
128208
if (
129209
document.readyState === "complete" ||
@@ -132,9 +212,11 @@ if (
132212
// call on next available tick
133213
setTimeout(topbarInjector, 1);
134214
setTimeout(addEventListenerToShowHideTopbar, 1);
215+
setTimeout(addSidebarToggleButton, 1);
135216
} else {
136217
document.addEventListener("DOMContentLoaded", topbarInjector);
137218
document.addEventListener("DOMContentLoaded", addEventListenerToShowHideTopbar);
219+
document.addEventListener("DOMContentLoaded", addSidebarToggleButton);
138220
}
139221

140222
//

0 commit comments

Comments
 (0)