Bladeren bron

Support `>|` for moving a carousel to the last page.

Naotoshi Fujita 2 jaren geleden
bovenliggende
commit
da7407c733

+ 3 - 1
dist/js/splide.cjs.js

@@ -1388,13 +1388,15 @@ const Controller = (Splide, Components, options, event) => {
   function parse(control) {
     let index = currIndex;
     if (isString(control)) {
-      const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
+      const [, indicator, number] = control.match(/([+\-<>]\|?)(\d+)?/) || [];
       if (indicator === "+" || indicator === "-") {
         index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
       } else if (indicator === ">") {
         index = number ? toIndex(+number) : getNext(true);
       } else if (indicator === "<") {
         index = getPrev(true);
+      } else if (indicator === ">|") {
+        index = endIndex;
       }
     } else {
       index = isLoop ? control : clamp(control, 0, endIndex);

+ 3 - 1
dist/js/splide.esm.js

@@ -1384,13 +1384,15 @@ const Controller = (Splide, Components, options, event) => {
   function parse(control) {
     let index = currIndex;
     if (isString(control)) {
-      const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
+      const [, indicator, number] = control.match(/([+\-<>]\|?)(\d+)?/) || [];
       if (indicator === "+" || indicator === "-") {
         index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
       } else if (indicator === ">") {
         index = number ? toIndex(+number) : getNext(true);
       } else if (indicator === "<") {
         index = getPrev(true);
+      } else if (indicator === ">|") {
+        index = endIndex;
       }
     } else {
       index = isLoop ? control : clamp(control, 0, endIndex);

+ 3 - 1
dist/js/splide.js

@@ -1384,13 +1384,15 @@
     function parse(control) {
       let index = currIndex;
       if (isString(control)) {
-        const [, indicator, number] = control.match(/([+\-<>])(\d+)?/) || [];
+        const [, indicator, number] = control.match(/([+\-<>]\|?)(\d+)?/) || [];
         if (indicator === "+" || indicator === "-") {
           index = computeDestIndex(currIndex + +`${indicator}${+number || 1}`, currIndex);
         } else if (indicator === ">") {
           index = number ? toIndex(+number) : getNext(true);
         } else if (indicator === "<") {
           index = getPrev(true);
+        } else if (indicator === ">|") {
+          index = endIndex;
         }
       } else {
         index = isLoop ? control : clamp(control, 0, endIndex);

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


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


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


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

@@ -205,7 +205,7 @@ export const Controller: ComponentConstructor<ControllerComponent> = ( Splide, C
     let index = currIndex;
 
     if ( isString( control ) ) {
-      const [ , indicator, number ] = control.match( /([+\-<>])(\d+)?/ ) || [];
+      const [ , indicator, number ] = control.match( /([+\-<>]\|?)(\d+)?/ ) || [];
 
       if ( indicator === '+' || indicator === '-' ) {
         index = computeDestIndex( currIndex + +`${ indicator }${ +number || 1 }`, currIndex );
@@ -213,6 +213,8 @@ export const Controller: ComponentConstructor<ControllerComponent> = ( Splide, C
         index = number ? toIndex( +number ) : getNext( true );
       } else if ( indicator === '<' ) {
         index = getPrev( true );
+      } else if ( indicator === '>|' ) {
+        index = endIndex;
       }
     } else {
       index = isLoop ? control : clamp( control, 0, endIndex );

+ 7 - 0
src/js/components/Controller/test/slide.test.ts

@@ -115,4 +115,11 @@ describe( 'Controller#go()', () => {
     splide.go( -100 );
     expect( splide.index ).toBe( 0 );
   } );
+
+  test( 'can move the slider to the end page.', () => {
+    const splide = init( { speed: 0 } );
+
+    splide.go( '>|' );
+    expect( splide.index ).toBe( splide.length - 1 );
+  } );
 } );

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