Skip to content

Commit

Permalink
👷 build v4.2.0 with horizontalOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Apr 20, 2017
1 parent 389863a commit dec5a38
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 45 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ See [masonry.desandro.com](http://masonry.desandro.com) for complete docs and de
Link directly to Masonry files on [unpkg](https://unpkg.com/).

``` html
<script src="https://unpkg.com/masonry-layout@4.1/dist/masonry.pkgd.js"></script>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.js"></script>
<!-- or -->
<script src="https://unpkg.com/masonry-layout@4.1/dist/masonry.pkgd.min.js"></script>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
```

### Package managers
Expand Down
104 changes: 70 additions & 34 deletions dist/masonry.pkgd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry PACKAGED v4.1.1
* Masonry PACKAGED v4.2.0
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down Expand Up @@ -471,7 +471,7 @@ return getSize;
});

/**
* matchesSelector v2.0.1
* matchesSelector v2.0.2
* matchesSelector( element, '.selector' )
* MIT license
*/
Expand All @@ -497,7 +497,7 @@ return getSize;
'use strict';

var matchesMethod = ( function() {
var ElemProto = Element.prototype;
var ElemProto = window.Element.prototype;
// check for the standard method name first
if ( ElemProto.matches ) {
return 'matches';
Expand Down Expand Up @@ -525,7 +525,7 @@ return getSize;
}));

/**
* Fizzy UI utils v2.0.2
* Fizzy UI utils v2.0.4
* MIT license
*/

