(element, animationEvent, className)
| 399 | } |
| 400 | |
| 401 | function animationRunner(element, animationEvent, className) { |
| 402 | //transcluded directives may sometimes fire an animation using only comment nodes |
| 403 | //best to catch this early on to prevent any animation operations from occurring |
| 404 | var node = element[0]; |
| 405 | if(!node) { |
| 406 | return; |
| 407 | } |
| 408 | |
| 409 | var isSetClassOperation = animationEvent == 'setClass'; |
| 410 | var isClassBased = isSetClassOperation || |
| 411 | animationEvent == 'addClass' || |
| 412 | animationEvent == 'removeClass'; |
| 413 | |
| 414 | var classNameAdd, classNameRemove; |
| 415 | if(angular.isArray(className)) { |
| 416 | classNameAdd = className[0]; |
| 417 | classNameRemove = className[1]; |
| 418 | className = classNameAdd + ' ' + classNameRemove; |
| 419 | } |
| 420 | |
| 421 | var currentClassName = element.attr('class'); |
| 422 | var classes = currentClassName + ' ' + className; |
| 423 | if(!isAnimatableClassName(classes)) { |
| 424 | return; |
| 425 | } |
| 426 | |
| 427 | var beforeComplete = noop, |
| 428 | beforeCancel = [], |
| 429 | before = [], |
| 430 | afterComplete = noop, |
| 431 | afterCancel = [], |
| 432 | after = []; |
| 433 | |
| 434 | var animationLookup = (' ' + classes).replace(/\s+/g,'.'); |
| 435 | forEach(lookup(animationLookup), function(animationFactory) { |
| 436 | var created = registerAnimation(animationFactory, animationEvent); |
| 437 | if(!created && isSetClassOperation) { |
| 438 | registerAnimation(animationFactory, 'addClass'); |
| 439 | registerAnimation(animationFactory, 'removeClass'); |
| 440 | } |
| 441 | }); |
| 442 | |
| 443 | function registerAnimation(animationFactory, event) { |
| 444 | var afterFn = animationFactory[event]; |
| 445 | var beforeFn = animationFactory['before' + event.charAt(0).toUpperCase() + event.substr(1)]; |
| 446 | if(afterFn || beforeFn) { |
| 447 | if(event == 'leave') { |
| 448 | beforeFn = afterFn; |
| 449 | //when set as null then animation knows to skip this phase |
| 450 | afterFn = null; |
| 451 | } |
| 452 | after.push({ |
| 453 | event : event, fn : afterFn |
| 454 | }); |
| 455 | before.push({ |
| 456 | event : event, fn : beforeFn |
| 457 | }); |
| 458 | return true; |
no test coverage detected