|
86 | 86 | position: fixed; |
87 | 87 | top: 10px; |
88 | 88 | right: 10px; |
89 | | - background: rgba(0,0,0,0.8); |
| 89 | + background: rgba(255,0,0,0.9); |
90 | 90 | color: white; |
91 | 91 | padding: 10px; |
92 | 92 | font-size: 12px; |
93 | 93 | z-index: 9999; |
94 | 94 | max-width: 300px; |
| 95 | + border: 2px solid yellow; |
95 | 96 | } |
96 | 97 | </style> |
97 | 98 |
|
98 | 99 | <h1>Media</h1> |
99 | 100 |
|
100 | 101 | <!-- Debug info for production --> |
101 | 102 | <div class="debug-info" id="debug-info"> |
102 | | - Initializing... |
| 103 | + HTML loaded |
103 | 104 | </div> |
104 | 105 |
|
105 | 106 | <section class="media-grid"> |
@@ -137,110 +138,72 @@ <h3 class="archive__item-title"> |
137 | 138 | </section> |
138 | 139 |
|
139 | 140 | <script> |
140 | | -// Simplified version with error handling |
141 | | -try { |
142 | | - let masonryAttempts = 0; |
143 | | - |
| 141 | +(function() { |
| 142 | + var debug = document.getElementById('debug-info'); |
| 143 | + |
144 | 144 | function updateDebug(message) { |
145 | | - try { |
146 | | - const debug = document.getElementById('debug-info'); |
147 | | - if (debug) { |
148 | | - debug.innerHTML = `${message}<br>Time: ${new Date().toLocaleTimeString()}`; |
149 | | - } |
150 | | - } catch (e) { |
151 | | - console.error('Debug update error:', e); |
| 145 | + if (debug) { |
| 146 | + debug.innerHTML = message + '<br>Time: ' + new Date().toLocaleTimeString(); |
| 147 | + debug.style.background = 'rgba(0,255,0,0.9)'; // Green when working |
152 | 148 | } |
153 | 149 | } |
154 | 150 |
|
155 | | - // Test basic functionality first |
156 | | - updateDebug('Script loaded successfully'); |
| 151 | + updateDebug('JavaScript executing'); |
157 | 152 |
|
158 | 153 | function masonryLayout() { |
159 | | - try { |
160 | | - const grid = document.querySelector('.media-grid'); |
161 | | - if (!grid) { |
162 | | - updateDebug('Grid not found'); |
163 | | - return; |
164 | | - } |
165 | | - |
166 | | - const items = grid.querySelectorAll('.media-card'); |
167 | | - masonryAttempts++; |
168 | | - |
169 | | - updateDebug(`Attempt ${masonryAttempts}: Found ${items.length} items`); |
170 | | - |
171 | | - const rowHeight = 10; |
172 | | - const gap = 12; |
173 | | - |
174 | | - // Reset all items |
175 | | - items.forEach(item => { |
176 | | - item.style.gridRowEnd = 'auto'; |
177 | | - }); |
178 | | - |
179 | | - // Force reflow |
180 | | - grid.offsetHeight; |
181 | | - |
182 | | - // Calculate row spans |
183 | | - items.forEach((item, index) => { |
184 | | - const rect = item.getBoundingClientRect(); |
185 | | - const itemHeight = rect.height; |
186 | | - const rowSpan = Math.ceil((itemHeight + gap) / (rowHeight + gap)); |
187 | | - item.style.gridRowEnd = `span ${Math.max(1, rowSpan)}`; |
188 | | - }); |
189 | | - |
190 | | - updateDebug(`Attempt ${masonryAttempts}: Layout applied`); |
191 | | - |
192 | | - } catch (e) { |
193 | | - updateDebug(`Error in masonry: ${e.message}`); |
194 | | - console.error('Masonry error:', e); |
| 154 | + var grid = document.querySelector('.media-grid'); |
| 155 | + if (!grid) { |
| 156 | + updateDebug('ERROR: Grid not found'); |
| 157 | + return; |
| 158 | + } |
| 159 | + |
| 160 | + var items = grid.querySelectorAll('.media-card'); |
| 161 | + updateDebug('Processing ' + items.length + ' cards'); |
| 162 | + |
| 163 | + var rowHeight = 10; |
| 164 | + var gap = 12; |
| 165 | + |
| 166 | + // Reset all items |
| 167 | + for (var i = 0; i < items.length; i++) { |
| 168 | + items[i].style.gridRowEnd = 'auto'; |
| 169 | + } |
| 170 | + |
| 171 | + // Force reflow |
| 172 | + grid.offsetHeight; |
| 173 | + |
| 174 | + // Apply masonry |
| 175 | + for (var i = 0; i < items.length; i++) { |
| 176 | + var rect = items[i].getBoundingClientRect(); |
| 177 | + var itemHeight = rect.height; |
| 178 | + var rowSpan = Math.ceil((itemHeight + gap) / (rowHeight + gap)); |
| 179 | + items[i].style.gridRowEnd = 'span ' + Math.max(1, rowSpan); |
195 | 180 | } |
| 181 | + |
| 182 | + updateDebug('Masonry layout applied successfully'); |
196 | 183 | } |
197 | 184 |
|
198 | | - // Simple initialization |
199 | | - function initMasonry() { |
| 185 | + function init() { |
200 | 186 | updateDebug('Initializing masonry...'); |
201 | | - setTimeout(masonryLayout, 100); |
202 | | - setTimeout(masonryLayout, 500); |
203 | | - setTimeout(masonryLayout, 1000); |
204 | | - setTimeout(masonryLayout, 2000); |
205 | | - setTimeout(masonryLayout, 4000); |
| 187 | + setTimeout(function() { masonryLayout(); }, 100); |
| 188 | + setTimeout(function() { masonryLayout(); }, 1000); |
| 189 | + setTimeout(function() { masonryLayout(); }, 3000); |
| 190 | + setTimeout(function() { masonryLayout(); }, 6000); |
206 | 191 | } |
207 | 192 |
|
208 | | - // Event listeners |
| 193 | + // Start when DOM is ready |
209 | 194 | if (document.readyState === 'loading') { |
210 | | - document.addEventListener('DOMContentLoaded', initMasonry); |
| 195 | + document.addEventListener('DOMContentLoaded', init); |
211 | 196 | } else { |
212 | | - initMasonry(); |
| 197 | + init(); |
213 | 198 | } |
214 | 199 |
|
215 | | - window.addEventListener('load', () => { |
216 | | - updateDebug('Window loaded'); |
217 | | - setTimeout(initMasonry, 200); |
| 200 | + // Also run when window loads |
| 201 | + window.addEventListener('load', function() { |
| 202 | + updateDebug('Window loaded - running masonry'); |
| 203 | + setTimeout(function() { masonryLayout(); }, 500); |
218 | 204 | }); |
219 | 205 |
|
220 | | - // Handle Instagram embeds if available |
221 | | - setTimeout(() => { |
222 | | - try { |
223 | | - if (window.instgrm && window.instgrm.Embeds) { |
224 | | - updateDebug('Processing Instagram embeds'); |
225 | | - window.instgrm.Embeds.process(); |
226 | | - setTimeout(masonryLayout, 2000); |
227 | | - } |
228 | | - } catch (e) { |
229 | | - updateDebug(`Instagram error: ${e.message}`); |
230 | | - } |
231 | | - }, 2000); |
232 | | - |
233 | | - updateDebug('Script initialization complete'); |
234 | | - |
235 | | -} catch (e) { |
236 | | - // Fallback error reporting |
237 | | - const debug = document.getElementById('debug-info'); |
238 | | - if (debug) { |
239 | | - debug.innerHTML = `Script error: ${e.message}`; |
240 | | - } |
241 | | - console.error('Script initialization error:', e); |
242 | | -} |
| 206 | +})(); |
243 | 207 | </script> |
244 | 208 |
|
245 | | -<!-- Load Instagram script after our script --> |
246 | 209 | <script async src="https://www.instagram.com/embed.js"></script> |
0 commit comments