Skip to content

Commit 5a6bad0

Browse files
authored
Merge pull request akiran#506 from blairanderson/prevent-autoplay
prevent autoplay transition when there are no extra cards akiran#505
2 parents d8c2638 + 14a6f90 commit 5a6bad0

File tree

2 files changed

+43
-26
lines changed

2 files changed

+43
-26
lines changed

src/arrows.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import React from 'react';
44
import classnames from 'classnames';
5+
import Helpers from './mixins/helpers';
56

67
export var PrevArrow = React.createClass({
78

@@ -47,24 +48,11 @@ export var NextArrow = React.createClass({
4748
var nextClasses = {'slick-arrow': true, 'slick-next': true};
4849
var nextHandler = this.clickHandler.bind(this, {message: 'next'});
4950

50-
if (!this.props.infinite) {
51-
if (this.props.centerMode) {
52-
// check if current slide is last slide
53-
if (this.props.currentSlide >= (this.props.slideCount - 1)) {
54-
nextClasses['slick-disabled'] = true;
55-
nextHandler = null;
56-
}
57-
} else {
58-
// check if all slides are shown in slider
59-
if (this.props.slideCount <= this.props.slidesToShow ||
60-
this.props.currentSlide >= (this.props.slideCount - this.props.slidesToShow)) {
61-
nextClasses['slick-disabled'] = true;
62-
nextHandler = null;
63-
}
64-
}
51+
if (!Helpers.canGoNext(this.props)) {
52+
nextClasses['slick-disabled'] = true;
53+
nextHandler = null;
6554
}
6655

67-
6856
var nextArrowProps = {
6957
key: '1',
7058
'data-role': 'none',

src/mixins/helpers.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,24 @@ var helpers = {
105105
}
106106
}
107107
},
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+
},
108126
slideHandler: function (index) {
109127
// Functionality of animateSlide and postSlide is merged into this function
110128
// console.log('slideHandler', index);
@@ -123,7 +141,7 @@ var helpers = {
123141
if(this.props.infinite === false &&
124142
(index < 0 || index >= this.state.slideCount)) {
125143
return;
126-
}
144+
}
127145

128146
// Shifting targetSlide back into the range
129147
if (index < 0) {
@@ -292,21 +310,32 @@ var helpers = {
292310

293311
return 'vertical';
294312
},
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+
},
295332
autoPlay: function () {
296333
if (this.state.autoPlayTimer) {
297334
return;
298335
}
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-
};
307336
if (this.props.autoplay) {
308337
this.setState({
309-
autoPlayTimer: setInterval(play, this.props.autoplaySpeed)
338+
autoPlayTimer: setInterval(this.play, this.props.autoplaySpeed)
310339
});
311340
}
312341
},

0 commit comments

Comments
 (0)