Browse Source

Add arrangeComplete event; Fixes #732

triggered after layout, hide and reveal are all done
pull/894/head
David DeSandro 10 years ago
parent
commit
fa2c14ba2b
  1. 1
      changelog.md
  2. 27
      js/isotope.js
  3. 3
      sandbox/filter-sort.html
  4. 16
      test/arrange-complete.js
  5. 4
      test/index.html

1
changelog.md

@ -1,5 +1,6 @@
# Changelog # 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) + 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) + Added [fizzy-ui-utils](https://github.com/metafizzy/fizzy-ui-utils)

27
js/isotope.js

@ -190,6 +190,8 @@ var getText = docElem.textContent ?
_this.hide( filtered.needHide ); _this.hide( filtered.needHide );
} }
this._bindArrangeComplete();
if ( this._isInstant ) { if ( this._isInstant ) {
this._noTransition( hideReveal ); this._noTransition( hideReveal );
} else { } else {
@ -212,6 +214,31 @@ var getText = docElem.textContent ?
return isInstant; 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 -------------------------- // // -------------------------- filter -------------------------- //
Isotope.prototype._filter = function( items ) { Isotope.prototype._filter = function( items ) {

3
sandbox/filter-sort.html

@ -212,6 +212,9 @@ docReady( function() {
// console.log( 'revealComplete', items ); // console.log( 'revealComplete', items );
// }) // })
// iso.on( 'arrangeComplete', function( items ) {
// console.log( 'arrangeComplete', items.length );
// });
}); });

16
test/layout-complete.js → test/arrange-complete.js

@ -1,16 +1,16 @@
test( 'layoutComplete', function() { test( 'arrangeComplete', function() {
'use strict'; 'use strict';
var iso = new Isotope( '#layout-complete', { var iso = new Isotope( '#arrange-complete', {
layoutMode: 'fitRows', layoutMode: 'fitRows',
transitionDuration: '0.1s' transitionDuration: '0.1s'
}); });
var tests = [ var tests = [
function() { function() {
iso.once( 'layoutComplete', function() { iso.once( 'arrangeComplete', function() {
ok( true, 'layoutComplete after some were filtered' ); ok( true, 'arrangeComplete after some were filtered' );
next(); next();
}); });
@ -19,7 +19,7 @@ test( 'layoutComplete', function() {
}); });
}, },
function() { function() {
iso.once( 'layoutComplete', function() { iso.once( 'arrangeComplete', function() {
ok( true, 'after some revealed, some hidden, some same' ); ok( true, 'after some revealed, some hidden, some same' );
next(); next();
}); });
@ -29,7 +29,7 @@ test( 'layoutComplete', function() {
}); });
}, },
function() { function() {
iso.once( 'layoutComplete', function() { iso.once( 'arrangeComplete', function() {
ok( true, 'after random sort' ); ok( true, 'after random sort' );
next(); next();
}); });
@ -39,7 +39,7 @@ test( 'layoutComplete', function() {
}); });
}, },
function() { function() {
iso.once( 'layoutComplete', function() { iso.once( 'arrangeComplete', function() {
ok( true, 'after layout mid-way thru transition' ); ok( true, 'after layout mid-way thru transition' );
next(); next();
}); });
@ -60,7 +60,7 @@ test( 'layoutComplete', function() {
function next() { function next() {
if ( tests.length ) { if ( tests.length ) {
var nextTest = tests.shift(); var nextTest = tests.shift();
// HACK for consecutive layoutComplete calls // HACK for consecutive arrangeComplete calls
setTimeout( nextTest ); setTimeout( nextTest );
} else { } else {
start(); start();

4
test/index.html

@ -36,7 +36,7 @@
<script src="sorting.js"></script> <script src="sorting.js"></script>
<script src="sort-data.js"></script> <script src="sort-data.js"></script>
<script src="filtering.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="get-segment-size.js"></script>
<script src="masonry-measure-columns.js"></script> <script src="masonry-measure-columns.js"></script>
<script src="masonry-stamp.js"></script> <script src="masonry-stamp.js"></script>
@ -90,7 +90,7 @@
<h2>layoutComplete</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 a1 b1">a1 b1</div>
<div class="item a2 b1">a2 b1</div> <div class="item a2 b1">a2 b1</div>
<div class="item a3 b1">a3 b1</div> <div class="item a3 b1">a3 b1</div>

Loading…
Cancel
Save