7
7
*
8
8
*/
9
9
angular . module ( 'ui.bootstrap.carousel' , [ 'ui.bootstrap.transition' ] )
10
- . controller ( 'CarouselController' , [ '$scope' , '$timeout' , '$ interval', '$transition ' , function ( $scope , $timeout , $ interval, $transition ) {
10
+ . controller ( 'CarouselController' , [ '$scope' , '$interval' , '$animate ' , function ( $scope , $interval , $animate ) {
11
11
var self = this ,
12
12
slides = self . slides = $scope . slides = [ ] ,
13
13
currentIndex = - 1 ,
@@ -23,51 +23,30 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
23
23
direction = nextIndex > currentIndex ? 'next' : 'prev' ;
24
24
}
25
25
if ( nextSlide && nextSlide !== self . currentSlide ) {
26
- if ( $scope . $currentTransition ) {
27
- $scope . $currentTransition . cancel ( ) ;
28
- //Timeout so ng-class in template has time to fix classes for finished slide
29
- $timeout ( goNext ) ;
30
- } else {
31
- goNext ( ) ;
32
- }
26
+ goNext ( ) ;
33
27
}
34
28
function goNext ( ) {
35
29
// Scope has been destroyed, stop here.
36
30
if ( destroyed ) { return ; }
37
- //If we have a slide to transition from and we have a transition type and we're allowed, go
38
- if ( self . currentSlide && angular . isString ( direction ) && ! $scope . noTransition && nextSlide . $element ) {
39
- //We shouldn't do class manip in here, but it's the same weird thing bootstrap does. need to fix sometime
40
- nextSlide . $element . addClass ( direction ) ;
41
- var reflow = nextSlide . $element [ 0 ] . offsetWidth ; //force reflow
42
31
43
- //Set all other slides to stop doing their stuff for the new transition
44
- angular . forEach ( slides , function ( slide ) {
45
- angular . extend ( slide , { direction : '' , entering : false , leaving : false , active : false } ) ;
46
- } ) ;
47
- angular . extend ( nextSlide , { direction : direction , active : true , entering : true } ) ;
48
- angular . extend ( self . currentSlide || { } , { direction : direction , leaving : true } ) ;
32
+ angular . extend ( nextSlide , { direction : direction , active : true } ) ;
33
+ angular . extend ( self . currentSlide || { } , { direction : direction , active : false } ) ;
49
34
50
- $scope . $currentTransition = $transition ( nextSlide . $element , { } ) ;
51
- //We have to create new pointers inside a closure since next & current will change
52
- ( function ( next , current ) {
53
- $scope . $currentTransition . then (
54
- function ( ) { transitionDone ( next , current ) ; } ,
55
- function ( ) { transitionDone ( next , current ) ; }
56
- ) ;
57
- } ( nextSlide , self . currentSlide ) ) ;
58
- } else {
59
- transitionDone ( nextSlide , self . currentSlide ) ;
35
+ if ( $animate . enabled ( ) && ! $scope . noTransition && nextSlide . $element ) {
36
+ $scope . $currentTransition = true ;
37
+ // TODO: Switch to use .one when upgrading beyond 1.2.21
38
+ // (See https://github.com/angular/angular.js/pull/5984)
39
+ nextSlide . $element . on ( '$animate:close' , function closeFn ( ) {
40
+ $scope . $currentTransition = null ;
41
+ nextSlide . $element . off ( '$animate:close' , closeFn ) ;
42
+ } ) ;
60
43
}
44
+
61
45
self . currentSlide = nextSlide ;
62
46
currentIndex = nextIndex ;
63
47
//every time you change slides, reset the timer
64
48
restartTimer ( ) ;
65
49
}
66
- function transitionDone ( next , current ) {
67
- angular . extend ( next , { direction : '' , active : true , leaving : false , entering : false } ) ;
68
- angular . extend ( current || { } , { direction : '' , active : false , leaving : false , entering : false } ) ;
69
- $scope . $currentTransition = null ;
70
- }
71
50
} ;
72
51
$scope . $on ( '$destroy' , function ( ) {
73
52
destroyed = true ;
@@ -290,4 +269,55 @@ function CarouselDemoCtrl($scope) {
290
269
} ) ;
291
270
}
292
271
} ;
293
- } ) ;
272
+ } )
273
+
274
+ . animation ( '.item' , [
275
+ '$animate' ,
276
+ function ( $animate ) {
277
+ return {
278
+ beforeAddClass : function ( element , className , done ) {
279
+ // Due to transclusion, noTransition property is on parent's scope
280
+ if ( className == 'active' && element . parent ( ) &&
281
+ ! element . parent ( ) . scope ( ) . noTransition ) {
282
+ var stopped = false ;
283
+ var direction = element . isolateScope ( ) . direction ;
284
+ var directionClass = direction == 'next' ? 'left' : 'right' ;
285
+ element . addClass ( direction ) ;
286
+ $animate . addClass ( element , directionClass ) . then ( function ( ) {
287
+ if ( ! stopped ) {
288
+ element . removeClass ( directionClass + ' ' + direction ) ;
289
+ }
290
+ done ( ) ;
291
+ } ) ;
292
+
293
+ return function ( ) {
294
+ stopped = true ;
295
+ } ;
296
+ }
297
+ done ( ) ;
298
+ } ,
299
+ beforeRemoveClass : function ( element , className , done ) {
300
+ // Due to transclusion, noTransition property is on parent's scope
301
+ if ( className == 'active' && element . parent ( ) &&
302
+ ! element . parent ( ) . scope ( ) . noTransition ) {
303
+ var stopped = false ;
304
+ var direction = element . isolateScope ( ) . direction ;
305
+ var directionClass = direction == 'next' ? 'left' : 'right' ;
306
+ $animate . addClass ( element , directionClass ) . then ( function ( ) {
307
+ if ( ! stopped ) {
308
+ element . removeClass ( directionClass ) ;
309
+ }
310
+ done ( ) ;
311
+ } ) ;
312
+ return function ( ) {
313
+ stopped = true ;
314
+ } ;
315
+ }
316
+ done ( ) ;
317
+ }
318
+ } ;
319
+
320
+ } ] )
321
+
322
+
323
+ ;
0 commit comments