Repository navigation
Expand file tree
/
Copy pathresponsive-patch.js
More file actions
137 lines (122 loc) · 3.84 KB
/
Copy pathresponsive-patch.js
File metadata and controls
137 lines (122 loc) · 3.84 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* NEXA — Responsive Layout Patch v6.0
* Handles:
* 1. Sync badge repositioning
* 2. Body scroll lock when sidebar is open on mobile
* 3. Close sidebar when nav tab tapped on mobile
* 4. Resize cleanup
*
* Does NOT touch hamburger open/close — script.js owns that via:
* hamburger.addEventListener('click', ...) at top level
*/
(function () {
'use strict';
var MOBILE_BP = 768;
var _scrollY = 0; /* remember scroll position before lock */
function isMobile() {
return window.innerWidth <= MOBILE_BP;
}
/* ── Body scroll lock ── */
function lockScroll() {
_scrollY = window.scrollY;
document.body.classList.add('sidebar-open');
document.body.style.top = '-' + _scrollY + 'px';
}
function unlockScroll() {
document.body.classList.remove('sidebar-open');
document.body.style.top = '';
window.scrollTo(0, _scrollY);
}
/* ── Close sidebar helper ── */
function closeSidebar() {
var sidebar = document.getElementById('sidebar');
var overlay = document.getElementById('sidebar-overlay');
var ham = document.getElementById('hamburger');
if (sidebar) sidebar.classList.remove('open');
if (overlay) overlay.classList.remove('visible');
if (ham) ham.setAttribute('aria-expanded', 'false');
if (isMobile()) unlockScroll();
}
/* ── Observe sidebar open/close to apply scroll lock ── */
function watchSidebar() {
var sidebar = document.getElementById('sidebar');
if (!sidebar) return;
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (m) {
if (m.attributeName === 'class') {
if (sidebar.classList.contains('open') && isMobile()) {
lockScroll();
} else {
unlockScroll();
}
}
});
});
observer.observe(sidebar, { attributes: true, attributeFilter: ['class'] });
}
/* ── Close sidebar after picking a nav tab on mobile ── */
function wireNavClose() {
document.querySelectorAll('.nav-item[data-tab]').forEach(function (btn) {
btn.addEventListener('click', function () {
if (isMobile()) {
/* small delay lets script.js switchTab run first */
setTimeout(closeSidebar, 60);
}
});
});
}
/* ── Move sync badge into sidebar footer on desktop ── */
function placeBadge() {
var badge = document.getElementById('autosave-indicator');
var foot = document.querySelector('.sidebar-footer');
if (!badge) return;
if (isMobile()) {
badge.style.display = 'none';
} else {
badge.style.display = '';
if (foot && !foot.contains(badge)) {
foot.insertBefore(badge, foot.firstChild);
}
}
}
function fixUndoBannerPosition() {
var undo = document.getElementById('undo-banner');
if (!undo) return;
if (isMobile()) {
undo.style.bottom = '160px'; // above the input bar
undo.style.zIndex = '6000';
} else {
undo.style.bottom = '';
undo.style.zIndex = '';
}
}
/* ── Resize cleanup ── */
function onResize() {
placeBadge();
if (!isMobile()) {
/* Auto-close drawer when resizing to desktop */
var sidebar = document.getElementById('sidebar');
var overlay = document.getElementById('sidebar-overlay');
if (sidebar) sidebar.classList.remove('open');
if (overlay) overlay.classList.remove('visible');
unlockScroll();
}
}
/* ── Init ── */
function init() {
placeBadge();
fixUndoBannerPosition();
watchSidebar();
wireNavClose();
var t;
window.addEventListener('resize', function () {
clearTimeout(t);
t = setTimeout(onResize, 100);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
setTimeout(init, 0);
}
})();