diff --git a/src/minimasonry.js b/src/minimasonry.js index 1571f1b..2eb63b2 100644 --- a/src/minimasonry.js +++ b/src/minimasonry.js @@ -5,18 +5,19 @@ var MiniMasonry = function(conf) { this._count = null; this._width = 0; - this._resizeTimeout = null, - - this.conf = { - baseWidth: 255, - gutterX: null, - gutterY: null, - gutter: 10, - container: null, - minify: true, - ultimateGutter: 5, - surroundingGutter: true - }; + this._resizeTimeout = null; + + this.conf = { + baseWidth: 255, + gutterX: null, + gutterY: null, + gutter: 10, + container: null, + minify: true, + ultimateGutter: 5, + surroundingGutter: true, + center: true + }; this.init(conf); @@ -29,6 +30,8 @@ MiniMasonry.prototype.init = function(conf) { this.conf[i] = conf[i]; } } + this._gutterX = this.conf.gutterX; + if (this.conf.gutterX == null || this.conf.gutterY == null) { this.conf.gutterX = this.conf.gutterY = this.conf.gutter; } @@ -53,11 +56,13 @@ MiniMasonry.prototype.reset = function() { this._container.style.minWidth = minWidth + 'px'; } - if (this.getCount() == 1) { + if (this.getCount() === 1) { // Set ultimate gutter when only one column is displayed this.conf.gutterX = this.conf.ultimateGutter; // As gutters are reduced, to column may fit, forcing to 1 this._count = 1; + } else { + this.conf.gutterX = this._gutterX ?? this.conf.gutter; } if (this._width < (this.conf.baseWidth + (2 * this.conf.gutterX))) { @@ -113,7 +118,7 @@ MiniMasonry.prototype.layout = function() { } var initialLeft = this.conf.surroundingGutter ? this.conf.gutterX : 0; - if (this._count > this._sizes.length) { + if (this._count > this._sizes.length && this.conf.center) { //If more columns than children var occupiedSpace = (this._sizes.length * (width + this.conf.gutterX)) - this.conf.gutterX; initialLeft = ((this._width - occupiedSpace) / 2); @@ -175,7 +180,7 @@ MiniMasonry.prototype.resizeThrottler = function() { if (this._container.clientWidth != this._width) { this.layout(); } - // The actualResizeHandler will execute at a rate of 30fps + // The actualResizeHandler will execute at a rate of 30fps }.bind(this), 33); } }