Skip to content

Commit ba51343

Browse files
Hopefully fixed media box arrangement?
1 parent 60c596f commit ba51343

1 file changed

Lines changed: 45 additions & 42 deletions

File tree

_pages/media.html

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
border-color: #d1d5da !important;
3131
}
3232

33-
/* Grid container with tighter spacing */
33+
/* Grid container with separate horizontal and vertical gaps */
3434
body .media-page .media-grid,
3535
.media-grid {
3636
display: grid !important;
3737
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 */
4041
align-items: start !important;
4142
width: 100% !important;
4243
max-width: none !important;
@@ -80,26 +81,10 @@
8081
border-radius: 4px !important;
8182
margin-bottom: 0.5rem !important;
8283
}
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-
}
9784
</style>
9885

9986
<h1>Media</h1>
10087

101-
<div class="debug-info" id="debug-info">HTML loaded</div>
102-
10388
<section class="media-grid">
10489
{% assign media_items = site.media | sort: "date" | reverse %}
10590
{% for item in media_items %}
@@ -134,38 +119,56 @@ <h3 class="archive__item-title">
134119
{% endfor %}
135120
</section>
136121

137-
<!-- Minimal test script -->
138122
<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() {
143124
var grid = document.querySelector('.media-grid');
144125
var items = grid.querySelectorAll('.media-card');
145126

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)
147130

131+
// Reset all items first
148132
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';
152134
}
153135

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;
160138

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+
}
169172
</script>
170173

171174
<script async src="https://www.instagram.com/embed.js"></script>

0 commit comments

Comments
 (0)