NaotoshiFujita 5 سال پیش
والد
کامیت
b1cfc0fd67

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 0
dist/js/splide.min.js


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


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

@@ -105,7 +105,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - A computed page number.
 		 * @return {number} - A computed page number.
 		 */
 		 */
 		pageToIndex( page ) {
 		pageToIndex( page ) {
-			if ( options.focus !== false ) {
+			if ( hasFocus() ) {
 				return page;
 				return page;
 			}
 			}
 
 
@@ -131,7 +131,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - A computed page number.
 		 * @return {number} - A computed page number.
 		 */
 		 */
 		indexToPage( index ) {
 		indexToPage( index ) {
-			if ( options.focus !== false ) {
+			if ( hasFocus() ) {
 				return index;
 				return index;
 			}
 			}
 
 
@@ -207,7 +207,7 @@ export default ( Splide, Components ) => {
 		 */
 		 */
 		get pageLength() {
 		get pageLength() {
 			const length = Splide.length;
 			const length = Splide.length;
-			return options.focus !== false ? length : Math.ceil( length / options.perPage );
+			return hasFocus() ? length : Math.ceil( length / options.perPage );
 		},
 		},
 
 
 		/**
 		/**
@@ -218,7 +218,7 @@ export default ( Splide, Components ) => {
 		get edgeIndex() {
 		get edgeIndex() {
 			const length = Splide.length;
 			const length = Splide.length;
 
 
-			if ( options.focus !== false || options.isNavigation || Splide.is( LOOP ) ) {
+			if ( hasFocus() || options.isNavigation || Splide.is( LOOP ) ) {
 				return length - 1;
 				return length - 1;
 			}
 			}
 
 
@@ -231,7 +231,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - The index of the previous slide if available. -1 otherwise.
 		 * @return {number} - The index of the previous slide if available. -1 otherwise.
 		 */
 		 */
 		get prevIndex() {
 		get prevIndex() {
-			let prev = this.parse( '-' );
+			let prev = Splide.index - 1;
 
 
 			if ( Splide.is( LOOP ) || options.rewind ) {
 			if ( Splide.is( LOOP ) || options.rewind ) {
 				prev = this.rewind( prev );
 				prev = this.rewind( prev );
@@ -246,7 +246,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - The index of the next slide if available. -1 otherwise.
 		 * @return {number} - The index of the next slide if available. -1 otherwise.
 		 */
 		 */
 		get nextIndex() {
 		get nextIndex() {
-			let next = this.parse( '+' );
+			let next = Splide.index + 1;
 
 
 			if ( Splide.is( LOOP ) || options.rewind ) {
 			if ( Splide.is( LOOP ) || options.rewind ) {
 				next = this.rewind( next );
 				next = this.rewind( next );
@@ -268,5 +268,14 @@ export default ( Splide, Components ) => {
 			} );
 			} );
 	}
 	}
 
 
+	/**
+	 * Verify if the focus option is available or not.
+	 *
+	 * @return {boolean} - True if a slider has the focus option.
+	 */
+	function hasFocus() {
+		return Splide.options.focus !== false;
+	}
+
 	return Controller;
 	return Controller;
 }
 }

+ 1 - 1
src/js/components/layout/resolvers/vertical.js

@@ -97,7 +97,7 @@ export default ( Splide, Components, options ) => {
 		 */
 		 */
 		get height() {
 		get height() {
 			const height = options.height || this.width * options.heightRatio;
 			const height = options.height || this.width * options.heightRatio;
-			exist( height, '"height" or "heightRatio" must be given in TTB mode.' );
+			exist( height, '"height" or "heightRatio" is missing.' );
 			return toPixel( Splide.root, height ) - this.padding.top - this.padding.bottom;
 			return toPixel( Splide.root, height ) - this.padding.top - this.padding.bottom;
 		},
 		},
 
 

+ 33 - 14
src/js/transitions/slide/index.js

@@ -17,28 +17,47 @@ import { subscribe, applyStyle } from '../../utils/dom';
  * @return {Object} - The component object.
  * @return {Object} - The component object.
  */
  */
 export default ( Splide, Components ) => {
 export default ( Splide, Components ) => {
+	/**
+	 * Hold the list element.
+	 *
+	 * @type {Element}
+	 */
+	let list;
+
+	/**
+	 * Hold the onEnd callback function.
+	 *
+	 * @type {function}
+	 */
+	let endCallback;
+
 	return {
 	return {
 		/**
 		/**
-		 * Start transition.
-		 *
-		 * @param {number}    destIndex - Destination slide index that might be clone's.
-		 * @param {number}    newIndex  - New index.
-		 * @param {Object}    coord     - Destination coordinates.
-		 * @param {function}  onEnd     - Callback function must be invoked when transition is completed.
+		 * Called when the component is mounted.
 		 */
 		 */
-		start( destIndex, newIndex, coord, onEnd ) {
-			const list    = Components.Elements.list;
-			const options = Splide.options;
+		mount() {
+			list = Components.Elements.list;
 
 
-			const removers = subscribe( list, 'transitionend', e => {
-				if ( e.target === list ) {
-					onEnd();
-					removers[0]();
+			subscribe( list, 'transitionend', e => {
+				if ( e.target === list && endCallback ) {
+					endCallback();
 				}
 				}
 			} );
 			} );
+		},
+
+		/**
+		 * Start transition.
+		 *
+		 * @param {number}   destIndex - Destination slide index that might be clone's.
+		 * @param {number}   newIndex  - New index.
+		 * @param {Object}   coord     - Destination coordinates.
+		 * @param {function} onEnd     - Callback function must be invoked when transition is completed.
+		 */
+		start( destIndex, newIndex, coord, onEnd ) {
+			endCallback = onEnd;
 
 
 			applyStyle( list, {
 			applyStyle( list, {
-				transition: `transform ${ options.speed }ms ${ options.easing }`,
+				transition: `transform ${ Splide.options.speed }ms ${ Splide.options.easing }`,
 				transform : `translate(${ coord.x }px,${ coord.y }px)`,
 				transform : `translate(${ coord.x }px,${ coord.y }px)`,
 			} );
 			} );
 		},
 		},

+ 6 - 5
tests/core/splide.test.js

@@ -1,6 +1,7 @@
 import { minimum } from '../data/html';
 import { minimum } from '../data/html';
 import Splide from '../../src/js/splide';
 import Splide from '../../src/js/splide';
 import { DEFAULTS } from '../../src/js/constants/defaults';
 import { DEFAULTS } from '../../src/js/constants/defaults';
+import { COMPLETE } from '../../src/js/components';
 
 
 
 
 describe( 'Splide ', () => {
 describe( 'Splide ', () => {
@@ -9,23 +10,23 @@ describe( 'Splide ', () => {
 	} );
 	} );
 
 
 	test( 'should find an element with the given selector.', () => {
 	test( 'should find an element with the given selector.', () => {
-		const splide = new Splide( '#splide' );
+		const splide = new Splide( '#splide', {}, COMPLETE );
 		expect( splide.root.id ).toBe( 'splide' );
 		expect( splide.root.id ).toBe( 'splide' );
 	} );
 	} );
 
 
 	test( 'should accept an element as a root on construction.', () => {
 	test( 'should accept an element as a root on construction.', () => {
 		const root   = document.getElementById( 'splide' );
 		const root   = document.getElementById( 'splide' );
-		const splide = new Splide( root );
+		const splide = new Splide( root, {}, COMPLETE );
 		expect( splide.root.id ).toBe( 'splide' );
 		expect( splide.root.id ).toBe( 'splide' );
 	} );
 	} );
 
 
 	test( 'should overwrite default options with a given ones on construction.', () => {
 	test( 'should overwrite default options with a given ones on construction.', () => {
-		const splide = new Splide( '#splide', { perPage: 3 } );
+		const splide = new Splide( '#splide', { perPage: 3 }, COMPLETE );
 		expect( splide.options ).toEqual( { ...DEFAULTS, perPage: 3 } );
 		expect( splide.options ).toEqual( { ...DEFAULTS, perPage: 3 } );
 	} );
 	} );
 
 
 	test( '"is" should verify if a given type is a current one.', () => {
 	test( '"is" should verify if a given type is a current one.', () => {
-		const splide = new Splide( '#splide', { type: 'loop' } ).mount();
+		const splide = new Splide( '#splide', { type: 'loop' }, COMPLETE ).mount();
 		expect( splide.is( 'slide' ) ).toBe( false );
 		expect( splide.is( 'slide' ) ).toBe( false );
 		expect( splide.is( 'loop' ) ).toBe( true );
 		expect( splide.is( 'loop' ) ).toBe( true );
 	} );
 	} );
@@ -34,7 +35,7 @@ describe( 'Splide ', () => {
 		const root = document.getElementById( 'splide' );
 		const root = document.getElementById( 'splide' );
 		root.style.visibility = 'hidden';
 		root.style.visibility = 'hidden';
 
 
-		const splide = new Splide( root );
+		const splide = new Splide( root, {}, COMPLETE );
 		expect( splide.root.style.visibility ).toBe( 'hidden' );
 		expect( splide.root.style.visibility ).toBe( 'hidden' );
 
 
 		splide.mount();
 		splide.mount();

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است