Browse Source

Bug Fix: "focus" should've accept 0. trim() of vertical resolver didn't work correctly.

NaotoshiFujita 6 years ago
parent
commit
1e5c569685

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


+ 1 - 1
src/js/components/a11y/index.js

@@ -132,7 +132,7 @@ export default ( Splide, Components ) => {
 
 		data.items.forEach( item => {
 			const options  = Splide.options;
-			const text     = ! options.focus && options.perPage > 1 ? i18n.pageX : i18n.slideX;
+			const text     = options.focus === false && options.perPage > 1 ? i18n.pageX : i18n.slideX;
 			const label    = sprintf( text, item.page + 1 );
 			const srt      = createSrt( label );
 			const button   = item.button;

+ 4 - 4
src/js/components/controller/index.js

@@ -105,7 +105,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - A computed page number.
 		 */
 		pageToIndex( page ) {
-			if ( options.focus ) {
+			if ( options.focus !== false ) {
 				return page;
 			}
 
@@ -131,7 +131,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - A computed page number.
 		 */
 		indexToPage( index ) {
-			if ( options.focus ) {
+			if ( options.focus !== false ) {
 				return index;
 			}
 
@@ -207,7 +207,7 @@ export default ( Splide, Components ) => {
 		 */
 		get pageLength() {
 			const length = Splide.length;
-			return options.focus ? length : Math.ceil( length / options.perPage );
+			return options.focus !== false ? length : Math.ceil( length / options.perPage );
 		},
 
 		/**
@@ -218,7 +218,7 @@ export default ( Splide, Components ) => {
 		get edgeIndex() {
 			const length = Splide.length;
 
-			if ( options.focus || options.isNavigation || Splide.is( LOOP ) ) {
+			if ( options.focus !== false || options.isNavigation || Splide.is( LOOP ) ) {
 				return length - 1;
 			}
 

+ 1 - 1
src/js/components/pagination/index.js

@@ -166,7 +166,7 @@ export default ( Splide, Components, name ) => {
 		const Slides  = Components.Slides;
 
 		const items = Slides.getSlides( false, true )
-			.filter( Slide => options.focus || Slide.index % options.perPage === 0 )
+			.filter( Slide => options.focus !== false || Slide.index % options.perPage === 0 )
 			.map( ( Slide, page ) => {
 				const li      = create( 'li', {} );
 				const button  = create( 'button', { class: classes.page } );

+ 1 - 1
src/js/components/slides/index.js

@@ -91,7 +91,7 @@ export default ( Splide, Components ) => {
 		getSlidesByPage( page ) {
 			const idx     = Components.Controller.pageToIndex( page );
 			const options = Splide.options;
-			const max     = options.focus ? 1 : options.perPage;
+			const max     = options.focus !== false ? 1 : options.perPage;
 
 			return Slides.filter( ( { index } ) => idx <= index && index < idx + max );
 		},

+ 1 - 1
src/js/components/track/resolvers/horizontal.js

@@ -91,7 +91,7 @@ export default ( Splide, Components ) => {
 			if ( focus === 'center' ) {
 				focusOffset = ( width - slideWidth + gap ) / 2;
 			} else {
-				focusOffset = parseInt( focus || 0 ) * slideWidth;
+				focusOffset = ( parseInt( focus ) || 0 ) * slideWidth;
 			}
 
 			return slideWidth * Components.Clones.length / 2 - focusOffset;

+ 2 - 2
src/js/components/track/resolvers/vertical.js

@@ -64,7 +64,7 @@ export default ( Splide, Components ) => {
 		 * @return {number} - Trimmed position.
 		 */
 		trim( position ) {
-			const edge = -( Layout.listHeight - Splide.options.perPage * Layout.slideHeight );
+			const edge = -( Layout.slideHeight * ( Splide.length - Splide.options.perPage ) );
 			return between( position, edge, 0 );
 		},
 
@@ -82,7 +82,7 @@ export default ( Splide, Components ) => {
 			if ( focus === 'center' ) {
 				focusOffset = ( listHeight - slideHeight + gap ) / 2;
 			} else {
-				focusOffset = parseInt( focus || 0 ) * slideHeight;
+				focusOffset = ( parseInt( focus ) || 0 ) * slideHeight;
 			}
 
 			return slideHeight * Components.Clones.length / 2 - focusOffset;

+ 2 - 2
src/js/constants/defaults.js

@@ -98,9 +98,9 @@ export const DEFAULTS = {
 	 * Determine which slide should be focused if there are multiple slides in a page.
 	 * A string "center" is acceptable for centering slides.
 	 *
-	 * @type {number|string}
+	 * @type {boolean|number|string}
 	 */
-	focus: 0,
+	focus: false,
 
 	/**
 	 * Gap between slides. CSS format is allowed such as 1em.

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