|
30 | 30 | border-color: #d1d5da !important; |
31 | 31 | } |
32 | 32 |
|
33 | | - /* Grid container with tighter spacing */ |
| 33 | + /* Grid container with separate horizontal and vertical gaps */ |
34 | 34 | body .media-page .media-grid, |
35 | 35 | .media-grid { |
36 | 36 | display: grid !important; |
37 | 37 | grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important; |
38 | | - grid-auto-rows: 10px !important; |
39 | | - gap: 12px !important; |
| 38 | + grid-auto-rows: 20px !important; /* Row height for masonry calculation */ |
| 39 | + row-gap: 1px !important; /* Vertical gap between rows */ |
| 40 | + column-gap: 20px !important; /* Horizontal gap between columns */ |
40 | 41 | align-items: start !important; |
41 | 42 | width: 100% !important; |
42 | 43 | max-width: none !important; |
|
80 | 81 | border-radius: 4px !important; |
81 | 82 | margin-bottom: 0.5rem !important; |
82 | 83 | } |
83 | | - |
84 | | - /* Production debugging */ |
85 | | - .debug-info { |
86 | | - position: fixed; |
87 | | - top: 10px; |
88 | | - right: 10px; |
89 | | - background: rgba(255,0,0,0.9); |
90 | | - color: white; |
91 | | - padding: 10px; |
92 | | - font-size: 12px; |
93 | | - z-index: 9999; |
94 | | - max-width: 300px; |
95 | | - border: 2px solid yellow; |
96 | | - } |
97 | 84 | </style> |
98 | 85 |
|
99 | 86 | <h1>Media</h1> |
100 | 87 |
|
101 | | -<div class="debug-info" id="debug-info">HTML loaded</div> |
102 | | - |
103 | 88 | <section class="media-grid"> |
104 | 89 | {% assign media_items = site.media | sort: "date" | reverse %} |
105 | 90 | {% for item in media_items %} |
@@ -134,38 +119,56 @@ <h3 class="archive__item-title"> |
134 | 119 | {% endfor %} |
135 | 120 | </section> |
136 | 121 |
|
137 | | -<!-- Minimal test script --> |
138 | 122 | <script> |
139 | | -document.getElementById('debug-info').innerHTML = 'JS executing'; |
140 | | -document.getElementById('debug-info').style.background = 'rgba(0,255,0,0.9)'; |
141 | | - |
142 | | -setTimeout(function() { |
| 123 | +function applyMasonry() { |
143 | 124 | var grid = document.querySelector('.media-grid'); |
144 | 125 | var items = grid.querySelectorAll('.media-card'); |
145 | 126 |
|
146 | | - document.getElementById('debug-info').innerHTML = 'Found ' + items.length + ' items'; |
| 127 | + var rowHeight = 20; // Match CSS grid-auto-rows |
| 128 | + var verticalGap = 1; // Match CSS row-gap |
| 129 | + var horizontalGap = 20; // Match CSS column-gap (not used in calculation) |
147 | 130 |
|
| 131 | + // Reset all items first |
148 | 132 | for (var i = 0; i < items.length; i++) { |
149 | | - var rect = items[i].getBoundingClientRect(); |
150 | | - var rowSpan = Math.ceil((rect.height + 12) / 10); |
151 | | - items[i].style.gridRowEnd = 'span ' + Math.max(1, rowSpan); |
| 133 | + items[i].style.gridRowEnd = 'auto'; |
152 | 134 | } |
153 | 135 |
|
154 | | - document.getElementById('debug-info').innerHTML = 'Masonry applied'; |
155 | | -}, 1000); |
156 | | - |
157 | | -setTimeout(function() { |
158 | | - var grid = document.querySelector('.media-grid'); |
159 | | - var items = grid.querySelectorAll('.media-card'); |
| 136 | + // Force reflow |
| 137 | + grid.offsetHeight; |
160 | 138 |
|
161 | | - for (var i = 0; i < items.length; i++) { |
162 | | - var rect = items[i].getBoundingClientRect(); |
163 | | - var rowSpan = Math.ceil((rect.height + 12) / 10); |
164 | | - items[i].style.gridRowEnd = 'span ' + Math.max(1, rowSpan); |
165 | | - } |
166 | | - |
167 | | - document.getElementById('debug-info').innerHTML = 'Second masonry pass'; |
168 | | -}, 3000); |
| 139 | + // Calculate spans |
| 140 | + setTimeout(function() { |
| 141 | + for (var i = 0; i < items.length; i++) { |
| 142 | + var rect = items[i].getBoundingClientRect(); |
| 143 | + var itemHeight = rect.height; |
| 144 | + |
| 145 | + // Only use vertical gap in calculation since that's what affects row spans |
| 146 | + var rowSpan = Math.ceil((itemHeight + verticalGap) / rowHeight); |
| 147 | + |
| 148 | + items[i].style.gridRowEnd = 'span ' + rowSpan; |
| 149 | + } |
| 150 | + }, 100); |
| 151 | +} |
| 152 | + |
| 153 | +// Apply masonry multiple times to handle loading content |
| 154 | +setTimeout(applyMasonry, 500); |
| 155 | +setTimeout(applyMasonry, 1500); |
| 156 | +setTimeout(applyMasonry, 3000); |
| 157 | +setTimeout(applyMasonry, 5000); |
| 158 | + |
| 159 | +window.addEventListener('resize', function() { |
| 160 | + setTimeout(applyMasonry, 200); |
| 161 | +}); |
| 162 | + |
| 163 | +// Handle Instagram embeds |
| 164 | +if (window.instgrm) { |
| 165 | + setTimeout(function() { |
| 166 | + if (window.instgrm.Embeds) { |
| 167 | + window.instgrm.Embeds.process(); |
| 168 | + setTimeout(applyMasonry, 2000); |
| 169 | + } |
| 170 | + }, 1000); |
| 171 | +} |
169 | 172 | </script> |
170 | 173 |
|
171 | 174 | <script async src="https://www.instagram.com/embed.js"></script> |
0 commit comments