diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/animate.js | 16 | ||||
| -rw-r--r-- | src/ngAnimate/animate.js | 42 |
2 files changed, 27 insertions, 31 deletions
diff --git a/src/ng/animate.js b/src/ng/animate.js index 7927b12f..2d9e6191 100644 --- a/src/ng/animate.js +++ b/src/ng/animate.js @@ -1,5 +1,7 @@ 'use strict'; +var $animateMinErr = minErr('$animate'); + /** * @ngdoc object * @name ng.$animateProvider @@ -14,7 +16,7 @@ */ var $AnimateProvider = ['$provide', function($provide) { - this.$$selectors = []; + this.$$selectors = {}; /** @@ -47,13 +49,11 @@ var $AnimateProvider = ['$provide', function($provide) { * @param {function} factory The factory function that will be executed to return the animation object. */ this.register = function(name, factory) { - var classes = name.substr(1).split('.'); - name += '-animation'; - this.$$selectors.push({ - selectors : classes, - name : name - }); - $provide.factory(name, factory); + var key = name + '-animation'; + if (name && name.charAt(0) != '.') throw $animateMinErr('notcsel', + "Expecting class selector starting with '.' got '{0}'.", name); + this.$$selectors[name.substr(1)] = key; + $provide.factory(key, factory); }; this.$get = ['$timeout', function($timeout) { diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index 20ceaf07..d572619f 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -174,7 +174,7 @@ * a javascript callback function. When an animation is triggered, $animate will look for a matching animation which fits * the element's CSS class attribute value and then run the matching animation event function (if found). * In other words, if the CSS classes present on the animated element match any of the JavaScript animations then the callback function - * be executed. It should be also noted that only simple or compound class selectors are allowed. + * be executed. It should be also noted that only simple class selectors are allowed. * * Within a JavaScript animation, an object containing various event callback animation functions is expected to be returned. * As explained above, these callbacks are triggered based on the animation event. Therefore if an enter animation is run, @@ -211,27 +211,23 @@ angular.module('ngAnimate', ['ng']) $rootElement.data(NG_ANIMATE_STATE, rootAnimateState); function lookup(name) { - var i, ii; if (name) { - var classes = name.substr(1).split('.'), - classMap = {}; - - for (i = 0, ii = classes.length; i < ii; i++) { - classMap[classes[i]] = true; - } - - var matches = []; - for (i = 0, ii = selectors.length; i < ii; i++) { - var selectorFactory = selectors[i]; - var found = true; - for(var j = 0, jj = selectorFactory.selectors.length; j < jj; j++) { - var klass = selectorFactory.selectors[j]; - if(klass.length > 0) { - found = found && classMap[klass]; - } - } - if(found) { - matches.push($injector.get(selectorFactory.name)); + var matches = [], + flagMap = {}, + classes = name.substr(1).split('.'); + + //the empty string value is the default animation + //operation which performs CSS transition and keyframe + //animations sniffing. This is always included for each + //element animation procedure + classes.push(''); + + for(var i=0; i < classes.length; i++) { + var klass = classes[i], + selectorFactoryName = selectors[klass]; + if(selectorFactoryName && !flagMap[klass]) { + matches.push($injector.get(selectorFactoryName)); + flagMap[klass] = true; } } return matches; @@ -444,8 +440,8 @@ angular.module('ngAnimate', ['ng']) and the onComplete callback will be fired once the animation is fully complete. */ function performAnimation(event, className, element, parent, after, onComplete) { - var classes = ((element.attr('class') || '') + ' ' + className), - animationLookup = (' ' + classes).replace(/\s+/g,'.'), + var classes = (element.attr('class') || '') + ' ' + className; + var animationLookup = (' ' + classes).replace(/\s+/g,'.'), animations = []; forEach(lookup(animationLookup), function(animation, index) { animations.push({ |
