This repository was archived by the owner on May 29, 2019. It is now read-only.
File tree 1 file changed +20
-21
lines changed
1 file changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -103,24 +103,32 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
103
103
} ;
104
104
105
105
$scope . $watch ( 'interval' , restartTimer ) ;
106
+ $scope . $on ( '$destroy' , resetTimer ) ;
107
+
106
108
function restartTimer ( ) {
109
+ resetTimer ( ) ;
110
+ var interval = + $scope . interval ;
111
+ if ( ! isNaN ( interval ) && interval >= 0 ) {
112
+ currentTimeout = $timeout ( timerFn , interval ) ;
113
+ }
114
+ }
115
+
116
+ function resetTimer ( ) {
107
117
if ( currentTimeout ) {
108
118
$timeout . cancel ( currentTimeout ) ;
109
119
currentTimeout = null ;
110
120
}
111
- function go ( ) {
112
- if ( isPlaying ) {
113
- $scope . next ( ) ;
114
- restartTimer ( ) ;
115
- } else {
116
- $scope . pause ( ) ;
117
- }
118
- }
119
- var interval = + $scope . interval ;
120
- if ( ! isNaN ( interval ) && interval >= 0 ) {
121
- currentTimeout = $timeout ( go , interval ) ;
121
+ }
122
+
123
+ function timerFn ( ) {
124
+ if ( isPlaying ) {
125
+ $scope . next ( ) ;
126
+ restartTimer ( ) ;
127
+ } else {
128
+ $scope . pause ( ) ;
122
129
}
123
130
}
131
+
124
132
$scope . play = function ( ) {
125
133
if ( ! isPlaying ) {
126
134
isPlaying = true ;
@@ -130,10 +138,7 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
130
138
$scope . pause = function ( ) {
131
139
if ( ! $scope . noPause ) {
132
140
isPlaying = false ;
133
- if ( currentTimeout ) {
134
- $timeout . cancel ( currentTimeout ) ;
135
- currentTimeout = null ;
136
- }
141
+ resetTimer ( ) ;
137
142
}
138
143
} ;
139
144
@@ -166,12 +171,6 @@ angular.module('ui.bootstrap.carousel', ['ui.bootstrap.transition'])
166
171
}
167
172
} ;
168
173
169
- $scope . $on ( '$destroy' , function ( ) {
170
- if ( currentTimeout ) {
171
- $timeout . cancel ( currentTimeout ) ;
172
- currentTimeout = null ;
173
- }
174
- } ) ;
175
174
} ] )
176
175
177
176
/**
You can’t perform that action at this time.
0 commit comments