@@ -25,19 +25,26 @@ import 'glider-js/glider.css';
25
25
*
26
26
* Glider-JS doesn't support RTL at the moment, this is to add basic
27
27
* functioning support for the nav arrows as otherwise the nav arrows
28
- * becomes useless on RTL sites.
28
+ * become useless on RTL sites.
29
29
*
30
30
* @todo Maybe replace glider-js with other lightweight lib which has RTL support. or Replace it with 'amp-carousel' once we have the support.
31
- * @param { Object|string } slide Slide arrow string based on action.
32
- * @param { boolean } dot Is dot navigation action.
33
- * @param { Object } e Event object.
34
- * @return { boolean } Navigation done.
31
+ * @param slideIndex Slide arrow string based on action.
32
+ * @param isActuallyDotIndex Is dot navigation action.
33
+ * @param e Event object.
34
+ * @return Navigation done.
35
35
*/
36
- Glider . prototype . scrollItem = function ( slide , dot , e ) {
37
- // glider-js doesn't seem to pass right amount of arguments.
38
- if ( e === undefined && dot ?. target ) {
39
- e = dot ;
40
- dot = false ;
36
+ Glider . prototype . scrollItem = function (
37
+ slideIndex : number ,
38
+ isActuallyDotIndex : boolean ,
39
+ e : Event
40
+ ) {
41
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Workaround
42
+ // @ts -ignore
43
+ if ( e === undefined && isActuallyDotIndex ?. target ) {
44
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -- Workaround
45
+ // @ts -ignore
46
+ e = isActuallyDotIndex ;
47
+ isActuallyDotIndex = false ;
41
48
}
42
49
43
50
if ( e === undefined ) {
@@ -50,17 +57,21 @@ Glider.prototype.scrollItem = function (slide, dot, e) {
50
57
}
51
58
52
59
// Somehow slidesToScroll and slidesToShow can end up being 0.
53
- this . opt . slidesToScroll = Math . max ( 1 , this . opt . slidesToScroll ) ;
54
- this . opt . slidesToShow = Math . max ( 1 , this . opt . slidesToShow ) ;
60
+ this . opt . slidesToScroll = Math . max ( 1 , this . opt . slidesToScroll as number ) ;
61
+ this . opt . slidesToShow = Math . max ( 1 , this . opt . slidesToShow as number ) ;
55
62
// This will also cause this.itemWidth to be Infinity because division by zero returns Infinity in JS.
56
63
// Update this.itemWidth with actual value in this case.
57
64
if ( this . itemWidth === Number . POSITIVE_INFINITY ) {
58
65
// It's a sibling.
59
- const carouselWrapper = e . target . parentElement . querySelector (
66
+ const carouselWrapper = (
67
+ e . target as HTMLElement
68
+ ) . parentElement ?. querySelector (
60
69
'.web-stories-list__carousel'
61
- ) ;
70
+ ) as HTMLElement ;
62
71
const itemStyle = window . getComputedStyle (
63
- carouselWrapper . querySelector ( '.web-stories-list__story' )
72
+ carouselWrapper . querySelector (
73
+ '.web-stories-list__story'
74
+ ) as unknown as HTMLElement
64
75
) ;
65
76
66
77
this . itemWidth =
@@ -69,56 +80,62 @@ Glider.prototype.scrollItem = function (slide, dot, e) {
69
80
Number . parseFloat ( itemStyle . marginRight ) ) ;
70
81
}
71
82
72
- const originalSlide = slide ;
83
+ const originalSlide = slideIndex ;
73
84
++ this . animate_id ;
74
85
75
- if ( dot === true ) {
76
- slide = slide * this . containerWidth ;
77
- slide = Math . round ( slide / this . itemWidth ) * this . itemWidth ;
86
+ if ( isActuallyDotIndex === true ) {
87
+ slideIndex = slideIndex * this . containerWidth ;
88
+ slideIndex = Math . round ( slideIndex / this . itemWidth ) * this . itemWidth ;
78
89
} else {
79
- if ( typeof slide === 'string' ) {
80
- const backwards = slide === 'prev' ;
90
+ if ( typeof slideIndex === 'string' ) {
91
+ const backwards = slideIndex === 'prev' ;
81
92
82
93
// use precise location if fractional slides are on
83
94
if ( this . opt . slidesToScroll % 1 || this . opt . slidesToShow % 1 ) {
84
- slide = this . getCurrentSlide ( ) ;
95
+ slideIndex = this . getCurrentSlide ( ) ;
85
96
} else {
86
- slide = ! isNaN ( this . slide ) ? this . slide : 0 ;
97
+ slideIndex = ! isNaN ( this . slide ) ? this . slide : 0 ;
87
98
}
88
99
89
100
if ( backwards ) {
90
- slide -= this . opt . slidesToScroll ;
101
+ slideIndex -= this . opt . slidesToScroll ;
91
102
} else {
92
- slide += this . opt . slidesToScroll ;
103
+ slideIndex += this . opt . slidesToScroll ;
93
104
}
94
105
95
106
if ( this . opt . rewind ) {
96
- const scrollLeft = this . ele . scrollLeft ;
97
- slide =
107
+ const scrollLeft = ( this . ele as HTMLElement )
108
+ . scrollLeft as unknown as number ;
109
+ slideIndex =
98
110
backwards && ! scrollLeft
99
111
? this . slides . length
100
112
: ! backwards &&
101
113
scrollLeft + this . containerWidth >= Math . floor ( this . trackWidth )
102
114
? 0
103
- : slide ;
115
+ : slideIndex ;
104
116
}
105
117
}
106
118
107
- slide = Math . min ( slide , this . slides . length ) ;
119
+ slideIndex = Math . min ( slideIndex , this . slides . length ) ;
108
120
109
- this . slide = slide ;
110
- slide = this . itemWidth * slide ;
121
+ this . slide = slideIndex ;
122
+ slideIndex = this . itemWidth * slideIndex ;
111
123
}
112
124
113
125
this . scrollTo (
114
- slide ,
115
- this . opt . duration * Math . abs ( this . ele . scrollLeft - slide ) ,
116
- function ( ) {
126
+ slideIndex ,
127
+ this . opt . duration *
128
+ Math . abs ( ( this . ele as HTMLElement ) . scrollLeft - slideIndex ) ,
129
+ function ( this : Glider < HTMLElement > ) {
117
130
this . updateControls ( ) ;
118
131
this . emit ( 'animated' , {
119
132
value : originalSlide ,
120
133
type :
121
- typeof originalSlide === 'string' ? 'arrow' : dot ? 'dot' : 'slide' ,
134
+ typeof originalSlide === 'string'
135
+ ? 'arrow'
136
+ : isActuallyDotIndex
137
+ ? 'dot'
138
+ : 'slide' ,
122
139
} ) ;
123
140
}
124
141
) ;
0 commit comments