@@ -1123,7 +1123,7 @@ Code related to measuring the size of the carousel after mounting
1123
1123
this . capturePeekingMeasurements ( ) ;
1124
1124
1125
1125
if ( this . isVariableWidth ) {
1126
- return this . captureTrackWidth ( ) ;
1126
+ return this . captureCarouselDims ( ) ;
1127
1127
}
1128
1128
} ,
1129
1129
// 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
1159
1159
1160
1160
1161
1161
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
+ }
1162
1170
}
1163
1171
}
1164
1172
} ) ;
@@ -1255,6 +1263,10 @@ notPassive = {
1255
1263
1256
1264
if ( ! this . trackWidth ) {
1257
1265
return 0 ;
1266
+ }
1267
+
1268
+ if ( this . isVariableWidth ) {
1269
+ return this . fractionalIndexFromMeasurements ;
1258
1270
} // Work in positive numbers
1259
1271
1260
1272
@@ -1290,6 +1302,16 @@ notPassive = {
1290
1302
1291
1303
return pageProgressPercent + setIndex * this . pages + pageIndex ;
1292
1304
} ,
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
+ } ,
1293
1315
// Determine if the user is dragging vertically
1294
1316
isVerticalDrag : function ( ) {
1295
1317
if ( ! this . dragDirectionRatio ) {
@@ -1329,7 +1351,7 @@ notPassive = {
1329
1351
} // If rendering variable width slides, don't come to a rest at an index
1330
1352
1331
1353
} 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
1333
1355
} else if ( this . isVerticalDrag ) {
1334
1356
this . goto ( this . index ) ;
1335
1357
} else {
@@ -1740,7 +1762,11 @@ Code related to dealing with advancing between pages
1740
1762
// The current number of pages
1741
1763
pages : function ( ) {
1742
1764
switch ( false ) {
1765
+ // When variable width, pages is slide count
1766
+ case ! this . isVariableWidth :
1767
+ return this . slidesCount ;
1743
1768
// When looping and paginating per slide, make a dot per slide
1769
+
1744
1770
case ! ( this . paginateBySlide && this . shouldLoop ) :
1745
1771
return this . slidesCount ;
1746
1772
// 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
1902
1928
getXForIndex : function ( index ) {
1903
1929
var x ; // Figure out the new x position
1904
1930
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
+
1906
1944
1907
1945
x += this . makeIncompletePageOffset ( index ) ;
1908
1946
return Math . round ( this . applyXBoundaries ( x ) ) ;
@@ -2446,7 +2484,8 @@ Functionality related to supporting variable width slides
2446
2484
/* harmony default export */ var variable_width_coffee = ( {
2447
2485
data : function ( ) {
2448
2486
return {
2449
- measuredTrackWidth : 0
2487
+ measuredTrackWidth : 0 ,
2488
+ measuredSlidesWidths : [ ]
2450
2489
} ;
2451
2490
} ,
2452
2491
computed : {
@@ -2456,13 +2495,34 @@ Functionality related to supporting variable width slides
2456
2495
}
2457
2496
} ,
2458
2497
methods : {
2498
+ // Capture all dimensions of carousel
2499
+ captureCarouselDims : function ( ) {
2500
+ this . captureTrackWidth ( ) ;
2501
+ return this . captureSlideWidths ( ) ;
2502
+ } ,
2459
2503
// Measure the width of the track
2460
2504
captureTrackWidth : function ( ) {
2461
2505
if ( ! this . $refs . track ) {
2462
2506
return ;
2463
2507
}
2464
2508
2465
2509
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 ;
2466
2526
}
2467
2527
}
2468
2528
} ) ;
0 commit comments