Skip to content

Commit

Permalink
Add arrangeComplete event; Fixes #732
Browse files Browse the repository at this point in the history
triggered after layout, hide and reveal are all done
  • Loading branch information
desandro committed Apr 10, 2015
1 parent ad341c9 commit fa2c14b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
@@ -1,5 +1,6 @@
# Changelog

+ Added [`arrangeComplete` event](http://isotope.metafizzy.co/events.html#arrangecomplete). Fixed [#732](https://github.com/metafizzy/isotope/issues/732)
+ Changed `bower.json` `main` to just `js/isotope.js`. Resolved [#879](https://github.com/metafizzy/isotope/issues/879)
+ Added [fizzy-ui-utils](https://github.com/metafizzy/fizzy-ui-utils)

Expand Down
27 changes: 27 additions & 0 deletions js/isotope.js
Expand Up @@ -190,6 +190,8 @@ var getText = docElem.textContent ?
_this.hide( filtered.needHide );
}

this._bindArrangeComplete();

if ( this._isInstant ) {
this._noTransition( hideReveal );
} else {
Expand All @@ -212,6 +214,31 @@ var getText = docElem.textContent ?
return isInstant;
};

// listen for layoutComplete, hideComplete and revealComplete
// to trigger arrangeComplete
Isotope.prototype._bindArrangeComplete = function() {
// listen for 3 events to trigger arrangeComplete
var isLayoutComplete, isHideComplete, isRevealComplete;
var _this = this;
function arrangeParallelCallback() {
if ( isLayoutComplete && isHideComplete && isRevealComplete ) {
_this.emitEvent( 'arrangeComplete', [ _this.filteredItems ] );
}
}
this.once( 'layoutComplete', function() {
isLayoutComplete = true;
arrangeParallelCallback();
});
this.once( 'hideComplete', function() {
isHideComplete = true;
arrangeParallelCallback();
});
this.once( 'revealComplete', function() {
isRevealComplete = true;
arrangeParallelCallback();
});
};

// -------------------------- filter -------------------------- //

Isotope.prototype._filter = function( items ) {
Expand Down
3 changes: 3 additions & 0 deletions sandbox/filter-sort.html
Expand Up @@ -212,6 +212,9 @@ <h2 class="name">Actinium</h2>
// console.log( 'revealComplete', items );
// })

// iso.on( 'arrangeComplete', function( items ) {
// console.log( 'arrangeComplete', items.length );
// });

});

Expand Down
16 changes: 8 additions & 8 deletions test/layout-complete.js → test/arrange-complete.js
@@ -1,16 +1,16 @@
test( 'layoutComplete', function() {
test( 'arrangeComplete', function() {

'use strict';

var iso = new Isotope( '#layout-complete', {
var iso = new Isotope( '#arrange-complete', {
layoutMode: 'fitRows',
transitionDuration: '0.1s'
});

var tests = [
function() {
iso.once( 'layoutComplete', function() {
ok( true, 'layoutComplete after some were filtered' );
iso.once( 'arrangeComplete', function() {
ok( true, 'arrangeComplete after some were filtered' );
next();
});

Expand All @@ -19,7 +19,7 @@ test( 'layoutComplete', function() {
});
},
function() {
iso.once( 'layoutComplete', function() {
iso.once( 'arrangeComplete', function() {
ok( true, 'after some revealed, some hidden, some same' );
next();
});
Expand All @@ -29,7 +29,7 @@ test( 'layoutComplete', function() {
});
},
function() {
iso.once( 'layoutComplete', function() {
iso.once( 'arrangeComplete', function() {
ok( true, 'after random sort' );
next();
});
Expand All @@ -39,7 +39,7 @@ test( 'layoutComplete', function() {
});
},
function() {
iso.once( 'layoutComplete', function() {
iso.once( 'arrangeComplete', function() {
ok( true, 'after layout mid-way thru transition' );
next();
});
Expand All @@ -60,7 +60,7 @@ test( 'layoutComplete', function() {
function next() {
if ( tests.length ) {
var nextTest = tests.shift();
// HACK for consecutive layoutComplete calls
// HACK for consecutive arrangeComplete calls
setTimeout( nextTest );
} else {
start();
Expand Down
4 changes: 2 additions & 2 deletions test/index.html
Expand Up @@ -36,7 +36,7 @@
<script src="sorting.js"></script>
<script src="sort-data.js"></script>
<script src="filtering.js"></script>
<script src="layout-complete.js"></script>
<script src="arrange-complete.js"></script>
<script src="get-segment-size.js"></script>
<script src="masonry-measure-columns.js"></script>
<script src="masonry-stamp.js"></script>
Expand Down Expand Up @@ -90,7 +90,7 @@ <h2>Filtering</h2>

<h2>layoutComplete</h2>

<div id="layout-complete" class="container">
<div id="arrange-complete" class="container">
<div class="item a1 b1">a1 b1</div>
<div class="item a2 b1">a2 b1</div>
<div class="item a3 b1">a3 b1</div>
Expand Down

0 comments on commit fa2c14b

Please sign in to comment.