Jelajahi Sumber

Jump to the current index on refresh.

NaotoshiFujita 3 tahun lalu
induk
melakukan
4b62d1fab4

+ 4 - 4
dist/js/splide.js

@@ -1598,10 +1598,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       slideCount = getLength(true);
       perMove = options.perMove;
       perPage = options.perPage;
-
-      if (currIndex >= slideCount) {
-        Move.jump(currIndex = slideCount - 1);
-      }
+      currIndex = min(currIndex, slideCount - 1);
+      Move.jump(currIndex);
     }
 
     function reindex() {
@@ -2868,6 +2866,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
     _proto.go = function go(control) {
       this._Components.Controller.go(control);
+
+      return this;
     };
 
     _proto.on = function on(events, callback) {

File diff ditekan karena terlalu besar
+ 0 - 0
dist/js/splide.js.map


+ 3 - 4
src/js/components/Controller/Controller.ts

@@ -3,7 +3,7 @@ import { LOOP, SLIDE } from '../../constants/types';
 import { EventInterface } from '../../constructors';
 import { Splide } from '../../core/Splide/Splide';
 import { BaseComponent, Components, Options } from '../../types';
-import { approximatelyEqual, between, clamp, floor, isString, isUndefined, max } from '../../utils';
+import { approximatelyEqual, between, clamp, floor, isString, isUndefined, max, min } from '../../utils';
 
 
 /**
@@ -83,10 +83,9 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
     slideCount = getLength( true );
     perMove    = options.perMove;
     perPage    = options.perPage;
+    currIndex  = min( currIndex, slideCount - 1 );
 
-    if ( currIndex >= slideCount ) {
-      Move.jump( ( currIndex = slideCount - 1 ) );
-    }
+    Move.jump( currIndex );
   }
 
   /**

+ 5 - 2
src/js/core/Splide/Splide.ts

@@ -185,10 +185,13 @@ export class Splide {
    * splide.go( '>2' );
    * ```
    *
-   * @param control
+   * @param control - A control pattern.
+   *
+   * @return `this`
    */
-  go( control: number | string ): void {
+  go( control: number | string ): this {
     this._Components.Controller.go( control );
+    return this;
   }
 
   /**

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini