Skip to content

Instantly share code, notes, and snippets.

@mgibbs189
Created August 7, 2018 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgibbs189/4264bdd3e3c5ac558aebce5a0408b719 to your computer and use it in GitHub Desktop.
Save mgibbs189/4264bdd3e3c5ac558aebce5a0408b719 to your computer and use it in GitHub Desktop.
FacetWP - Masonry with the layout builder?
function resizeGridItem(item){
grid = document.getElementsByClassName("fwpl-layout")[0];
rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'));
rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap'));
rowSpan = Math.ceil((item.querySelector('.fwpl-row').getBoundingClientRect().height+rowGap)/(rowHeight+rowGap));
item.style.gridRowEnd = "span "+rowSpan;
}
function resizeAllGridItems(){
allItems = document.getElementsByClassName("fwpl-result");
for(x=0;x<allItems.length;x++){
resizeGridItem(allItems[x]);
}
}
function resizeInstance(instance){
item = instance.elements[0];
resizeGridItem(item);
}
window.onload = resizeAllGridItems();
window.addEventListener("resize", resizeAllGridItems);
allItems = document.getElementsByClassName("fwpl-result");
for(x=0;x<allItems.length;x++){
imagesLoaded( allItems[x], resizeInstance);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment