@@ -103,6 +103,24 @@ var helpers = {
103
103
}
104
104
}
105
105
} ,
106
+ canGoNext : function ( opts ) {
107
+ var canGo = true ;
108
+ if ( ! opts . infinite ) {
109
+ if ( opts . centerMode ) {
110
+ // check if current slide is last slide
111
+ if ( opts . currentSlide >= ( opts . slideCount - 1 ) ) {
112
+ canGo = false ;
113
+ }
114
+ } else {
115
+ // check if all slides are shown in slider
116
+ if ( opts . slideCount <= opts . slidesToShow ||
117
+ opts . currentSlide >= ( opts . slideCount - opts . slidesToShow ) ) {
118
+ canGo = false ;
119
+ }
120
+ }
121
+ }
122
+ return canGo ;
123
+ } ,
106
124
slideHandler : function ( index ) {
107
125
// Functionality of animateSlide and postSlide is merged into this function
108
126
// console.log('slideHandler', index);
@@ -121,7 +139,7 @@ var helpers = {
121
139
if ( this . props . infinite === false &&
122
140
( index < 0 || index >= this . state . slideCount ) ) {
123
141
return ;
124
- }
142
+ }
125
143
126
144
// Shifting targetSlide back into the range
127
145
if ( index < 0 ) {
@@ -290,21 +308,32 @@ var helpers = {
290
308
291
309
return 'vertical' ;
292
310
} ,
311
+ play : function ( ) {
312
+ var nextIndex ;
313
+
314
+ if ( ! this . state . mounted ) {
315
+ return false
316
+ }
317
+
318
+ if ( this . props . rtl ) {
319
+ nextIndex = this . state . currentSlide - this . props . slidesToScroll ;
320
+ } else {
321
+ if ( this . canGoNext ( Object . assign ( { } , this . props , this . state ) ) ) {
322
+ nextIndex = this . state . currentSlide + this . props . slidesToScroll ;
323
+ } else {
324
+ return false ;
325
+ }
326
+ }
327
+
328
+ this . slideHandler ( nextIndex ) ;
329
+ } ,
293
330
autoPlay : function ( ) {
294
331
if ( this . state . autoPlayTimer ) {
295
332
return ;
296
333
}
297
- var play = ( ) => {
298
- if ( this . state . mounted ) {
299
- var nextIndex = this . props . rtl ?
300
- this . state . currentSlide - this . props . slidesToScroll :
301
- this . state . currentSlide + this . props . slidesToScroll ;
302
- this . slideHandler ( nextIndex ) ;
303
- }
304
- } ;
305
334
if ( this . props . autoplay ) {
306
335
this . setState ( {
307
- autoPlayTimer : setInterval ( play , this . props . autoplaySpeed )
336
+ autoPlayTimer : setInterval ( this . play , this . props . autoplaySpeed )
308
337
} ) ;
309
338
}
310
339
} ,
0 commit comments