-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (39 loc) · 1.52 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// main.js
document.addEventListener('DOMContentLoaded', function() {
const sidebarElements = document.querySelectorAll('.sidebar');
const originalPositions = [];
// Store the original parents and next siblings
sidebarElements.forEach(function(sidebarElement, index) {
originalPositions[index] = {
parent: sidebarElement.parentNode,
nextSibling: sidebarElement.nextSibling
};
});
function moveSidebars() {
const sidebarContent = document.querySelector('.sidebarContent');
if (window.innerWidth > 900) {
// Move sidebars into sidebar-content
sidebarElements.forEach(function(sidebarElement) {
if (sidebarElement.parentNode !== sidebarContent) {
sidebarContent.appendChild(sidebarElement);
}
});
} else {
// Move sidebars back to their original positions
sidebarElements.forEach(function(sidebarElement, index) {
const { parent, nextSibling } = originalPositions[index];
if (sidebarElement.parentNode !== parent) {
if (nextSibling) {
parent.insertBefore(sidebarElement, nextSibling);
} else {
parent.appendChild(sidebarElement);
}
}
});
}
}
// Initial call
moveSidebars();
// Add event listener for resize
window.addEventListener('resize', moveSidebars);
});