@@ -11,19 +11,20 @@ angular.module('ui.bootstrap.transition', [])
1111 */
1212. factory ( '$transition' , [ '$q' , '$timeout' , '$rootScope' , function ( $q , $timeout , $rootScope ) {
1313
14- var $transition = function ( element , trigger ) {
15-
14+ var $transition = function ( element , trigger , options ) {
15+ options = options || { } ;
1616 var deferred = $q . defer ( ) ;
17+ var endEventName = $transition [ options . animation ? "animationEndEventName" : "transitionEndEventName" ] ;
18+
1719 var transitionEndHandler = function ( event ) {
1820 $rootScope . $apply ( function ( ) {
19- element . unbind ( $transition . transitionEndEventName , transitionEndHandler ) ;
21+ element . unbind ( endEventName , transitionEndHandler ) ;
2022 deferred . resolve ( element ) ;
2123 } ) ;
2224 } ;
2325
24- // Only bind if the browser supports transitions
25- if ( $transition . transitionEndEventName ) {
26- element . bind ( $transition . transitionEndEventName , transitionEndHandler ) ;
26+ if ( endEventName ) {
27+ element . bind ( endEventName , transitionEndHandler ) ;
2728 }
2829
2930 // Wrap in a timeout to allow the browser time to update the DOM before the transition is to occur
@@ -35,19 +36,18 @@ angular.module('ui.bootstrap.transition', [])
3536 } else if ( angular . isObject ( trigger ) ) {
3637 element . css ( trigger ) ;
3738 }
38-
39- // If the browser doesn't support transitions then we immediately resolve the event
40- if ( ! $transition . transitionEndEventName ) {
39+ //If browser does not support transitions, instantly resolve
40+ if ( ! endEventName ) {
4141 deferred . resolve ( element ) ;
4242 }
4343 } ) ;
4444
45- // Add out custom cancel function to the promise that is returned
45+ // Add our custom cancel function to the promise that is returned
4646 // We can call this if we are about to run a new transition, which we know will prevent this transition from ending,
4747 // i.e. it will therefore never raise a transitionEnd event for that transition
4848 deferred . promise . cancel = function ( ) {
49- if ( $transition . transitionEndEventName ) {
50- element . unbind ( $transition . transitionEndEventName , transitionEndHandler ) ;
49+ if ( endEventName ) {
50+ element . unbind ( endEventName , transitionEndHandler ) ;
5151 }
5252 deferred . reject ( 'Transition cancelled' ) ;
5353 } ;
@@ -64,10 +64,21 @@ angular.module('ui.bootstrap.transition', [])
6464 'msTransition' : 'MSTransitionEnd' ,
6565 'transition' : 'transitionend'
6666 } ;
67- for ( var name in transitionEndEventNames ) {
68- if ( transElement . style [ name ] !== undefined ) {
69- $transition . transitionEndEventName = transitionEndEventNames [ name ] ;
67+ var animationEndEventNames = {
68+ 'WebkitTransition' : 'webkitAnimationEnd' ,
69+ 'MozTransition' : 'animationend' ,
70+ 'OTransition' : 'oAnimationEnd' ,
71+ 'msTransition' : 'MSAnimationEnd' ,
72+ 'transition' : 'animationend'
73+ } ;
74+ function findEndEventName ( endEventNames ) {
75+ for ( var name in endEventNames ) {
76+ if ( transElement . style [ name ] !== undefined ) {
77+ return endEventNames [ name ] ;
78+ }
7079 }
7180 }
81+ $transition . transitionEndEventName = findEndEventName ( transitionEndEventNames ) ;
82+ $transition . animationEndEventName = findEndEventName ( animationEndEventNames ) ;
7283 return $transition ;
73- } ] ) ;
84+ } ] ) ;
0 commit comments