-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
57 lines (47 loc) · 1.96 KB
/
script.js
File metadata and controls
57 lines (47 loc) · 1.96 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
document.addEventListener('DOMContentLoaded', function() {
fetch('/footer.html')
.then(response => response.text())
.then(data => {
document.getElementById('footer-placeholder').innerHTML = data;
})
.catch(error => console.error('Ошибка загрузки футера:', error));
fetch('/sidebar.html')
.then(response => response.text())
.then(data => {
document.getElementById('sidebar-placeholder').innerHTML = data;
initSidebar();
initSidebarTree();
})
.catch(error => console.error('Ошибка загрузки боковой панели:', error));
function initSidebar() {
const menuToggle = document.getElementById('menu-toggle');
const sidebar = document.getElementById('site-tree-sidebar');
const closeBtn = document.querySelector('.closebtn');
if (menuToggle && sidebar && closeBtn) {
menuToggle.addEventListener('click', function(event) {
event.stopPropagation();
sidebar.classList.toggle('open');
});
closeBtn.addEventListener('click', function() {
sidebar.classList.remove('open');
});
document.addEventListener('click', function(event) {
if (!sidebar.contains(event.target) && event.target !== menuToggle) {
sidebar.classList.remove('open');
}
});
}
}
function initSidebarTree() {
const arrows = document.querySelectorAll('.sidebar-content .arrow');
arrows.forEach(arrow => {
arrow.addEventListener('click', function(event) {
event.stopPropagation();
const parentLi = arrow.closest('.has-children');
if (parentLi) {
parentLi.classList.toggle('expanded');
}
});
});
}
});