Skip to content

Commit

Permalink
fallback to columnWidth = innerWidth;
Browse files Browse the repository at this point in the history
Fixes #358

tick version
  • Loading branch information
desandro committed Jun 24, 2013
1 parent 32033bf commit ab600d0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "masonry",
"version": "3.0.0",
"version": "3.0.1",
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
Expand Down
12 changes: 9 additions & 3 deletions masonry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry v3.0.0
* Masonry v3.0.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down Expand Up @@ -54,8 +54,14 @@ function masonryDefinition( Outlayer, getSize ) {

Masonry.prototype.measureColumns = function() {
// if columnWidth is 0, default to outerWidth of first item
var firstItemElem = this.items[0].element;
this.columnWidth = this.columnWidth || getSize( firstItemElem ).outerWidth;
var firstItem = this.items[0];
var firstItemElem = firstItem && firstItem.element;
if ( !this.columnWidth ) {
// columnWidth fall back to item of first element
this.columnWidth = firstItemElem ? getSize( firstItemElem ).outerWidth :
// or size of container
this.size.innerWidth;
}
this.columnWidth += this.gutter;

this.cols = Math.floor( ( this.size.innerWidth + this.gutter ) / this.columnWidth );
Expand Down
9 changes: 9 additions & 0 deletions test/empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test( 'empty', function() {

var container = document.querySelector('#empty');
var msnry = new Masonry( container );

ok( true, 'empty masonry did not throw error' );
equal( msnry.columnWidth, getSize( container ).innerWidth, 'columnWidth = innerWidth' );

});
4 changes: 4 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<script src="basic-layout.js"></script>
<script src="gutter.js"></script>
<script src="stamp.js"></script>
<script src="empty.js"></script>

</head>
<body>
Expand Down Expand Up @@ -99,5 +100,8 @@ <h2>Stamp</h2>
<div class="item"></div>
</div>

<h2>Empty</h2>
<div id="empty" class="container"></div>

</body>
</html>

0 comments on commit ab600d0

Please sign in to comment.