|
|
@@ -5,13 +5,37 @@ var NG_ANIMATE_PIN_DATA = '$ngAnimatePin'; |
|
|
var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { |
|
|
var PRE_DIGEST_STATE = 1; |
|
|
var RUNNING_STATE = 2; |
|
|
var ONE_SPACE = ' '; |
|
|
|
|
|
var rules = this.rules = { |
|
|
skip: [], |
|
|
cancel: [], |
|
|
join: [] |
|
|
}; |
|
|
|
|
|
function makeTruthyCssClassMap(classString) { |
|
|
if (!classString) { |
|
|
return null; |
|
|
} |
|
|
|
|
|
var keys = classString.split(ONE_SPACE); |
|
|
var map = Object.create(null); |
|
|
|
|
|
forEach(keys, function(key) { |
|
|
map[key] = true; |
|
|
}); |
|
|
return map; |
|
|
} |
|
|
|
|
|
function hasMatchingClasses(newClassString, currentClassString) { |
|
|
if (newClassString && currentClassString) { |
|
|
var currentClassMap = makeTruthyCssClassMap(currentClassString); |
|
|
return newClassString.split(ONE_SPACE).some(function(className) { |
|
|
return currentClassMap[className]; |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
function isAllowed(ruleType, element, currentAnimation, previousAnimation) { |
|
|
return rules[ruleType].some(function(fn) { |
|
|
return fn(element, currentAnimation, previousAnimation); |
|
|
@@ -59,11 +83,19 @@ var $$AnimateQueueProvider = ['$animateProvider', function($animateProvider) { |
|
|
}); |
|
|
|
|
|
rules.cancel.push(function(element, newAnimation, currentAnimation) { |
|
|
var nO = newAnimation.options; |
|
|
var cO = currentAnimation.options; |
|
|
|
|
|
// if the exact same CSS class is added/removed then it's safe to cancel it |
|
|
return (nO.addClass && nO.addClass === cO.removeClass) || (nO.removeClass && nO.removeClass === cO.addClass); |
|
|
|
|
|
var nA = newAnimation.options.addClass; |
|
|
var nR = newAnimation.options.removeClass; |
|
|
var cA = currentAnimation.options.addClass; |
|
|
var cR = currentAnimation.options.removeClass; |
|
|
|
|
|
// early detection to save the global CPU shortage :) |
|
|
if ((isUndefined(nA) && isUndefined(nR)) || (isUndefined(cA) && isUndefined(cR))) { |
|
|
return false; |
|
|
} |
|
|
|
|
|
return (hasMatchingClasses(nA, cR)) || (hasMatchingClasses(nR, cA)); |
|
|
}); |
|
|
|
|
|
this.$get = ['$$rAF', '$rootScope', '$rootElement', '$document', '$$HashMap', |
|
|
|