Skip to content

Commit e2c4e5e

Browse files
author
GeiserX
committed
Fix header overflow visibility and allow ZIP buttons to overflow
- Measure overflow space using header actions container width - Keep overflow button visible when needed and show burger icon - Allow ZIP import/export to move into overflow on small screens
1 parent 62a1d94 commit e2c4e5e

2 files changed

Lines changed: 16 additions & 42 deletions

File tree

cms/static/js/main.js

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,16 @@ function syncHeaderOverflow() {
103103
allButtons.forEach((btn) => btn.classList.remove('is-overflowed'));
104104

105105
// Hide overflow button initially to measure without it
106-
if (overflowBtn) {
107-
overflowBtn.style.display = 'none';
108-
}
106+
if (overflowBtn) overflowBtn.style.display = 'none';
109107

110108
// Force layout settle to get accurate measurements
111109
void header.offsetWidth;
112110
void main.offsetWidth;
113111

114-
// Get actual measurements after reset
115-
const headerRect = header.getBoundingClientRect();
116-
const logoContainer = header.querySelector('div:first-child');
117-
const logoRect = logoContainer ? logoContainer.getBoundingClientRect() : { width: 0 };
118-
119-
// Get computed styles for padding
120-
const headerStyles = window.getComputedStyle(header);
121-
const paddingLeft = parseFloat(headerStyles.paddingLeft) || 0;
122-
const paddingRight = parseFloat(headerStyles.paddingRight) || 0;
112+
// Measure on the actions container to avoid over-subtracting
113+
const actionsRect = headerActions.getBoundingClientRect();
123114
const gap = 8; // gap between elements (0.5rem = 8px)
124115

125-
// Calculate space taken by logo and gaps
126-
const logoWithGap = logoRect.width + gap;
127-
128116
// Measure all button widths
129117
let totalButtonsWidth = 0;
130118
const buttonWidths = [];
@@ -140,8 +128,8 @@ function syncHeaderOverflow() {
140128
totalButtonsWidth -= gap;
141129
}
142130

143-
// Calculate available width: full header width minus logo, padding, and gaps
144-
const availableWidthWithoutOverflow = headerRect.width - logoWithGap - paddingLeft - paddingRight;
131+
// Available width is the width of the actions container
132+
const availableWidthWithoutOverflow = actionsRect.width;
145133

146134
// First check: do all buttons fit without overflow button?
147135
if (totalButtonsWidth <= availableWidthWithoutOverflow) {
@@ -154,28 +142,20 @@ function syncHeaderOverflow() {
154142

155143
// Buttons don't all fit - we need the overflow button
156144
const overflowBtnWidth = overflowBtn ? (overflowBtn.getBoundingClientRect().width || 80) + gap : 80 + gap;
157-
const availableWidthWithOverflow = headerRect.width - logoWithGap - overflowBtnWidth - paddingLeft - paddingRight;
145+
const availableWidthWithOverflow = actionsRect.width - overflowBtnWidth;
158146

159147
// Now calculate what fits: pinned buttons always show, then fit overflowable from left
160148
let currentWidth = 0;
161149

162-
// Add pinned buttons first
150+
// Add pinned buttons first (none currently, but keep logic)
163151
pinnedButtons.forEach((btn) => {
164152
const item = buttonWidths.find(b => b.btn === btn);
165-
if (item) {
166-
currentWidth += item.width + gap;
167-
}
153+
if (item) currentWidth += item.width + gap;
168154
});
169-
170-
// Subtract gap after last pinned button if there are overflowable buttons
171-
if (pinnedButtons.length > 0 && overflowableButtons.length > 0) {
172-
currentWidth -= gap; // Remove the gap, we'll add it between sections if needed
173-
}
174-
155+
if (pinnedButtons.length > 0 && overflowableButtons.length > 0) currentWidth -= gap;
156+
175157
// Show overflow button since we need it
176-
if (overflowBtn) {
177-
overflowBtn.style.display = '';
178-
}
158+
if (overflowBtn) overflowBtn.style.display = '';
179159

180160
// Now fit overflowable buttons from left to right
181161
let overflowCount = 0;
@@ -196,14 +176,8 @@ function syncHeaderOverflow() {
196176
}
197177

198178
// Show divider only if there are overflow items
199-
if (overflowDivider) {
200-
overflowDivider.style.display = overflowCount > 0 ? 'block' : 'none';
201-
}
202-
203-
// If no buttons in overflow, hide the overflow button
204-
if (overflowCount === 0 && overflowBtn) {
205-
overflowBtn.style.display = 'none';
206-
}
179+
if (overflowDivider) overflowDivider.style.display = overflowCount > 0 ? 'block' : 'none';
180+
if (overflowCount === 0 && overflowBtn) overflowBtn.style.display = 'none';
207181
}
208182

209183
// Close dropdown when clicking outside

cms/templates/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ <h1 class="logo-title">Way-CMS</h1>
283283
</div>
284284
<div class="header-actions" id="header-actions">
285285
<div class="header-actions-main" id="header-actions-main">
286-
<!-- Pinned buttons (always visible) -->
287-
<button class="btn btn-primary header-action-btn is-pinned" onclick="downloadCurrentFolder()" data-overflow-key="zip-export" data-overflow-label="📦 ZIP Export">📦 ZIP Export</button>
288-
<button class="btn btn-primary header-action-btn is-pinned" onclick="showUploadZipDialog()" data-overflow-key="zip-import" data-overflow-label="📤 ZIP Import">📤 ZIP Import</button>
286+
<!-- Primary buttons (can overflow on small screens) -->
287+
<button class="btn btn-primary header-action-btn is-overflowable" onclick="downloadCurrentFolder()" data-overflow-key="zip-export" data-overflow-label="📦 ZIP Export">📦 ZIP Export</button>
288+
<button class="btn btn-primary header-action-btn is-overflowable" onclick="showUploadZipDialog()" data-overflow-key="zip-import" data-overflow-label="📤 ZIP Import">📤 ZIP Import</button>
289289

290290
<!-- Overflowable buttons (auto-moved into More when needed) -->
291291
<button class="btn btn-secondary header-action-btn is-overflowable" onclick="toggleSearch()" data-overflow-key="search" data-overflow-label="🔍 Search">🔍 Search</button>

0 commit comments

Comments
 (0)