Skip to content

Commit

Permalink
Merge pull request #743 from ressourcenmangel/feature/rewind-on-prev
Browse files Browse the repository at this point in the history
Add option for rewind on prev button
  • Loading branch information
meandmax authored Oct 16, 2018
2 parents 51b22b6 + 73a9cf6 commit 0403c86
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ li {
<td>if slider reached the last slide, with next click the slider goes back to the startindex. (do not combine with infinite)</td>
<td>default: false</td>
</tr>
<tr>
<td>rewindPrev</td>
<td>if slider is on the first slide, with prev click the slider goes to the last slide. (do not combine with infinite)</td>
<td>default: false</td>
</tr>
<tr>
<td>slideSpeed</td>
<td>time in milliseconds for the animation of a valid slide attempt</td>
Expand Down
10 changes: 8 additions & 2 deletions dist/jquery.lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function lory(slider, opts) {
slidesToScroll = _options3.slidesToScroll,
infinite = _options3.infinite,
rewind = _options3.rewind,
rewindPrev = _options3.rewindPrev,
rewindSpeed = _options3.rewindSpeed,
ease = _options3.ease,
classNameActiveSlide = _options3.classNameActiveSlide,
Expand Down Expand Up @@ -282,6 +283,11 @@ function lory(slider, opts) {
nextIndex += infinite;
}

if (rewindPrev && Math.abs(position.x) === 0 && direction === false) {
nextIndex = slides.length - 1;
duration = rewindSpeed;
}

var nextOffset = Math.min(Math.max(slides[nextIndex].offsetLeft * -1, maxOffset * -1), 0);

if (rewind && Math.abs(position.x) === maxOffset && direction) {
Expand Down Expand Up @@ -332,7 +338,7 @@ function lory(slider, opts) {
* update classes for next and prev arrows
* based on user settings
*/
if (prevCtrl && !infinite && nextIndex === 0) {
if (prevCtrl && !infinite && !rewindPrev && nextIndex === 0) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down Expand Up @@ -385,7 +391,7 @@ function lory(slider, opts) {
} else {
slides = slice.call(slideContainer.children);

if (prevCtrl) {
if (prevCtrl && !options.rewindPrev) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.lory.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jquery.lory.min.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function lory(slider, opts) {
slidesToScroll = _options3.slidesToScroll,
infinite = _options3.infinite,
rewind = _options3.rewind,
rewindPrev = _options3.rewindPrev,
rewindSpeed = _options3.rewindSpeed,
ease = _options3.ease,
classNameActiveSlide = _options3.classNameActiveSlide,
Expand Down Expand Up @@ -282,6 +283,11 @@ function lory(slider, opts) {
nextIndex += infinite;
}

if (rewindPrev && Math.abs(position.x) === 0 && direction === false) {
nextIndex = slides.length - 1;
duration = rewindSpeed;
}

var nextOffset = Math.min(Math.max(slides[nextIndex].offsetLeft * -1, maxOffset * -1), 0);

if (rewind && Math.abs(position.x) === maxOffset && direction) {
Expand Down Expand Up @@ -332,7 +338,7 @@ function lory(slider, opts) {
* update classes for next and prev arrows
* based on user settings
*/
if (prevCtrl && !infinite && nextIndex === 0) {
if (prevCtrl && !infinite && !rewindPrev && nextIndex === 0) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down Expand Up @@ -385,7 +391,7 @@ function lory(slider, opts) {
} else {
slides = slice.call(slideContainer.children);

if (prevCtrl) {
if (prevCtrl && !options.rewindPrev) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/lory.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/lory.min.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/lory.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export function lory (slider, opts) {
slidesToScroll,
infinite,
rewind,
rewindPrev,
rewindSpeed,
ease,
classNameActiveSlide,
Expand Down Expand Up @@ -176,6 +177,11 @@ export function lory (slider, opts) {
nextIndex += infinite;
}

if (rewindPrev && Math.abs(position.x) === 0 && direction === false) {
nextIndex = slides.length - 1;
duration = rewindSpeed;
}

let nextOffset = Math.min(Math.max(slides[nextIndex].offsetLeft * -1, maxOffset * -1), 0);

if (rewind && Math.abs(position.x) === maxOffset && direction) {
Expand Down Expand Up @@ -227,7 +233,7 @@ export function lory (slider, opts) {
* update classes for next and prev arrows
* based on user settings
*/
if (prevCtrl && !infinite && nextIndex === 0) {
if (prevCtrl && !infinite && !rewindPrev && nextIndex === 0) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down Expand Up @@ -278,7 +284,7 @@ export function lory (slider, opts) {
} else {
slides = slice.call(slideContainer.children);

if (prevCtrl) {
if (prevCtrl && !options.rewindPrev) {
prevCtrl.classList.add(classNameDisabledPrevCtrl);
}

Expand Down

0 comments on commit 0403c86

Please sign in to comment.