7
7
*
8
8
*/
9
9
angular . module ( 'ui.bootstrap.carousel' , [ 'ui.bootstrap.transition' ] )
10
- . controller ( 'CarouselController' , [ '$scope' , '$timeout' , '$transition ' , function ( $scope , $timeout , $transition ) {
10
+ . controller ( 'CarouselController' , [ '$scope' , '$timeout' , '$animate ' , function ( $scope , $timeout , $animate ) {
11
11
var self = this ,
12
12
slides = self . slides = $scope . slides = [ ] ,
13
13
currentIndex = - 1 ,
@@ -23,51 +23,32 @@ 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 {
26
+ if ( ! $animate . enabled ( ) || ! $scope . $currentTransition ) {
31
27
goNext ( ) ;
32
28
}
33
29
}
34
30
function goNext ( ) {
35
31
// Scope has been destroyed, stop here.
36
32
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
33
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 } ) ;
34
+ angular . extend ( nextSlide , { direction : direction , active : true } ) ;
35
+ angular . extend ( self . currentSlide || { } , { direction : direction , active : false } ) ;
49
36
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 ) ;
37
+ if ( $animate . enabled ( ) && ! $scope . noTransition && nextSlide . $element ) {
38
+ $scope . $currentTransition = true ;
39
+ // TODO: Switch to use .one when upgrading beyond 1.2.21
40
+ // (See https://github.com/angular/angular.js/pull/5984)
41
+ nextSlide . $element . on ( '$animate:close' , function closeFn ( ) {
42
+ $scope . $currentTransition = null ;
43
+ nextSlide . $element . off ( '$animate:close' , closeFn ) ;
44
+ } ) ;
60
45
}
46
+
61
47
self . currentSlide = nextSlide ;
62
48
currentIndex = nextIndex ;
63
49
//every time you change slides, reset the timer
64
50
restartTimer ( ) ;
65
51
}
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
52
} ;
72
53
$scope . $on ( '$destroy' , function ( ) {
73
54
destroyed = true ;
@@ -290,4 +271,72 @@ function CarouselDemoCtrl($scope) {
290
271
} ) ;
291
272
}
292
273
} ;
293
- } ) ;
274
+ } )
275
+
276
+ . animation ( '.item' , [
277
+ '$animate' ,
278
+ function ( $animate ) {
279
+ return {
280
+ beforeAddClass : function ( element , className , done ) {
281
+ // Due to transclusion, noTransition property is on parent's scope
282
+ if ( className == 'active' && element . parent ( ) &&
283
+ ! element . parent ( ) . scope ( ) . noTransition ) {
284
+ var stopped = false ;
285
+ var direction = element . isolateScope ( ) . direction ;
286
+ var directionClass = direction == 'next' ? 'left' : 'right' ;
287
+ element . addClass ( direction ) ;
288
+ $animate . addClass ( element , directionClass , function ( ) {
289
+ if ( ! stopped ) {
290
+ element . removeClass ( directionClass + ' ' + direction ) ;
291
+ }
292
+ done ( ) ;
293
+ } ) ;
294
+
295
+ return function ( ) {
296
+ stopped = true ;
297
+ } ;
298
+ }
299
+ done ( ) ;
300
+ } ,
301
+ beforeRemoveClass : function ( element , className , done ) {
302
+ // Due to transclusion, noTransition property is on parent's scope
303
+ if ( className == 'active' && element . parent ( ) &&
304
+ ! element . parent ( ) . scope ( ) . noTransition ) {
305
+ var stopped = false ;
306
+ var direction = element . isolateScope ( ) . direction ;
307
+ var directionClass = direction == 'next' ? 'left' : 'right' ;
308
+ $animate . addClass ( element , directionClass , function ( ) {
309
+ if ( ! stopped ) {
310
+ element . removeClass ( directionClass ) ;
311
+ }
312
+ done ( ) ;
313
+ } ) ;
314
+ return function ( ) {
315
+ stopped = true ;
316
+ } ;
317
+ }
318
+ done ( ) ;
319
+ }
320
+ } ;
321
+
322
+ } ] )
323
+
324
+ . run ( [
325
+ '$document' ,
326
+ function ( $document ) {
327
+ if ( ! angular . $$csp ( ) ) {
328
+ angular . element ( $document ) . find ( 'head' )
329
+ . prepend (
330
+ '<style type="text/css">@charset "UTF-8";' +
331
+ '.ng-animate.item.active-add:not(.left):not(.right) {' +
332
+ ' transition: 0 ease-in-out left;' +
333
+ '}' +
334
+ '.ng-animate.item.active-remove:not(.left):not(.right) {' +
335
+ ' transition: 0 ease-in-out left;' +
336
+ '}'
337
+ ) ;
338
+ }
339
+ } ] )
340
+
341
+
342
+ ;
0 commit comments