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