Skip to content

Commit

Permalink
Fix layoutEnd event bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasramo committed Aug 14, 2020
1 parent 8ae3445 commit 49f562c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ npm install muuri

Or download:

- [muuri.js](https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.js) - for development (not minified, with comments).
- [muuri.min.js](https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.min.js) - for production (minified, no comments).
- [muuri.js](https://cdn.jsdelivr.net/npm/[email protected].3/dist/muuri.js) - for development (not minified, with comments).
- [muuri.min.js](https://cdn.jsdelivr.net/npm/[email protected].3/dist/muuri.min.js) - for production (minified, no comments).

Or link directly:

```html
<script src="https://cdn.jsdelivr.net/npm/[email protected].2/dist/muuri.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].3/dist/muuri.min.js"></script>
```

<h3><a id="getting-started-2" href="#getting-started-2" aria-hidden="true">#</a> 2. Get Web Animations Polyfill (if needed)</h3>
Expand Down
12 changes: 9 additions & 3 deletions dist/muuri.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Muuri v0.9.2
* Muuri v0.9.3
* https://muuri.dev/
* Copyright (c) 2015-present, Haltu Oy
* Released under the MIT license
Expand Down Expand Up @@ -8631,6 +8631,8 @@
// Only active non-dragged items need to be moved.
if (item.isActive() && !item.isDragging()) {
itemsToLayout.push(item);
} else {
--counter;
}
}

Expand All @@ -8644,9 +8646,13 @@
// to container dimension changes.
if (this._hasListeners(EVENT_LAYOUT_START)) {
this._emit(EVENT_LAYOUT_START, layout.items.slice(0), instant === true);
// Let's make sure that the current layout process has not been overridden
// in the layoutStart event, and if so, let's stop processing the aborted
// layout.
if (this._layout.id !== layout.id) return;
}

function tryFinish() {
var tryFinish = function () {
if (--counter > 0) return;

var hasLayoutChanged = grid._layout.id !== layout.id;
Expand All @@ -8663,7 +8669,7 @@
if (!hasLayoutChanged && grid._hasListeners(EVENT_LAYOUT_END)) {
grid._emit(EVENT_LAYOUT_END, layout.items.slice(0));
}
}
};

if (!itemsToLayout.length) {
tryFinish();
Expand Down
4 changes: 2 additions & 2 deletions dist/muuri.min.js

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions dist/muuri.module.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Muuri v0.9.2
* Muuri v0.9.3
* https://muuri.dev/
* Copyright (c) 2015-present, Haltu Oy
* Released under the MIT license
Expand Down Expand Up @@ -8625,6 +8625,8 @@ Grid.prototype._onLayoutDataReceived = (function () {
// Only active non-dragged items need to be moved.
if (item.isActive() && !item.isDragging()) {
itemsToLayout.push(item);
} else {
--counter;
}
}

Expand All @@ -8638,9 +8640,13 @@ Grid.prototype._onLayoutDataReceived = (function () {
// to container dimension changes.
if (this._hasListeners(EVENT_LAYOUT_START)) {
this._emit(EVENT_LAYOUT_START, layout.items.slice(0), instant === true);
// Let's make sure that the current layout process has not been overridden
// in the layoutStart event, and if so, let's stop processing the aborted
// layout.
if (this._layout.id !== layout.id) return;
}

function tryFinish() {
var tryFinish = function () {
if (--counter > 0) return;

var hasLayoutChanged = grid._layout.id !== layout.id;
Expand All @@ -8657,7 +8663,7 @@ Grid.prototype._onLayoutDataReceived = (function () {
if (!hasLayoutChanged && grid._hasListeners(EVENT_LAYOUT_END)) {
grid._emit(EVENT_LAYOUT_END, layout.items.slice(0));
}
}
};

if (!itemsToLayout.length) {
tryFinish();
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "muuri",
"version": "0.9.2",
"version": "0.9.3",
"description": "Responsive, sortable, filterable and draggable layouts",
"keywords": [
"grid",
Expand Down
10 changes: 8 additions & 2 deletions src/Grid/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,8 @@ Grid.prototype._onLayoutDataReceived = (function () {
// Only active non-dragged items need to be moved.
if (item.isActive() && !item.isDragging()) {
itemsToLayout.push(item);
} else {
--counter;
}
}

Expand All @@ -1401,9 +1403,13 @@ Grid.prototype._onLayoutDataReceived = (function () {
// to container dimension changes.
if (this._hasListeners(EVENT_LAYOUT_START)) {
this._emit(EVENT_LAYOUT_START, layout.items.slice(0), instant === true);
// Let's make sure that the current layout process has not been overridden
// in the layoutStart event, and if so, let's stop processing the aborted
// layout.
if (this._layout.id !== layout.id) return;
}

function tryFinish() {
var tryFinish = function () {
if (--counter > 0) return;

var hasLayoutChanged = grid._layout.id !== layout.id;
Expand All @@ -1420,7 +1426,7 @@ Grid.prototype._onLayoutDataReceived = (function () {
if (!hasLayoutChanged && grid._hasListeners(EVENT_LAYOUT_END)) {
grid._emit(EVENT_LAYOUT_END, layout.items.slice(0));
}
}
};

if (!itemsToLayout.length) {
tryFinish();
Expand Down

0 comments on commit 49f562c

Please sign in to comment.