Browse Source

Bug Fix: perMove didn't work properly with autoplay(#50).

NaotoshiFujita 5 years ago
parent
commit
04afb570fb

+ 32 - 21
dist/js/splide.esm.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 2.3.1
+ * Version  : 2.3.2
  * License  : MIT
  * Copyright: 2020 Naotoshi Fujita
  */
@@ -2474,7 +2474,7 @@ var controller_floor = Math.floor;
      */
     parse: function parse(control) {
       var index = Splide.index;
-      var matches = String(control).match(/([+\-<>])(\d+)?/);
+      var matches = String(control).match(/([+\-<>]+)(\d+)?/);
       var indicator = matches ? matches[1] : '';
       var number = matches ? parseInt(matches[2]) : 0;
 
@@ -2488,11 +2488,8 @@ var controller_floor = Math.floor;
           break;
 
         case '>':
-          index = this.toIndex(number > -1 ? number : this.toPage(index) + 1);
-          break;
-
         case '<':
-          index = this.toIndex(number > -1 ? number : this.toPage(index) - 1);
+          index = parsePage(number, index, indicator === '<');
           break;
 
         default:
@@ -2663,7 +2660,7 @@ var controller_floor = Math.floor;
 
   };
   /**
-   * Listen some events.
+   * Listen to some events.
    */
 
   function bind() {
@@ -2684,6 +2681,31 @@ var controller_floor = Math.floor;
   function hasFocus() {
     return options.focus !== false;
   }
+  /**
+   * Return the next or previous page index computed by the page number and current index.
+   *
+   * @param {number}  number - Specify the page number.
+   * @param {number}  index  - Current index.
+   * @param {boolean} prev   - Prev or next.
+   *
+   * @return {number} - Slide index.
+   */
+
+
+  function parsePage(number, index, prev) {
+    if (number > -1) {
+      return Controller.toIndex(number);
+    }
+
+    var perMove = options.perMove;
+    var sign = prev ? -1 : 1;
+
+    if (perMove) {
+      return index + perMove * sign;
+    }
+
+    return Controller.toIndex(Controller.toPage(index) + sign);
+  }
 
   return Controller;
 });
@@ -4563,27 +4585,16 @@ var SIZE = 40;
     }
   };
   /**
-   * Listen native and custom events.
+   * Listen to native and custom events.
    */
 
   function bind() {
     Splide.on('click', function () {
-      return onClick(true);
+      Splide.go('<');
     }, prev).on('click', function () {
-      return onClick(false);
+      Splide.go('>');
     }, next).on('mounted move updated refresh', updateDisabled);
   }
-  /**
-   * Called when an arrow is clicked.
-   *
-   * @param {boolean} prev - If true, the previous arrow is clicked.
-   */
-
-
-  function onClick(prev) {
-    var perMove = Splide.options.perMove;
-    Splide.go(perMove ? "" + (prev ? '-' : '+') + perMove : prev ? '<' : '>');
-  }
   /**
    * Update a disabled attribute.
    */

+ 32 - 21
dist/js/splide.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 2.3.1
+ * Version  : 2.3.2
  * License  : MIT
  * Copyright: 2020 Naotoshi Fujita
  */
@@ -2464,7 +2464,7 @@ var controller_floor = Math.floor;
      */
     parse: function parse(control) {
       var index = Splide.index;
-      var matches = String(control).match(/([+\-<>])(\d+)?/);
+      var matches = String(control).match(/([+\-<>]+)(\d+)?/);
       var indicator = matches ? matches[1] : '';
       var number = matches ? parseInt(matches[2]) : 0;
 
@@ -2478,11 +2478,8 @@ var controller_floor = Math.floor;
           break;
 
         case '>':
-          index = this.toIndex(number > -1 ? number : this.toPage(index) + 1);
-          break;
-
         case '<':
-          index = this.toIndex(number > -1 ? number : this.toPage(index) - 1);
+          index = parsePage(number, index, indicator === '<');
           break;
 
         default:
@@ -2653,7 +2650,7 @@ var controller_floor = Math.floor;
 
   };
   /**
-   * Listen some events.
+   * Listen to some events.
    */
 
   function bind() {
@@ -2674,6 +2671,31 @@ var controller_floor = Math.floor;
   function hasFocus() {
     return options.focus !== false;
   }
+  /**
+   * Return the next or previous page index computed by the page number and current index.
+   *
+   * @param {number}  number - Specify the page number.
+   * @param {number}  index  - Current index.
+   * @param {boolean} prev   - Prev or next.
+   *
+   * @return {number} - Slide index.
+   */
+
+
+  function parsePage(number, index, prev) {
+    if (number > -1) {
+      return Controller.toIndex(number);
+    }
+
+    var perMove = options.perMove;
+    var sign = prev ? -1 : 1;
+
+    if (perMove) {
+      return index + perMove * sign;
+    }
+
+    return Controller.toIndex(Controller.toPage(index) + sign);
+  }
 
   return Controller;
 });
