mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix($animate): ensure all animated elements are taken care of during the closing timeout
Closes #6395
This commit is contained in:
@@ -1063,6 +1063,15 @@ angular.module('ngAnimate', ['ng'])
|
||||
var closingTimestamp = 0;
|
||||
var animationElementQueue = [];
|
||||
function animationCloseHandler(element, totalTime) {
|
||||
var node = extractElementNode(element);
|
||||
element = angular.element(node);
|
||||
|
||||
//this item will be garbage collected by the closing
|
||||
//animation timeout
|
||||
animationElementQueue.push(element);
|
||||
|
||||
//but it may not need to cancel out the existing timeout
|
||||
//if the timestamp is less than the previous one
|
||||
var futureTimestamp = Date.now() + (totalTime * 1000);
|
||||
if(futureTimestamp <= closingTimestamp) {
|
||||
return;
|
||||
@@ -1070,10 +1079,6 @@ angular.module('ngAnimate', ['ng'])
|
||||
|
||||
$timeout.cancel(closingTimer);
|
||||
|
||||
var node = extractElementNode(element);
|
||||
element = angular.element(node);
|
||||
animationElementQueue.push(element);
|
||||
|
||||
closingTimestamp = futureTimestamp;
|
||||
closingTimer = $timeout(function() {
|
||||
closeAllAnimations(animationElementQueue);
|
||||
|
||||
@@ -1181,6 +1181,49 @@ describe("ngAnimate", function() {
|
||||
expect(element.hasClass('some-class-add-active')).toBe(false);
|
||||
}));
|
||||
|
||||
it("should intelligently cancel former timeouts and close off a series of elements a final timeout", function() {
|
||||
var cancellations = 0;
|
||||
module(function($provide) {
|
||||
$provide.decorator('$timeout', function($delegate) {
|
||||
var _cancel = $delegate.cancel;
|
||||
$delegate.cancel = function() {
|
||||
cancellations++;
|
||||
return _cancel.apply($delegate, arguments);
|
||||
};
|
||||
return $delegate;
|
||||
});
|
||||
})
|
||||
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {
|
||||
if (!$sniffer.transitions) return;
|
||||
|
||||
ss.addRule('.animate-me', '-webkit-transition:1s linear all;' +
|
||||
'transition:1s linear all;');
|
||||
|
||||
element = $compile(html('<div><div class="animate-me" ng-repeat="item in items"></div></div>'))($rootScope);
|
||||
|
||||
$rootScope.items = [1,2,3,4,5,6,7,8,9,10];
|
||||
var totalOperations = $rootScope.items.length;
|
||||
|
||||
$rootScope.$digest();
|
||||
|
||||
$rootScope.items = [0];
|
||||
$animate.triggerReflow();
|
||||
$timeout.flush(1500);
|
||||
|
||||
expect(cancellations).toBeLessThan(totalOperations);
|
||||
expect(element.children().length).toBe(10);
|
||||
cancellations = 0;
|
||||
|
||||
$rootScope.items = [1];
|
||||
$rootScope.$digest();
|
||||
|
||||
$animate.triggerReflow();
|
||||
$timeout.flush(1500);
|
||||
expect(element.children().length).toBe(1);
|
||||
expect(cancellations).toBeLessThan(totalOperations);
|
||||
});
|
||||
});
|
||||
|
||||
it("apply a closing timeout with respect to a staggering animation",
|
||||
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user