diff --git a/_posts/tests/2011-05-18-centered-masonry.html b/_posts/tests/2011-05-18-centered-masonry.html index c303183..431befb 100644 --- a/_posts/tests/2011-05-18-centered-masonry.html +++ b/_posts/tests/2011-05-18-centered-masonry.html @@ -85,18 +85,21 @@ category: tests }; $.Isotope.prototype._masonryGetContainerSize = function() { - var itemsTotalWidth = 0; - this.$filteredAtoms.each(function(){ - itemsTotalWidth += $(this).outerWidth(true); - }); + var unusedCols = 0, + i = this.masonry.cols; + // count unused columns + while ( --i ) { + if ( this.masonry.colYs[i] !== 0 ) { + break; + } + unusedCols++; + } - var layoutWidth = this.masonry.cols * this.masonry.columnWidth, - size = { + return { height : Math.max.apply( Math, this.masonry.colYs ), - width : Math.min(layoutWidth, itemsTotalWidth ) + // fit container to columns that have been used; + width : (this.masonry.cols - unusedCols) * this.masonry.columnWidth }; - return size; - };