Skip to content

Commit 66c4613

Browse files
committed
add sidebar effect
1 parent d0e61af commit 66c4613

1 file changed

Lines changed: 28 additions & 20 deletions

File tree

assets/js/documentation.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,28 +131,36 @@ function addSidebarToggleButton() {
131131

132132
// Check if the element exists
133133
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-
}
150134

151-
// Insert the button as the first child of the docs-right element
152-
docsRight.insertBefore(button, docsRight.firstChild);
135+
// check if the button already exists
136+
var button = document.getElementById('documenter-article-toggle-button-sidebar');
137+
if (!(button)) {
138+
139+
// Create the new button element
140+
var button = document.createElement('a');
141+
button.className = 'docs-article-toggle-button-sidebar fa-solid';
142+
button.id = 'documenter-article-toggle-button-sidebar';
143+
button.href = 'javascript:;';
144+
button.title = 'Fold sidebar';
145+
146+
// Check localStorage for button status
147+
var buttonStatus = localStorage.getItem('sidebarButtonStatus');
148+
149+
// Set the button class based on the stored status
150+
if (buttonStatus === 'right') {
151+
button.classList.add('fa-chevron-right');
152+
} else {
153+
button.classList.add('fa-chevron-left'); // Default to left
154+
}
155+
156+
// Insert the button as the first child of the docs-right element
157+
docsRight.insertBefore(button, docsRight.firstChild);
158+
159+
// Event listener
160+
button.addEventListener('click', toggleSidebarButton);
161+
162+
}
153163

154-
// Event listener
155-
button.addEventListener('click', toggleSidebarButton);
156164
}
157165
}
158166

0 commit comments

Comments
 (0)