@@ -4553,27 +4575,16 @@ var SIZE = 40;
     }
   };
   /**
-   * Listen native and custom events.
+   * Listen to native and custom events.
    */
 
   function bind() {
     Splide.on('click', function () {
-      return onClick(true);
+      Splide.go('<');
     }, prev).on('click', function () {
-      return onClick(false);
+      Splide.go('>');
     }, next).on('mounted move updated refresh', updateDisabled);
   }
-  /**
-   * Called when an arrow is clicked.
-   *
-   * @param {boolean} prev - If true, the previous arrow is clicked.
-   */
-
-
-  function onClick(prev) {
-    var perMove = Splide.options.perMove;
-    Splide.go(perMove ? "" + (prev ? '-' : '+') + perMove : prev ? '<' : '>');
-  }
   /**
    * Update a disabled attribute.
    */

File diff suppressed because it is too large
+ 1 - 1
dist/js/splide.min.js


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


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@splidejs/splide",
-  "version": "2.3.1",
+  "version": "2.3.2",
   "description": "Splide is a lightweight and powerful slider without any dependencies.",
   "author": "Naotoshi Fujita",
   "license": "MIT",

+ 3 - 13
src/js/components/arrows/index.js

@@ -119,25 +119,15 @@ export default ( Splide, Components, name ) => {
 	};
 
 	/**
-	 * Listen native and custom events.
+	 * Listen to native and custom events.
 	 */
 	function bind() {
 		Splide
-			.on( 'click', () => onClick( true ), prev )
-			.on( 'click', () => onClick( false ), next )
+			.on( 'click', () => { Splide.go( '<' ) }, prev )
+			.on( 'click', () => { Splide.go( '>' ) }, next )
 			.on( 'mounted move updated refresh', updateDisabled );
 	}
 
-	/**
-	 * Called when an arrow is clicked.
-	 *
-	 * @param {boolean} prev - If true, the previous arrow is clicked.
-	 */
-	function onClick( prev ) {
-		const perMove = Splide.options.perMove;
-		Splide.go( perMove ? `${ prev ? '-' : '+' }${ perMove }` : ( prev ? '<' : '>' ) );
-	}
-
 	/**
 	 * Update a disabled attribute.
 	 */

+ 27 - 6
src/js/components/controller/index.js

@@ -77,7 +77,7 @@ export default ( Splide, Components ) => {
 		parse( control ) {
 			let index = Splide.index;
 
-			const matches   = String( control ).match( /([+\-<>])(\d+)?/ );
+			const matches   = String( control ).match( /([+\-<>]+)(\d+)?/ );
 			const indicator = matches ? matches[1] : '';
 			const number    = matches ? parseInt( matches[2] ) : 0;
 
@@ -91,11 +91,8 @@ export default ( Splide, Components ) => {
 					break;
 
 				case '>':
-					index = this.toIndex( number > -1 ? number : this.toPage( index ) + 1 );
-					break;
-
 				case '<':
-					index = this.toIndex( number > -1 ? number : this.toPage( index ) - 1 );
+					index = parsePage( number, index, indicator === '<' );
 					break;
 
 				default:
@@ -269,7 +266,7 @@ export default ( Splide, Components ) => {
 	};
 
 	/**
-	 * Listen some events.
+	 * Listen to some events.
 	 */
 	function bind() {
 		Splide
@@ -289,5 +286,29 @@ export default ( Splide, Components ) => {
 		return options.focus !== false;
 	}
 
+	/**
+	 * Return the next or previous page index computed by the page number and current index.
+	 *
+	 * @param {number}  number - Specify the page number.
+	 * @param {number}  index  - Current index.
+	 * @param {boolean} prev   - Prev or next.
+	 *
+	 * @return {number} - Slide index.
+	 */
+	function parsePage( number, index, prev ) {
+		if ( number > -1 ) {
+			return Controller.toIndex( number );
+		}
+
+		const perMove = options.perMove;
+		const sign    = prev ? -1 : 1;
+
+		if ( perMove ) {
+			return index + perMove * sign;
+		}
+
+		return Controller.toIndex( Controller.toPage( index ) + sign );
+	}
+
 	return Controller;
 }

Some files were not shown because too many files changed in this diff