File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ global ResizeObserver
3+ */
14'use strict' ;
25jQuery ( 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.
You can’t perform that action at this time.
0 commit comments