Skip to content

Commit

Permalink
Bug Fix: The page index was incorrect in the loop mode (#482).
Browse files Browse the repository at this point in the history
  • Loading branch information
NaotoshiFujita committed Nov 4, 2021
1 parent 5351ec3 commit da8452a
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist/js/splide-renderer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/js/splide.cjs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Splide.js
* Version : 3.2.4
* Version : 3.2.5
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
Expand Down Expand Up @@ -1392,7 +1392,7 @@ function Controller(Splide2, Components2, options) {
}
}
} else {
if (!isLoop && !incremental && dest !== from) {
if (!incremental && dest !== from) {
dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/splide.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Splide.js
* Version : 3.2.4
* Version : 3.2.5
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
Expand Down Expand Up @@ -1388,7 +1388,7 @@ function Controller(Splide2, Components2, options) {
}
}
} else {
if (!isLoop && !incremental && dest !== from) {
if (!incremental && dest !== from) {
dest = perMove ? dest : toIndex(toPage(from) + (dest < from ? -1 : 1));
}
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/splide.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/js/splide.min.js

Large diffs are not rendered by default.

Binary file modified dist/js/splide.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splidejs/splide",
"version": "3.2.4",
"version": "3.2.5",
"description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
"author": "Naotoshi Fujita",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/Controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
}
}
} else {
if ( ! isLoop && ! incremental && dest !== from ) {
if ( ! incremental && dest !== from ) {
dest = perMove ? dest : toIndex( toPage( from ) + ( dest < from ? -1 : 1 ) );
}
}
Expand Down
14 changes: 10 additions & 4 deletions src/js/components/Controller/test/loop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ describe( 'Controller#go()', () => {
expect( splide.index ).toBe( 0 );
} );

test( 'can loop the slider, using the end index.', () => {
// The end index is 1.
const splide = init( { rewind: true, perPage: 3, speed: 0 }, { length: 4 } );
test( 'can loop the slider, using the index of the last page.', () => {
// The length is 10 and the last page only contains the slide 9.
const splide = init( { type: 'loop', perPage: 3, speed: 0 } );

splide.go( '<' );
expect( splide.index ).toBe( 1 );
expect( splide.index ).toBe( 9 ); // 9, 0, 1

splide.go( '<' );
expect( splide.index ).toBe( 6 ); // 6, 7, 8

splide.go( '>' );
expect( splide.index ).toBe( 7 ); // 7, 8, 9

splide.go( '>' );
expect( splide.index ).toBe( 0 );
Expand Down
16 changes: 8 additions & 8 deletions src/js/test/php/examples/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<script>
document.addEventListener( 'DOMContentLoaded', function () {
var splide = new Splide( '#splide01', {
type : 'slide',
perPage: 3,
perMove: 2,
type : 'loop',
perPage: 5,
// perMove: 2,
rewind: true,
padding: {
right: 0,
left: 40,
},
// padding: {
// right: 0,
// left: 40,
// },
noDrag: 'button',
} );

Expand Down Expand Up @@ -58,7 +58,7 @@
</head>
<body>

<?php render(); ?>
<?php render( 'splide01', 12, true ); ?>

<pre></pre>

Expand Down

0 comments on commit da8452a

Please sign in to comment.