Skip to content

Commit bbd019f

Browse files
committed
remove item when transition duration = 0;
Ref desandro/masonry#372
1 parent 98da66e commit bbd019f

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "outlayer",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "the brains and guts of a layout library",
55
"main": [
66
"item.js",

item.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,21 @@ Item.prototype.removeElem = function() {
364364
this.emitEvent( 'remove', [ this ] );
365365
};
366366

367-
Item.prototype.remove = transitionProperty ? function() {
367+
Item.prototype.remove = function() {
368+
// just remove element if no transition support or no transition
369+
if ( !transitionProperty || !parseFloat( this.layout.options.transitionDuration ) ) {
370+
this.removeElem();
371+
return;
372+
}
373+
368374
// start transition
369375
var _this = this;
370376
this.on( 'transitionEnd', function() {
371377
_this.removeElem();
372378
return true; // bind once
373379
});
374380
this.hide();
375-
// if no transition just remove element
376-
} : Item.prototype.removeElem;
381+
};
377382

378383
Item.prototype.reveal = function() {
379384
delete this.isHidden;

test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ <h2>remove</h2>
110110
<div class="item w2"></div>
111111
<div class="item w2"></div>
112112
<div class="item"></div>
113+
<div class="item h2"></div>
114+
<div class="item h2"></div>
113115
<div class="item"></div>
114116
</div>
115117

test/remove.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,32 @@ test( 'remove', function() {
2121
}
2222
equal( container.children.length, expectedRemovedCount, 'elements removed from DOM' );
2323
equal( container.querySelectorAll('.w2').length, 0, 'matched elements were removed' );
24-
start();
24+
setTimeout( removeNoTransition, 20 );
25+
// start();
26+
return true;
2527
});
2628
stop();
2729
olayer.remove( w2Elems );
2830
equal( olayer.items.length, expectedRemovedCount, 'items removed from Packery instance' );
2931

32+
// check items are remove with no transition
33+
function removeNoTransition() {
34+
// disable transition by setting transition duration to 0
35+
olayer.options.transitionDuration = 0;
36+
var h2Elems = container.querySelectorAll('.h2');
37+
expectedRemovedCount -= h2Elems.length;
38+
39+
olayer.on( 'removeComplete', function( obj, removedItems ) {
40+
equal( true, true, 'no transition, removeComplete event did fire' );
41+
equal( removedItems.length, h2Elems.length, 'no transition, remove elems length matches 2nd argument length' );
42+
equal( container.children.length, expectedRemovedCount, 'no transition, elements removed from DOM' );
43+
equal( container.querySelectorAll('.h2').length, 0, 'no transition, matched elements were removed' );
44+
start();
45+
});
46+
47+
olayer.remove( h2Elems );
48+
}
49+
3050
});
3151

3252
})();

0 commit comments

Comments
 (0)