Skip to content

Commit 1a0c1c1

Browse files
authored
Details: re-layout masonry when fields are resized (#2908)
resolves #2898
1 parent beef36e commit 1a0c1c1

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

dt-assets/js/details.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/*
2+
global ResizeObserver
3+
*/
14
'use strict';
25
jQuery(document).ready(function ($) {
36
let post_id = window.detailsSettings.post_id;
@@ -1249,6 +1252,22 @@ jQuery(document).ready(function ($) {
12491252
service.initialize();
12501253
window.componentService = service;
12511254
}
1255+
1256+
// When components are resized, re-layout the masonry grid
1257+
const targetElement = document.querySelectorAll('.grid .bordered-box .cell');
1258+
let resizeTimeout;
1259+
const resizeObserver = new ResizeObserver((entries) => {
1260+
for (let entry of entries) {
1261+
// many of these can be triggered on initial load, so debounce them with a timeout
1262+
clearTimeout(resizeTimeout);
1263+
resizeTimeout = setTimeout(() => {
1264+
window.masonGrid.masonry('layout');
1265+
}, 100);
1266+
}
1267+
});
1268+
for (let element of targetElement) {
1269+
resizeObserver.observe(element);
1270+
}
12521271
});
12531272

12541273
// change update needed notification and switch if needed.

0 commit comments

Comments
 (0)