77*
88*/
99angular . 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 ) {
1111 var self = this ,
1212 slides = self . slides = $scope . slides = [ ] ,
1313 currentIndex = - 1 ,
@@ -23,51 +23,30 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
2323 direction = nextIndex > currentIndex ? 'next' : 'prev' ;
2424 }
2525 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 ( ) ;
3327 }
3428 function goNext ( ) {
3529 // Scope has been destroyed, stop here.
3630 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
4231
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 } ) ;
4934
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+ } ) ;
6043 }
44+
6145 self . currentSlide = nextSlide ;
6246 currentIndex = nextIndex ;
6347 //every time you change slides, reset the timer
6448 restartTimer ( ) ;
6549 }
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- }
7150 } ;
7251 $scope . $on ( '$destroy' , function ( ) {
7352 destroyed = true ;
@@ -290,4 +269,70 @@ function CarouselDemoCtrl($scope) {
290269 } ) ;
291270 }
292271 } ;
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 , 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 , 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+ . run ( [
323+ '$document' ,
324+ function ( $document ) {
325+ if ( ! angular . $$csp ( ) ) {
326+ angular . element ( $document ) . find ( 'head' )
327+ . prepend (
328+ '<style type="text/css">@charset "UTF-8";' +
329+ '.ng-animate.item:not(.left):not(.right) {' +
330+ ' transition: 0 ease-in-out left;' +
331+ '}' +
332+ '</style>'
333+ ) ;
334+ }
335+ } ] )
336+
337+
338+ ;
0 commit comments