aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngAnimate
diff options
context:
space:
mode:
authorMatias Niemelä2014-02-14 00:53:49 -0500
committerIgor Minar2014-02-14 16:28:56 -0800
commitcf5e463abd2c23f62e9c2e6361e6c53048c8910e (patch)
tree1833c0e402b67b2bb5298fa0db91f8329eafc1fe /src/ngAnimate
parentf288b8f010468237d238acf51ea3d8108138207a (diff)
downloadangular.js-cf5e463abd2c23f62e9c2e6361e6c53048c8910e.tar.bz2
pref($animate): only trigger DOM callbacks if registered on the element being animated
BREAKING CHANGE: Both the `$animate:before` and `$animate:after` DOM events must be now registered prior to the $animate operation taking place. The `$animate:close` event can be registered anytime afterwards. DOM callbacks used to fired for each and every animation operation that occurs within the $animate service provided in the ngAnimate module. This may end up slowing down an application if 100s of elements are being inserted into the page. Therefore after this change callbacks are only fired if registered on the element being animated.
Diffstat (limited to 'src/ngAnimate')
-rw-r--r--src/ngAnimate/animate.js34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js
index 99b42f38..dba8d3fa 100644
--- a/src/ngAnimate/animate.js
+++ b/src/ngAnimate/animate.js
@@ -627,6 +627,9 @@ angular.module('ngAnimate', ['ng'])
return;
}
+ var elementEvents = angular.element._data(node);
+ elementEvents = elementEvents && elementEvents.events;
+
var animationLookup = (' ' + classes).replace(/\s+/g,'.');
if (!parentElement) {
parentElement = afterElement ? afterElement.parent() : element.parent();
@@ -822,29 +825,32 @@ angular.module('ngAnimate', ['ng'])
}
function fireDOMCallback(animationPhase) {
- element.triggerHandler('$animate:' + animationPhase, {
- event : animationEvent,
- className : className
- });
+ var eventName = '$animate:' + animationPhase;
+ if(elementEvents && elementEvents[eventName] && elementEvents[eventName].length > 0) {
+ $$asyncQueueBuffer(function() {
+ element.triggerHandler(eventName, {
+ event : animationEvent,
+ className : className
+ });
+ });
+ }
}
function fireBeforeCallbackAsync() {
- $$asyncQueueBuffer(function() {
- fireDOMCallback('before');
- });
+ fireDOMCallback('before');
}
function fireAfterCallbackAsync() {
- $$asyncQueueBuffer(function() {
- fireDOMCallback('after');
- });
+ fireDOMCallback('after');
}
function fireDoneCallbackAsync() {
- $$asyncQueueBuffer(function() {
- fireDOMCallback('close');
- doneCallback && doneCallback();
- });
+ fireDOMCallback('close');
+ if(doneCallback) {
+ $$asyncQueueBuffer(function() {
+ doneCallback();
+ });
+ }
}
//it is less complicated to use a flag than managing and cancelling