masonry-simple 0.0.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/index.js +24 -21
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +24 -21
- package/dist/index.module.js.map +1 -1
- package/package.json +1 -1
- package/src/index.js +26 -28
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
[](https://github.com/ux-ui-pro/masonry-simple)
|
|
8
8
|
[](https://www.npmjs.org/package/masonry-simple)
|
|
9
9
|
|
|
10
|
-
<sup><a href="https://bundlephobia.com/package/masonry-simple">
|
|
10
|
+
<sup><a href="https://bundlephobia.com/package/masonry-simple">0.7kB gzipped</a></sup>
|
|
11
11
|
<h3><a href="https://codepen.io/ux-ui/pen/poxGEqX">Demo</a></h3>
|
|
12
12
|
|
|
13
13
|
</div>
|
|
@@ -31,9 +31,11 @@ import MasonrySimple from 'masonry-simple'
|
|
|
31
31
|
|
|
32
32
|
### Usage
|
|
33
33
|
```javascript
|
|
34
|
-
new MasonrySimple(
|
|
34
|
+
const masonry = new MasonrySimple()
|
|
35
|
+
|
|
36
|
+
masonry.options({
|
|
35
37
|
container: '.masonry',
|
|
36
|
-
|
|
38
|
+
timeout: 200
|
|
37
39
|
})
|
|
38
40
|
```
|
|
39
41
|
```HTML
|
package/dist/index.js
CHANGED
|
@@ -9,36 +9,36 @@ $parcel$defineInteropFlag(module.exports);
|
|
|
9
9
|
|
|
10
10
|
$parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
|
|
11
11
|
class $4fa36e821943b400$export$2e2bcd8739ae039 {
|
|
12
|
-
constructor(
|
|
13
|
-
|
|
12
|
+
constructor(){
|
|
13
|
+
this.grid = null;
|
|
14
|
+
this.gridItems = [];
|
|
15
|
+
this.timeout = 200;
|
|
16
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), this.timeout);
|
|
17
|
+
this.resizeObserver = null;
|
|
18
|
+
}
|
|
19
|
+
options(options = {}) {
|
|
20
|
+
const { container: container = ".masonry" , timeout: timeout = this.timeout } = options;
|
|
14
21
|
this.grid = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
15
|
-
this.gridItems =
|
|
16
|
-
...this.grid.children
|
|
17
|
-
];
|
|
18
|
-
this.resizeObserver = new ResizeObserver(()=>{
|
|
19
|
-
this.resizeAllItems();
|
|
20
|
-
});
|
|
21
|
-
this.resizeObserver.observe(this.grid);
|
|
22
|
-
window.onload = this.resizeAllItems.bind(this);
|
|
23
|
-
window.addEventListener("beforeunload", ()=>{
|
|
24
|
-
this.resizeObserver.unobserve(this.grid);
|
|
25
|
-
});
|
|
22
|
+
this.gridItems = Array.from(this.grid.children);
|
|
26
23
|
this.grid.style.contain = "layout";
|
|
27
|
-
this.
|
|
24
|
+
this.resizeObserver = new ResizeObserver(this.debouncedResize);
|
|
25
|
+
this.resizeObserver.observe(this.grid);
|
|
26
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), timeout);
|
|
27
|
+
this.resizeAllItems();
|
|
28
28
|
}
|
|
29
|
-
resizeItem(item) {
|
|
30
|
-
const rowHeight = 1;
|
|
31
|
-
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
|
|
29
|
+
resizeItem(item, rowHeight, rowGap) {
|
|
32
30
|
const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
|
|
33
31
|
item.style.gridRowEnd = "span " + rowSpan;
|
|
34
32
|
}
|
|
35
33
|
resizeAllItems() {
|
|
34
|
+
const rowHeight = 1;
|
|
35
|
+
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
|
|
36
36
|
this.grid.style.alignItems = "start";
|
|
37
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
37
|
+
this.gridItems.forEach((item)=>this.resizeItem(item, rowHeight, rowGap));
|
|
38
38
|
this.grid.style.alignItems = "stretch";
|
|
39
|
-
|
|
40
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
41
|
-
});
|
|
39
|
+
setTimeout(()=>{
|
|
40
|
+
this.gridItems.forEach((item)=>this.resizeItem(item, rowHeight, rowGap));
|
|
41
|
+
}, 0);
|
|
42
42
|
}
|
|
43
43
|
debounce(func, wait) {
|
|
44
44
|
let timeout;
|
|
@@ -51,6 +51,9 @@ class $4fa36e821943b400$export$2e2bcd8739ae039 {
|
|
|
51
51
|
timeout = setTimeout(later, wait);
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
+
debouncedResize = ()=>{
|
|
55
|
+
this.resizeAllItems();
|
|
56
|
+
};
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAe;IACd,
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAe;IACd,aAAc;QACb,IAAI,CAAC,IAAI,GAAG,IAAI;QAChB,IAAI,CAAC,SAAS,GAAG,EAAE;QACnB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO;QAChF,IAAI,CAAC,cAAc,GAAG,IAAI;IAC3B;IAEA,QAAQ,UAAU,CAAC,CAAC,EAAE;QACrB,MAAM,aACL,YAAY,sBACZ,UAAU,IAAI,CAAC,OAAO,GACtB,GAAG;QAEJ,IAAI,CAAC,IAAI,GAAG,qBAAqB,cAAc,YAAY,SAAS,aAAa,CAAC,UAAU;QAC5F,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ;QAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,eAAe;QAC7D,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;QACrC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG;QACpE,IAAI,CAAC,cAAc;IACpB;IAEA,WAAW,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE;QACnC,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,MAAK,IAAM,CAAA,YAAY,MAAK;QAC3E,KAAK,KAAK,CAAC,UAAU,GAAG,UAAU;IACnC;IAEA,iBAAiB;QAChB,MAAM,YAAY;QAClB,MAAM,SAAS,SAAS,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,WAAW;QAChE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,WAAW,IAAM;YAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,WAAW;QACjE,GAAG;IACJ;IAEA,SAAS,IAAI,EAAE,IAAI,EAAE;QACpB,IAAI;QACJ,OAAO,SAAS,iBAAiB,GAAG,IAAI,EAAE;YACzC,MAAM,QAAQ,IAAM;gBACnB,aAAa;gBACb,QAAQ;YACT;YACA,aAAa;YACb,UAAU,WAAW,OAAO;QAC7B;IACD;IAEA,kBAAkB,IAAM;QACvB,IAAI,CAAC,cAAc;IACpB,EAAC;AACF","sources":["src/index.js"],"sourcesContent":["export default class MasonrySimple {\r\n\tconstructor() {\r\n\t\tthis.grid = null\r\n\t\tthis.gridItems = []\r\n\t\tthis.timeout = 200\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), this.timeout)\r\n\t\tthis.resizeObserver = null\r\n\t}\r\n\r\n\toptions(options = {}) {\r\n\t\tconst {\r\n\t\t\tcontainer = '.masonry',\r\n\t\t\ttimeout = this.timeout\r\n\t\t} = options\r\n\r\n\t\tthis.grid = container instanceof HTMLElement ? container : document.querySelector(container)\r\n\t\tthis.gridItems = Array.from(this.grid.children)\r\n\t\tthis.grid.style.contain = 'layout'\r\n\t\tthis.resizeObserver = new ResizeObserver(this.debouncedResize)\r\n\t\tthis.resizeObserver.observe(this.grid)\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), timeout)\r\n\t\tthis.resizeAllItems()\r\n\t}\r\n\r\n\tresizeItem(item, rowHeight, rowGap) {\r\n\t\tconst rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))\r\n\t\titem.style.gridRowEnd = 'span ' + rowSpan\r\n\t}\r\n\r\n\tresizeAllItems() {\r\n\t\tconst rowHeight = 1\r\n\t\tconst rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))\r\n\t\tthis.grid.style.alignItems = 'start'\r\n\t\tthis.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))\r\n\t\tthis.grid.style.alignItems = 'stretch'\r\n\t\tsetTimeout(() => {\r\n\t\t\tthis.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))\r\n\t\t}, 0)\r\n\t}\r\n\r\n\tdebounce(func, wait) {\r\n\t\tlet timeout\r\n\t\treturn function executedFunction(...args) {\r\n\t\t\tconst later = () => {\r\n\t\t\t\tclearTimeout(timeout)\r\n\t\t\t\tfunc(...args)\r\n\t\t\t}\r\n\t\t\tclearTimeout(timeout)\r\n\t\t\ttimeout = setTimeout(later, wait)\r\n\t\t}\r\n\t}\r\n\r\n\tdebouncedResize = () => {\r\n\t\tthis.resizeAllItems()\r\n\t}\r\n}"],"names":[],"version":3,"file":"index.js.map"}
|
package/dist/index.module.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
|
|
2
|
-
constructor(
|
|
3
|
-
|
|
2
|
+
constructor(){
|
|
3
|
+
this.grid = null;
|
|
4
|
+
this.gridItems = [];
|
|
5
|
+
this.timeout = 200;
|
|
6
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), this.timeout);
|
|
7
|
+
this.resizeObserver = null;
|
|
8
|
+
}
|
|
9
|
+
options(options = {}) {
|
|
10
|
+
const { container: container = ".masonry" , timeout: timeout = this.timeout } = options;
|
|
4
11
|
this.grid = container instanceof HTMLElement ? container : document.querySelector(container);
|
|
5
|
-
this.gridItems =
|
|
6
|
-
...this.grid.children
|
|
7
|
-
];
|
|
8
|
-
this.resizeObserver = new ResizeObserver(()=>{
|
|
9
|
-
this.resizeAllItems();
|
|
10
|
-
});
|
|
11
|
-
this.resizeObserver.observe(this.grid);
|
|
12
|
-
window.onload = this.resizeAllItems.bind(this);
|
|
13
|
-
window.addEventListener("beforeunload", ()=>{
|
|
14
|
-
this.resizeObserver.unobserve(this.grid);
|
|
15
|
-
});
|
|
12
|
+
this.gridItems = Array.from(this.grid.children);
|
|
16
13
|
this.grid.style.contain = "layout";
|
|
17
|
-
this.
|
|
14
|
+
this.resizeObserver = new ResizeObserver(this.debouncedResize);
|
|
15
|
+
this.resizeObserver.observe(this.grid);
|
|
16
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), timeout);
|
|
17
|
+
this.resizeAllItems();
|
|
18
18
|
}
|
|
19
|
-
resizeItem(item) {
|
|
20
|
-
const rowHeight = 1;
|
|
21
|
-
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
|
|
19
|
+
resizeItem(item, rowHeight, rowGap) {
|
|
22
20
|
const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap));
|
|
23
21
|
item.style.gridRowEnd = "span " + rowSpan;
|
|
24
22
|
}
|
|
25
23
|
resizeAllItems() {
|
|
24
|
+
const rowHeight = 1;
|
|
25
|
+
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue("grid-row-gap"));
|
|
26
26
|
this.grid.style.alignItems = "start";
|
|
27
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
27
|
+
this.gridItems.forEach((item)=>this.resizeItem(item, rowHeight, rowGap));
|
|
28
28
|
this.grid.style.alignItems = "stretch";
|
|
29
|
-
|
|
30
|
-
this.gridItems.forEach((item)=>this.resizeItem(item));
|
|
31
|
-
});
|
|
29
|
+
setTimeout(()=>{
|
|
30
|
+
this.gridItems.forEach((item)=>this.resizeItem(item, rowHeight, rowGap));
|
|
31
|
+
}, 0);
|
|
32
32
|
}
|
|
33
33
|
debounce(func, wait) {
|
|
34
34
|
let timeout;
|
|
@@ -41,6 +41,9 @@ class $cf838c15c8b009ba$export$2e2bcd8739ae039 {
|
|
|
41
41
|
timeout = setTimeout(later, wait);
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
debouncedResize = ()=>{
|
|
45
|
+
this.resizeAllItems();
|
|
46
|
+
};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
|
package/dist/index.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAe;IACd,
|
|
1
|
+
{"mappings":"AAAe;IACd,aAAc;QACb,IAAI,CAAC,IAAI,GAAG,IAAI;QAChB,IAAI,CAAC,SAAS,GAAG,EAAE;QACnB,IAAI,CAAC,OAAO,GAAG;QACf,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,OAAO;QAChF,IAAI,CAAC,cAAc,GAAG,IAAI;IAC3B;IAEA,QAAQ,UAAU,CAAC,CAAC,EAAE;QACrB,MAAM,aACL,YAAY,sBACZ,UAAU,IAAI,CAAC,OAAO,GACtB,GAAG;QAEJ,IAAI,CAAC,IAAI,GAAG,qBAAqB,cAAc,YAAY,SAAS,aAAa,CAAC,UAAU;QAC5F,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ;QAC9C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG;QAC1B,IAAI,CAAC,cAAc,GAAG,IAAI,eAAe,IAAI,CAAC,eAAe;QAC7D,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;QACrC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,GAAG;QACpE,IAAI,CAAC,cAAc;IACpB;IAEA,WAAW,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE;QACnC,MAAM,UAAU,KAAK,IAAI,CAAC,AAAC,CAAA,KAAK,YAAY,GAAG,MAAK,IAAM,CAAA,YAAY,MAAK;QAC3E,KAAK,KAAK,CAAC,UAAU,GAAG,UAAU;IACnC;IAEA,iBAAiB;QAChB,MAAM,YAAY;QAClB,MAAM,SAAS,SAAS,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC;QAC5E,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,WAAW;QAChE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG;QAC7B,WAAW,IAAM;YAChB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA,OAAQ,IAAI,CAAC,UAAU,CAAC,MAAM,WAAW;QACjE,GAAG;IACJ;IAEA,SAAS,IAAI,EAAE,IAAI,EAAE;QACpB,IAAI;QACJ,OAAO,SAAS,iBAAiB,GAAG,IAAI,EAAE;YACzC,MAAM,QAAQ,IAAM;gBACnB,aAAa;gBACb,QAAQ;YACT;YACA,aAAa;YACb,UAAU,WAAW,OAAO;QAC7B;IACD;IAEA,kBAAkB,IAAM;QACvB,IAAI,CAAC,cAAc;IACpB,EAAC;AACF","sources":["src/index.js"],"sourcesContent":["export default class MasonrySimple {\r\n\tconstructor() {\r\n\t\tthis.grid = null\r\n\t\tthis.gridItems = []\r\n\t\tthis.timeout = 200\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), this.timeout)\r\n\t\tthis.resizeObserver = null\r\n\t}\r\n\r\n\toptions(options = {}) {\r\n\t\tconst {\r\n\t\t\tcontainer = '.masonry',\r\n\t\t\ttimeout = this.timeout\r\n\t\t} = options\r\n\r\n\t\tthis.grid = container instanceof HTMLElement ? container : document.querySelector(container)\r\n\t\tthis.gridItems = Array.from(this.grid.children)\r\n\t\tthis.grid.style.contain = 'layout'\r\n\t\tthis.resizeObserver = new ResizeObserver(this.debouncedResize)\r\n\t\tthis.resizeObserver.observe(this.grid)\r\n\t\tthis.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), timeout)\r\n\t\tthis.resizeAllItems()\r\n\t}\r\n\r\n\tresizeItem(item, rowHeight, rowGap) {\r\n\t\tconst rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))\r\n\t\titem.style.gridRowEnd = 'span ' + rowSpan\r\n\t}\r\n\r\n\tresizeAllItems() {\r\n\t\tconst rowHeight = 1\r\n\t\tconst rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))\r\n\t\tthis.grid.style.alignItems = 'start'\r\n\t\tthis.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))\r\n\t\tthis.grid.style.alignItems = 'stretch'\r\n\t\tsetTimeout(() => {\r\n\t\t\tthis.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))\r\n\t\t}, 0)\r\n\t}\r\n\r\n\tdebounce(func, wait) {\r\n\t\tlet timeout\r\n\t\treturn function executedFunction(...args) {\r\n\t\t\tconst later = () => {\r\n\t\t\t\tclearTimeout(timeout)\r\n\t\t\t\tfunc(...args)\r\n\t\t\t}\r\n\t\t\tclearTimeout(timeout)\r\n\t\t\ttimeout = setTimeout(later, wait)\r\n\t\t}\r\n\t}\r\n\r\n\tdebouncedResize = () => {\r\n\t\tthis.resizeAllItems()\r\n\t}\r\n}"],"names":[],"version":3,"file":"index.module.js.map"}
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,51 +1,45 @@
|
|
|
1
1
|
export default class MasonrySimple {
|
|
2
|
-
constructor(
|
|
2
|
+
constructor() {
|
|
3
|
+
this.grid = null
|
|
4
|
+
this.gridItems = []
|
|
5
|
+
this.timeout = 200
|
|
6
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), this.timeout)
|
|
7
|
+
this.resizeObserver = null
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
options(options = {}) {
|
|
3
11
|
const {
|
|
4
12
|
container = '.masonry',
|
|
5
|
-
|
|
13
|
+
timeout = this.timeout
|
|
6
14
|
} = options
|
|
7
15
|
|
|
8
16
|
this.grid = container instanceof HTMLElement ? container : document.querySelector(container)
|
|
9
|
-
this.gridItems =
|
|
10
|
-
|
|
11
|
-
this.resizeObserver = new ResizeObserver(() => {
|
|
12
|
-
this.resizeAllItems()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
this.resizeObserver.observe(this.grid)
|
|
16
|
-
|
|
17
|
-
window.onload = this.resizeAllItems.bind(this)
|
|
18
|
-
|
|
19
|
-
window.addEventListener('beforeunload', () => {
|
|
20
|
-
this.resizeObserver.unobserve(this.grid)
|
|
21
|
-
})
|
|
22
|
-
|
|
17
|
+
this.gridItems = Array.from(this.grid.children)
|
|
23
18
|
this.grid.style.contain = 'layout'
|
|
24
|
-
|
|
25
|
-
this.
|
|
19
|
+
this.resizeObserver = new ResizeObserver(this.debouncedResize)
|
|
20
|
+
this.resizeObserver.observe(this.grid)
|
|
21
|
+
this.resizeAllItems = this.debounce(this.resizeAllItems.bind(this), timeout)
|
|
22
|
+
this.resizeAllItems()
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
resizeItem(item) {
|
|
29
|
-
const rowHeight = 1
|
|
30
|
-
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))
|
|
25
|
+
resizeItem(item, rowHeight, rowGap) {
|
|
31
26
|
const rowSpan = Math.ceil((item.clientHeight + rowGap) / (rowHeight + rowGap))
|
|
32
|
-
|
|
33
27
|
item.style.gridRowEnd = 'span ' + rowSpan
|
|
34
28
|
}
|
|
35
29
|
|
|
36
30
|
resizeAllItems() {
|
|
31
|
+
const rowHeight = 1
|
|
32
|
+
const rowGap = parseInt(window.getComputedStyle(this.grid).getPropertyValue('grid-row-gap'))
|
|
37
33
|
this.grid.style.alignItems = 'start'
|
|
38
|
-
this.gridItems.forEach(item => this.resizeItem(item))
|
|
34
|
+
this.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))
|
|
39
35
|
this.grid.style.alignItems = 'stretch'
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
this.gridItems.forEach(item => this.resizeItem(item, rowHeight, rowGap))
|
|
38
|
+
}, 0)
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
debounce(func, wait) {
|
|
47
42
|
let timeout
|
|
48
|
-
|
|
49
43
|
return function executedFunction(...args) {
|
|
50
44
|
const later = () => {
|
|
51
45
|
clearTimeout(timeout)
|
|
@@ -55,4 +49,8 @@ export default class MasonrySimple {
|
|
|
55
49
|
timeout = setTimeout(later, wait)
|
|
56
50
|
}
|
|
57
51
|
}
|
|
52
|
+
|
|
53
|
+
debouncedResize = () => {
|
|
54
|
+
this.resizeAllItems()
|
|
55
|
+
}
|
|
58
56
|
}
|