Expand Down Expand Up @@ -586,7 +586,8 @@ utils.makeArray = function( obj ) {
if ( Array.isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( obj && typeof obj.length == 'number' ) {
} else if ( obj && typeof obj == 'object' &&
typeof obj.length == 'number' ) {
// convert nodeList to array
for ( var i=0; i < obj.length; i++ ) {
ary.push( obj[i] );
Expand Down Expand Up @@ -698,7 +699,8 @@ utils.debounceMethod = function( _class, methodName, threshold ) {
utils.docReady = function( callback ) {
var readyState = document.readyState;
if ( readyState == 'complete' || readyState == 'interactive' ) {
callback();
// do async to allow for other scripts to run. metafizzy/flickity#441
setTimeout( callback );
} else {
document.addEventListener( 'DOMContentLoaded', callback );
}
Expand Down Expand Up @@ -746,7 +748,7 @@ utils.htmlInit = function( WidgetClass, namespace ) {
}
// initialize
var instance = new WidgetClass( elem, options );
// make available via $().data('layoutname')
// make available via $().data('namespace')
if ( jQuery ) {
jQuery.data( elem, namespace, instance );
}
Expand Down Expand Up @@ -2256,7 +2258,7 @@ return Outlayer;
}));

/*!
* Masonry v4.1.1
* Masonry v4.2.0
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down Expand Up @@ -2298,7 +2300,9 @@ return Outlayer;
// isFitWidth -> fitWidth
Masonry.compatOptions.fitWidth = 'isFitWidth';

Masonry.prototype._resetLayout = function() {
var proto = Masonry.prototype;

proto._resetLayout = function() {
this.getSize();
this._getMeasurement( 'columnWidth', 'outerWidth' );
this._getMeasurement( 'gutter', 'outerWidth' );
Expand All @@ -2311,9 +2315,10 @@ return Outlayer;
}

this.maxY = 0;
this.horizontalColIndex = 0;
};

Masonry.prototype.measureColumns = function() {
proto.measureColumns = function() {
this.getContainerWidth();
// if columnWidth is 0, default to outerWidth of first item
if ( !this.columnWidth ) {
Expand All @@ -2338,7 +2343,7 @@ return Outlayer;
this.cols = Math.max( cols, 1 );
};

Masonry.prototype.getContainerWidth = function() {
proto.getContainerWidth = function() {
// container is parent if fit width
var isFitWidth = this._getOption('fitWidth');
var container = isFitWidth ? this.element.parentNode : this.element;
Expand All @@ -2348,41 +2353,49 @@ return Outlayer;
this.containerWidth = size && size.innerWidth;
};

Masonry.prototype._getItemLayoutPosition = function( item ) {
proto._getItemLayoutPosition = function( item ) {
item.getSize();
// how many columns does this brick span
var remainder = item.size.outerWidth % this.columnWidth;
var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
// round if off by 1 pixel, otherwise use ceil
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
colSpan = Math.min( colSpan, this.cols );

var colGroup = this._getColGroup( colSpan );
// get the minimum Y value from the columns
var minimumY = Math.min.apply( Math, colGroup );
var shortColIndex = colGroup.indexOf( minimumY );

// use horizontal or top column position
var colPosMethod = this.options.horizontalOrder ?
'_getHorizontalColPosition' : '_getTopColPosition';
var colPosition = this[ colPosMethod ]( colSpan, item );
// position the brick
var position = {
x: this.columnWidth * shortColIndex,
y: minimumY
x: this.columnWidth * colPosition.col,
y: colPosition.y
};

// apply setHeight to necessary columns
var setHeight = minimumY + item.size.outerHeight;
var setSpan = this.cols + 1 - colGroup.length;
for ( var i = 0; i < setSpan; i++ ) {
this.colYs[ shortColIndex + i ] = setHeight;
var setHeight = colPosition.y + item.size.outerHeight;
var setMax = colSpan + colPosition.col;
for ( var i = colPosition.col; i < setMax; i++ ) {
this.colYs[i] = setHeight;
}

return position;
};

proto._getTopColPosition = function( colSpan ) {
var colGroup = this._getTopColGroup( colSpan );
// get the minimum Y value from the columns
var minimumY = Math.min.apply( Math, colGroup );

return {
col: colGroup.indexOf( minimumY ),
y: minimumY,
};
};

/**
* @param {Number} colSpan - number of columns the element spans
* @returns {Array} colGroup
*/
Masonry.prototype._getColGroup = function( colSpan ) {
proto._getTopColGroup = function( colSpan ) {
if ( colSpan < 2 ) {
// if brick spans only one column, use all the column Ys
return this.colYs;
Expand All @@ -2393,15 +2406,38 @@ return Outlayer;
var groupCount = this.cols + 1 - colSpan;
// for each group potential horizontal position
for ( var i = 0; i < groupCount; i++ ) {
// make an array of colY values for that one group
var groupColYs = this.colYs.slice( i, i + colSpan );
// and get the max value of the array
colGroup[i] = Math.max.apply( Math, groupColYs );
colGroup[i] = this._getColGroupY( i, colSpan );
}
return colGroup;
};

Masonry.prototype._manageStamp = function( stamp ) {
proto._getColGroupY = function( col, colSpan ) {
if ( colSpan < 2 ) {
return this.colYs[ col ];
}
// make an array of colY values for that one group
var groupColYs = this.colYs.slice( col, col + colSpan );
// and get the max value of the array
return Math.max.apply( Math, groupColYs );
};

// get column position based on horizontal index. #873
proto._getHorizontalColPosition = function( colSpan, item ) {
var col = this.horizontalColIndex % this.cols;
var isOver = colSpan > 1 && col + colSpan > this.cols;
// shift to next row if item can't fit on current row
col = isOver ? 0 : col;
// don't let zero-size items take up space
var hasSize = item.size.outerWidth && item.size.outerHeight;
this.horizontalColIndex = hasSize ? col + colSpan : this.horizontalColIndex;

return {
col: col,
y: this._getColGroupY( col, colSpan ),
};
};

proto._manageStamp = function( stamp ) {
var stampSize = getSize( stamp );
var offset = this._getElementOffset( stamp );
// get the columns that this stamp affects
Expand All @@ -2424,7 +2460,7 @@ return Outlayer;
}
};

Masonry.prototype._getContainerSize = function() {
proto._getContainerSize = function() {
this.maxY = Math.max.apply( Math, this.colYs );
var size = {
height: this.maxY
Expand All @@ -2437,7 +2473,7 @@ return Outlayer;
return size;
};

Masonry.prototype._getContainerFitWidth = function() {
proto._getContainerFitWidth = function() {
var unusedCols = 0;
// count unused columns
var i = this.cols;
Expand All @@ -2451,7 +2487,7 @@ return Outlayer;
return ( this.cols - unusedCols ) * this.columnWidth - this.gutter;
};

Masonry.prototype.needsResizeLayout = function() {
proto.needsResizeLayout = function() {
var previousWidth = this.containerWidth;
this.getContainerWidth();
return previousWidth != this.containerWidth;
Expand Down
4 changes: 2 additions & 2 deletions dist/masonry.pkgd.min.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@ gulp.task( 'version', function() {
gulp.src( [ 'package.json' ] )
.pipe( replace( /"version": "\d\.\d+\.\d+"/, '"version": "' + version + '"' ) )
.pipe( gulp.dest('.') );
// replace CDN links in README
var minorVersion = version.match( /^\d\.\d+/ )[0];
gulp.src('README.md')
.pipe( replace( /masonry\-layout@\d\.\d+/g, 'masonry-layout@' + minorVersion ))
.pipe( gulp.dest('.') );
});

// ----- default ----- //
Expand Down
2 changes: 1 addition & 1 deletion masonry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry v4.1.1
* Masonry v4.2.0
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "masonry-layout",
"version": "4.1.1",
"version": "4.2.0",
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
Expand Down

0 comments on commit dec5a38

Please sign in to comment.