Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions src/minimasonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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;
}
Expand All @@ -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))) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand Down