Skip to content

Commit

Permalink
disable loop when rewind is true
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlanyuan committed Sep 29, 2016
1 parent 70d4889 commit 5014823
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@ npm install tiny-slider
## Features
- responsive
- fixed width
- gutter
- loop
- rewind ([pull 10](https://github.com/ganlanyuan/tiny-slider/pull/10))
- slide by page
- customize controls / nav / gutter
- customize controls / nav
- autoplay
- auto height
- lazyload
- touch support
- arrow keys
- accessibility for people using keyboard navigation or screen readers
(thank [DouglasdeMoura](https://github.com/DouglasdeMoura) and [epigeyre](https://github.com/epigeyre) for the sugestion, [issue4](https://github.com/ganlanyuan/tiny-slider/issues/4))
- accessibility for people using keyboard navigation or screen readers ([issue4](https://github.com/ganlanyuan/tiny-slider/issues/4))

## Usage
##### 1. Include tiny-slider
Expand Down Expand Up @@ -112,7 +113,8 @@ Default:
autoHeight: false,
responsive: false,
lazyload: false,
touch: true
touch: true,
rewind: false
}
```

Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class `tiny-next` => attribute `[data-controls="next"`.
- Fixed: an issue with `items`, when container width is shorter than one slide in fixedWidth slider.
-->

#### v0.5.0
- Added: `rewind` option. Thanks [faboulaws](https://github.com/ganlanyuan/tiny-slider/pull/10).

#### v0.4.2
- Fixed: a length issue when slider parent element has non-zero `padding`.

Expand Down
2 changes: 1 addition & 1 deletion dist/min/tiny-slider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/min/tiny-slider.native.js

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions dist/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ var tinySlider = (function () {
responsive: false,
lazyload: false,
touch: true,
rewind: false
}, options || {});

// make sure slider container exists
Expand Down Expand Up @@ -689,7 +690,8 @@ var tinySlider = (function () {
autoplayTimeout = options.autoplayTimeout,
autoplayDirection = (options.autoplayDirection === 'forward') ? 1 : -1,
autoplayText = options.autoplayText,
loop = (fixedWidth && !options.maxContainerWidth) ? false : options.loop,
rewind = options.rewind,
loop = (rewind || fixedWidth && !options.maxContainerWidth) ? false : options.loop,
autoHeight = options.autoHeight,
slideByPage = options.slideByPage,
lazyload = options.lazyload,
Expand Down Expand Up @@ -949,8 +951,7 @@ var tinySlider = (function () {
} else {
prevButton.disabled = false;
}

if (index === sliderCount - items) {
if (index === sliderCount - items && !rewind) {
nextButton.disabled = true;
changeFocus(nextButton, prevButton);
} else {
Expand Down Expand Up @@ -1129,7 +1130,11 @@ var tinySlider = (function () {
}

function onClickControlNext() {
onClickControl(1);
if(index === sliderCount - items && rewind){
onClickControl(- sliderCount + items);
}else{
onClickControl(1);
}
}

// on doc click
Expand Down
13 changes: 9 additions & 4 deletions dist/tiny-slider.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var tinySlider = (function () {
responsive: false,
lazyload: false,
touch: true,
rewind: false
}, options || {});

// make sure slider container exists
Expand Down Expand Up @@ -90,7 +91,8 @@ var tinySlider = (function () {
autoplayTimeout = options.autoplayTimeout,
autoplayDirection = (options.autoplayDirection === 'forward') ? 1 : -1,
autoplayText = options.autoplayText,
loop = (fixedWidth && !options.maxContainerWidth) ? false : options.loop,
rewind = options.rewind,
loop = (rewind || fixedWidth && !options.maxContainerWidth) ? false : options.loop,
autoHeight = options.autoHeight,
slideByPage = options.slideByPage,
lazyload = options.lazyload,
Expand Down Expand Up @@ -350,8 +352,7 @@ var tinySlider = (function () {
} else {
prevButton.disabled = false;
}

if (index === sliderCount - items) {
if (index === sliderCount - items && !rewind) {
nextButton.disabled = true;
changeFocus(nextButton, prevButton);
} else {
Expand Down Expand Up @@ -530,7 +531,11 @@ var tinySlider = (function () {
}

function onClickControlNext() {
onClickControl(1);
if(index === sliderCount - items && rewind){
onClickControl(- sliderCount + items);
}else{
onClickControl(1);
}
}

// on doc click
Expand Down
6 changes: 3 additions & 3 deletions src/tiny-slider.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ var tinySlider = (function () {
autoplayTimeout = options.autoplayTimeout,
autoplayDirection = (options.autoplayDirection === 'forward') ? 1 : -1,
autoplayText = options.autoplayText,
loop = (fixedWidth && !options.maxContainerWidth) ? false : options.loop,
rewind = options.rewind,
loop = (rewind || fixedWidth && !options.maxContainerWidth) ? false : options.loop,
autoHeight = options.autoHeight,
slideByPage = options.slideByPage,
lazyload = options.lazyload,
touch = options.touch,
rewind = options.rewind,

sliderId,
slideWidth,
Expand Down Expand Up @@ -532,7 +532,7 @@ var tinySlider = (function () {

function onClickControlNext() {
if(index === sliderCount - items && rewind){
onClickControl(-sliderCount);
onClickControl(- sliderCount + items);
}else{
onClickControl(1);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
responsive: {
500: 2,
800: 3,
}
},
rewind: true
}).init();

tinySlider({
Expand Down Expand Up @@ -171,7 +172,7 @@
tinySlider({
container: document.querySelector('.autoplay'),
items: 3,
autoplay: true,
// autoplay: true,
speed: 300,
autoplayTimeout: 3000,
autoplayText: ['▶', '❚❚']
Expand Down

0 comments on commit 5014823

Please sign in to comment.