Parcourir la source

Bug Fix: `getAdjacent()` returns an incorrect index when the `perMove` option is 2.

NaotoshiFujita il y a 3 ans
Parent
commit
120776f6e6

+ 1 - 1
dist/js/splide-renderer.min.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 3.1.2
+ * Version  : 3.1.3
  * License  : MIT
  * Copyright: 2021 Naotoshi Fujita
  */

+ 2 - 2
dist/js/splide.cjs.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 3.1.2
+ * Version  : 3.1.3
  * License  : MIT
  * Copyright: 2021 Naotoshi Fujita
  */
@@ -1354,7 +1354,7 @@ function Controller(Splide2, Components2, options) {
     return getAdjacent(true, destination);
   }
   function getAdjacent(prev, destination) {
-    const number = perMove || hasFocus() ? 1 : perPage;
+    const number = perMove || (hasFocus() ? 1 : perPage);
     const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
     if (dest === -1 && isSlide) {
       if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {

+ 2 - 2
dist/js/splide.esm.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 3.1.2
+ * Version  : 3.1.3
  * License  : MIT
  * Copyright: 2021 Naotoshi Fujita
  */
@@ -1350,7 +1350,7 @@ function Controller(Splide2, Components2, options) {
     return getAdjacent(true, destination);
   }
   function getAdjacent(prev, destination) {
-    const number = perMove || hasFocus() ? 1 : perPage;
+    const number = perMove || (hasFocus() ? 1 : perPage);
     const dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
     if (dest === -1 && isSlide) {
       if (!approximatelyEqual(getPosition(), getLimit(!prev), 1)) {

+ 2 - 2
dist/js/splide.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 /*!
  * Splide.js
- * Version  : 3.1.2
+ * Version  : 3.1.3
  * License  : MIT
  * Copyright: 2021 Naotoshi Fujita
  */
@@ -1611,7 +1611,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     }
 
     function getAdjacent(prev, destination) {
-      var number = perMove || hasFocus() ? 1 : perPage;
+      var number = perMove || (hasFocus() ? 1 : perPage);
       var dest = computeDestIndex(currIndex + number * (prev ? -1 : 1), currIndex);
 
       if (dest === -1 && isSlide) {

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
dist/js/splide.js.map


Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


+ 1 - 1
dist/types/types/options.d.ts

@@ -285,7 +285,7 @@ export interface ResponsiveOptions {
      */
     flickPower?: number;
     /**
-     * Limies the number of pages to move by "flick".
+     * Limits the number of pages to move by "flick".
      */
     flickMaxPages?: number;
     /**

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@splidejs/splide",
-  "version": "3.1.2",
+  "version": "3.1.3",
   "description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
   "author": "Naotoshi Fujita",
   "license": "MIT",

+ 1 - 1
src/js/components/Controller/Controller.ts

@@ -197,7 +197,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
    * @return An adjacent index if available, or otherwise `-1`.
    */
   function getAdjacent( prev: boolean, destination?: boolean ): number {
-    const number = perMove || hasFocus() ? 1 : perPage;
+    const number = perMove || ( hasFocus() ? 1 : perPage );
     const dest   = computeDestIndex( currIndex + number * ( prev ? -1 : 1 ), currIndex );
 
     if ( dest === -1 && isSlide ) {

+ 13 - 0
src/js/components/Controller/test/getAdjacent.test.ts

@@ -43,6 +43,19 @@ describe( 'Controller#getAdjacent()', () => {
     expect( Controller.getPrev() ).toBe( 2 );
   } );
 
+  test( 'can return the next/previous index with respecting the perMove option that is above 1.', () => {
+    const splide = init( { speed: 0, perPage: 3, perMove: 2 } );
+    const { Controller } = splide.Components;
+
+    expect( Controller.getNext() ).toBe( 2 );
+    expect( Controller.getPrev() ).toBe( -1 );
+
+    splide.go( 3 );
+
+    expect( Controller.getNext() ).toBe( 5 );
+    expect( Controller.getPrev() ).toBe( 1 );
+  } );
+
   test( 'can return -1 if there is no adjacent slide.', () => {
     const splide = init( { speed: 0 } );
     const { Controller } = splide.Components;

+ 48 - 36
src/js/test/php/examples/default.php

@@ -19,50 +19,62 @@ $settings = get_settings();
   <script>
     document.addEventListener( 'DOMContentLoaded', function () {
       var splide = new Splide( '#splide01', {
-        type             : 'loop',
-        perPage          : 3,
-        gap              : '1.5rem',
-        // speed: 600,
-        cover: true,
-        height           : 400,
-        // waitForTransition: false,
-        // direction        : 'ltr',
-        // drag      : true,
-        // pagination: false,
-        // arrows: false,
-        useScroll: true,
-        // focus: 'center',
-        dragMinThreshold: {
-          mouse: 4,
-        },
-        classes: {
-          arrows: 'splide__arrows splide__test',
-        },
-        slideFocus: false,
+        type   : 'slide',
+        perPage: 3,
+        // direction: 'ttb',
+        // height: 1000,
+        perMove: 2,
+        rewind: true,
+        // focus: 0,
         breakpoints: {
           1000: {
-            // direction: 'rtl',
-            // drag: false,
-            perPage: 2,
-          }
+            destroy: true,
+            // type   : 'fade',
+            // perPage: 1,
+          },
         },
       } );
 
-      splide.on( 'moved', () => {
-        console.log( 'moved' );
-      } );
+      // splide.on( 'moved', () => {
+      //   console.log( 'moved' );
+      // } );
+      //
+      // splide.on( 'visible', Slide => {
+      //   console.log( 'visible', Slide.index );
+      // } );
+      //
+      // splide.on( 'hidden', Slide => {
+      //   console.log( 'hidden', Slide.index );
+      // } );
+      //
+      // splide.on( 'click', () => {
+      //   console.log( 'click' );
+      // } );
 
-      splide.on( 'visible', Slide => {
-        console.log( 'visible', Slide.index );
-      } );
 
-      splide.on( 'hidden', Slide => {
-        console.log( 'hidden', Slide.index );
-      } );
+      // let prevType;
+      //
+      // splide.on( 'update', function onUpdate( options ) {
+      //   if ( prevType && prevType !== options.type ) {
+      //     splide.destroy();
+      //     splide.mount();
+      //     splide.on( 'update', onUpdate );
+      //
+      //     console.log( 'remount' );
+      //   }
+      //
+      //   prevType = options.type;
+      // } );
+
+      // let direction;
+
+      // splide.on( 'updated', options => {
+      //   if ( direction !== options.direction ) {
+      //     splide.refresh();
+      //     direction = options.direction;
+      //   }
+      // } );
 
-      splide.on( 'click', () => {
-        console.log( 'click' );
-      } );
 
       splide.mount();
     } );

+ 1 - 1
src/js/test/php/parts.php

@@ -18,7 +18,7 @@ function render_slides( $number = 10, $text = false ) {
     if ( $text ) {
       printf( '<span>%s</span>', $i + 1 );
     } else {
-      printf( '<img src="../../assets/images/pics/slide%02d.jpg">', $i + 1 );
+      printf( '<img src="../../assets/images/pics/slide%02d.jpg"><a href="#">hog</a>', $i + 1 );
     }
 
     echo '</li>' . PHP_EOL;

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff