@@ -1123,7 +1123,7 @@ Code related to measuring the size of the carousel after mounting
11231123 this . capturePeekingMeasurements ( ) ;
11241124
11251125 if ( this . isVariableWidth ) {
1126- return this . captureTrackWidth ( ) ;
1126+ return this . captureCarouselDims ( ) ;
11271127 }
11281128 } ,
11291129 // Make the width style that gives a slide it's width given
@@ -1159,6 +1159,14 @@ Code related to measuring the size of the carousel after mounting
11591159
11601160
11611161 return `calc( ${ 100 / slidesPerPage } % - (${ this . autoUnit ( peekLeft ) } + ${ this . autoUnit ( peekRight ) } ) / ${ slidesPerPage } - (${ this . autoUnit ( gutter ) } * ${ slidesPerPage - 1 } ) / ${ slidesPerPage } )` ;
1162+ } ,
1163+ // Get the target X scroll position of a given slide
1164+ targetXOfIdx : function ( idx ) {
1165+ if ( this . isVariableWidth ) {
1166+ return this . measuredSlidesWidths [ idx ] . targetXScroll ;
1167+ } else {
1168+ return this . pageWidth / this . currentSlidesPerPage ;
1169+ }
11621170 }
11631171 }
11641172} ) ;
@@ -1255,6 +1263,10 @@ notPassive = {
12551263
12561264 if ( ! this . trackWidth ) {
12571265 return 0 ;
1266+ }
1267+
1268+ if ( this . isVariableWidth ) {
1269+ return this . fractionalIndexFromMeasurements ;
12581270 } // Work in positive numbers
12591271
12601272
@@ -1290,6 +1302,16 @@ notPassive = {
12901302
12911303 return pageProgressPercent + setIndex * this . pages + pageIndex ;
12921304 } ,
1305+ fractionalIndexFromMeasurements : function ( ) {
1306+ var percentage , slideIdx , x ; // Work in positive numbers
1307+
1308+ x = this . currentX * - 1 ;
1309+ slideIdx = this . measuredSlidesWidths . findIndex ( measuredSlide => {
1310+ return measuredSlide . targetXScroll > x ;
1311+ } ) - 1 ;
1312+ percentage = ( x - this . measuredSlidesWidths [ slideIdx ] . targetXScroll ) / this . measuredSlidesWidths [ slideIdx ] . width ;
1313+ return slideIdx + percentage ;
1314+ } ,
12931315 // Determine if the user is dragging vertically
12941316 isVerticalDrag : function ( ) {
12951317 if ( ! this . dragDirectionRatio ) {
@@ -1329,7 +1351,7 @@ notPassive = {
13291351 } // If rendering variable width slides, don't come to a rest at an index
13301352
13311353 } else if ( this . isVariableWidth ) {
1332- this . tweenToStop ( ) ; // If user was vertically dragging, reset the index
1354+ this . goto ( this . dragIndex ) ; // If user was vertically dragging, reset the index
13331355 } else if ( this . isVerticalDrag ) {
13341356 this . goto ( this . index ) ;
13351357 } else {
@@ -1740,7 +1762,11 @@ Code related to dealing with advancing between pages
17401762 // The current number of pages
17411763 pages : function ( ) {
17421764 switch ( false ) {
1765+ // When variable width, pages is slide count
1766+ case ! this . isVariableWidth :
1767+ return this . slidesCount ;
17431768 // When looping and paginating per slide, make a dot per slide
1769+
17441770 case ! ( this . paginateBySlide && this . shouldLoop ) :
17451771 return this . slidesCount ;
17461772 // Else, restrict pages so you the last slide is flush with right edge
@@ -1902,7 +1928,19 @@ Code related to dealing with advancing between pages
19021928 getXForIndex : function ( index ) {
19031929 var x ; // Figure out the new x position
19041930
1905- x = this . paginateBySlide ? index * this . slideWidth * - 1 : index * this . pageWidth * - 1 ; // Apply adjustments to x value and persist
1931+ x = function ( ) {
1932+ switch ( false ) {
1933+ case ! this . isVariableWidth :
1934+ return this . targetXOfIdx ( this . applyIndexBoundaries ( index ) ) * - 1 ;
1935+
1936+ case ! this . paginateBySlide :
1937+ return index * this . slideWidth * - 1 ;
1938+
1939+ default :
1940+ return index * this . pageWidth * - 1 ;
1941+ }
1942+ } . call ( this ) ; // Apply adjustments to x value and persist
1943+
19061944
19071945 x += this . makeIncompletePageOffset ( index ) ;
19081946 return Math . round ( this . applyXBoundaries ( x ) ) ;
@@ -2446,7 +2484,8 @@ Functionality related to supporting variable width slides
24462484/* harmony default export */ var variable_width_coffee = ( {
24472485 data : function ( ) {
24482486 return {
2449- measuredTrackWidth : 0
2487+ measuredTrackWidth : 0 ,
2488+ measuredSlidesWidths : [ ]
24502489 } ;
24512490 } ,
24522491 computed : {
@@ -2456,13 +2495,34 @@ Functionality related to supporting variable width slides
24562495 }
24572496 } ,
24582497 methods : {
2498+ // Capture all dimensions of carousel
2499+ captureCarouselDims : function ( ) {
2500+ this . captureTrackWidth ( ) ;
2501+ return this . captureSlideWidths ( ) ;
2502+ } ,
24592503 // Measure the width of the track
24602504 captureTrackWidth : function ( ) {
24612505 if ( ! this . $refs . track ) {
24622506 return ;
24632507 }
24642508
24652509 return this . measuredTrackWidth = this . $refs . track . $el . scrollWidth ;
2510+ } ,
2511+ // Capture slide dims and place them into an array of data
2512+ captureSlideWidths : function ( ) {
2513+ var ref , ref1 ;
2514+
2515+ if ( ! this . $refs . track ) {
2516+ return ;
2517+ }
2518+
2519+ return this . measuredSlidesWidths = ( ref = this . $refs ) != null ? ( ref1 = ref . track ) != null ? ref1 . $children . reduce ( ( acc , child , idx , arr ) => {
2520+ var ref2 , ref3 ;
2521+ return [ ...acc , {
2522+ width : child . $el . clientWidth ,
2523+ targetXScroll : ( ( ( ref2 = acc [ idx - 1 ] ) != null ? ref2 . targetXScroll : void 0 ) || 0 ) + ( ( ( ref3 = acc [ idx - 1 ] ) != null ? ref3 . width : void 0 ) || 0 ) + this . gutter * ( idx > 0 )
2524+ } ] ;
2525+ } , [ ] ) : void 0 : void 0 ;
24662526 }
24672527 }
24682528} ) ;
0 commit comments