Skip to content

Commit 5b22991

Browse files
committed
v1.4.0
1 parent c4b5f7f commit 5b22991

File tree

6 files changed

+48
-23
lines changed

6 files changed

+48
-23
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Minimalist dependency free Masonry layout library
66

77
MiniMasonry is a **lightweight** dependency free Masonry layout. It will compute elements position in JavaScript and update their positions using CSS's **transform attribute**. This means positioning does not trigger browser layout and **use** the device's **GPU**. This also allows CSS animation during element positioning.
88

9-
MiniMasonry is **responsive**, you give it a target width and it will adjust columns number and elements width. MiniMasonry will increase element width (until another column can fit in the layout) but will never reduce the target width.
9+
MiniMasonry is **responsive** by default, you give it a target width and it will adjust columns number and elements width. MiniMasonry will increase element width (until another column can fit in the layout) but will never reduce the target width.
1010

1111
## Installation
1212

@@ -27,7 +27,7 @@ import MiniMasonry from "minimasonry";
2727

2828
## Usage
2929

30-
To use MiniMasonry you should have a container **relatively positioned** with your elements as children. Those **children** elements must be **absolutely positioned**.
30+
⚠️ To use MiniMasonry you should have a container **relatively positioned** with your elements as children. Those **children** elements must be **absolutely positioned**.
3131

3232
Then you can initialise MiniMasonry :
3333

@@ -52,6 +52,7 @@ surroundingGutter (boolean)|true|Set left gutter on first columns and right gutt
5252
ultimateGutter (int)|5|Gutter applied when only 1 column can be displayed.
5353
direction (string)|"ltr"|Sorting direction, "ltr" or "rtl".
5454
wedge (boolean)|false|False will start to sort from center, true will start from left or right according to direction parameter.
55+
responsive (boolean)|true|True will add a "resize" event listener on the window to redraw the masonry on window resize. This listener is throttled to 66ms (15fps).
5556

5657
## API
5758

@@ -60,9 +61,7 @@ Here is the list of available APIs :
6061
Name|Description
6162
----|-----------
6263
layout()|If list has changed, trigger a relayout of the masonry.
63-
destroy()|Remove the resize listener and set back container as it was before initialization.
64-
65-
MiniMasonry will add a "resize" event listener on the window to redraw the masonry on window resize. This listener is throttled to 66ms (15fps).
64+
destroy()|Remove the resize listener if any and set back container as it was before initialization.
6665

6766
## Example
6867

build/minimasonry.esm.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var MiniMasonry = function(conf) {
2020
ultimateGutter: 5,
2121
surroundingGutter: true,
2222
direction: 'ltr',
23-
wedge: false
23+
wedge: false,
24+
responsive: true,
2425
};
2526

2627
this.init(conf);
@@ -38,12 +39,9 @@ MiniMasonry.prototype.init = function(conf) {
3839
if (this.conf.gutterX == null || this.conf.gutterY == null) {
3940
this.conf.gutterX = this.conf.gutterY = this.conf.gutter;
4041
}
41-
4242
this._currentGutterX = this.conf.gutterX;
4343
this._currentGutterY = this.conf.gutterY;
4444

45-
console.log(this._currentGutterX);
46-
4745
this._container = typeof this.conf.container == 'object' && this.conf.container.nodeName ?
4846
this.conf.container :
4947
document.querySelector(this.conf.container);
@@ -52,11 +50,13 @@ MiniMasonry.prototype.init = function(conf) {
5250
throw new Error('Container not found or missing');
5351
}
5452

55-
var onResize = this.resizeThrottler.bind(this);
56-
window.addEventListener("resize", onResize);
57-
this._removeListener = function() {
58-
window.removeEventListener("resize", onResize);
59-
};
53+
if(this.config.responsive) {
54+
var onResize = this.resizeThrottler.bind(this);
55+
window.addEventListener("resize", onResize);
56+
this._removeListener = function() {
57+
window.removeEventListener("resize", onResize);
58+
};
59+
}
6060

6161
this.layout();
6262
};

build/minimasonry.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
declare module 'minimasonry' {
2+
export interface MiniMasonryOptions {
3+
container: string | ReturnType<typeof document.querySelector>;
4+
baseWidth?: number;
5+
gutter?: number;
6+
gutterX?: number;
7+
gutterY?: number;
8+
minify?: boolean;
9+
surroundingGutter?: boolean;
10+
ultimateGutter?: number;
11+
direction?: 'ltr' | 'rtl';
12+
wedge?: boolean;
13+
responsive?: boolean;
14+
}
15+
16+
export default class MiniMasonry {
17+
constructor(opts: MiniMasonryOptions);
18+
19+
layout(): void;
20+
destroy(): void;
21+
}
22+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "minimasonry",
33
"description": "Minimalist dependancy free Masonry layout library",
4-
"version": "1.3.1",
4+
"version": "1.4.0",
55
"devDependencies": {
66
"@rollup/plugin-commonjs": "^21.0.1",
77
"rollup": "^2.58.3",
@@ -13,6 +13,7 @@
1313
},
1414
"main": "build/minimasonry.min.js",
1515
"module": "build/minimasonry.esm.js",
16+
"types": "index.d.ts",
1617
"dependencies": {},
1718
"repository": {
1819
"type": "git",

src/minimasonry.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ var MiniMasonry = function(conf) {
2020
ultimateGutter: 5,
2121
surroundingGutter: true,
2222
direction: 'ltr',
23-
wedge: false
23+
wedge: false,
24+
responsive: true,
2425
};
2526

2627
this.init(conf);
@@ -49,10 +50,12 @@ MiniMasonry.prototype.init = function(conf) {
4950
throw new Error('Container not found or missing');
5051
}
5152

52-
var onResize = this.resizeThrottler.bind(this)
53-
window.addEventListener("resize", onResize);
54-
this._removeListener = function() {
55-
window.removeEventListener("resize", onResize);
53+
if(this.config.responsive) {
54+
var onResize = this.resizeThrottler.bind(this)
55+
window.addEventListener("resize", onResize);
56+
this._removeListener = function() {
57+
window.removeEventListener("resize", onResize);
58+
}
5659
}
5760

5861
this.layout();
@@ -213,8 +216,8 @@ MiniMasonry.prototype.resizeThrottler = function() {
213216
if (this._container.clientWidth != this._width) {
214217
this.layout();
215218
}
216-
// The actualResizeHandler will execute at a rate of 30fps
217-
}.bind(this), 33);
219+
// The actualResizeHandler will execute at a rate of 15fps
220+
}.bind(this), 66);
218221
}
219222
}
220223

0 commit comments

Comments
 (0)