33/**
44 * @module AbstractSlickCarousel
55 * @author OlegDutchenko <[email protected] > 6+ * @version 3.0.0
67 */
78
89// ----------------------------------------
@@ -25,33 +26,68 @@ export class AbstractSlickCarousel extends WebPluginInterface {
2526 /**
2627 * @param {jQuery } $container
2728 * @param {SlickCarouselSettings } clientSettings
29+ * @param {SlickCarouselSettings } clientProps
2830 */
29- constructor ( $container , clientSettings = { } ) {
31+ constructor ( $container , clientSettings = { } , clientProps ) {
3032 super ( ) ;
3133
3234 this . $container = $container ;
33- this . clientSettings = clientSettings ;
35+ this . $list = $ ( null ) ;
36+ this . $dots = $ ( null ) ;
37+ this . $prevArrow = $ ( null ) ;
38+ this . $nextArrow = $ ( null ) ;
39+ this . $arrows = $ ( null ) ;
40+
3441 this . isInitialized = false ;
3542 this . firstInitialize = true ;
36- this . cssReadyClass = 'is-ready' ;
37- this . pauseAutoPlayInOutOfView = false ;
43+
44+ /** @type {SlickCarouselProps } */
45+ this . props = { } ;
46+ this . clientProps = clientProps ;
3847
3948 /** @type {SlickCarouselSettings } */
4049 this . settings = { } ;
50+ this . clientSettings = clientSettings ;
51+ }
4152
42- this . $list = this . $container . find ( '[data-slick-carousel-list]' ) ;
43- this . $dots = this . $container . find ( '[data-slick-carousel-dots]' ) ;
44- this . $prevArrow = this . $container . find ( '[data-slick-carousel-prev-arrow]' ) ;
45- this . $nextArrow = this . $container . find ( '[data-slick-carousel-next-arrow]' ) ;
46- this . $arrows = this . $prevArrow . add ( this . $nextArrow ) ;
53+ /**
54+ * @type {SlickCarouselProps }
55+ */
56+ get defaultProps ( ) {
57+ return {
58+ pauseAutoPlayInOutOfView : true ,
59+ cssReadyClass : 'is-ready' ,
60+ cssInitializedClass : 'is-initialized' ,
61+ $listSelector : '[data-slick-carousel-list]' ,
62+ $dotsSelector : '[data-slick-carousel-dots]' ,
63+ $prevArrowSelector : '[data-slick-carousel-prev-arrow]' ,
64+ $nextArrowSelector : '[data-slick-carousel-next-arrow]'
65+ } ;
66+ }
67+
68+ /**
69+ * @type {SlickCarouselSettings }
70+ */
71+ get defaultSettings ( ) {
72+ return super . defaultSettings ;
4773 }
4874
4975 /**
5076 * @protected
5177 */
5278 _setup ( ) {
79+ // merge props
80+ this . props = $ . extend ( { } , this . defaultProps , this . clientProps ) ;
81+
82+ // get elements
83+ this . $list = this . $container . find ( this . props . $listSelector ) ;
84+ this . $dots = this . $container . find ( this . props . $dotsSelector ) ;
85+ this . $prevArrow = this . $container . find ( this . props . $prevArrowSelector ) ;
86+ this . $nextArrow = this . $container . find ( this . props . $nextArrowSelector ) ;
87+ this . $arrows = this . $prevArrow . add ( this . $nextArrow ) ;
88+
5389 // merge settings
54- let responsive = $ . extend ( [ ] , this . defaults ) ;
90+ let responsive = $ . extend ( [ ] , this . defaultSettings ) ;
5591 let clientResponsive = $ . extend ( [ ] , this . clientSettings . responsive ) ;
5692 if ( responsive . length && clientResponsive . length ) {
5793 clientResponsive . forEach ( ( { breakpoint, settings } ) => {
@@ -67,29 +103,30 @@ export class AbstractSlickCarousel extends WebPluginInterface {
67103 } ) ;
68104 }
69105
70- this . settings = $ . extend ( true , { } , this . defaults , this . clientSettings , {
106+ this . settings = $ . extend ( true , { } , this . defaultSettings , this . clientSettings , {
71107 responsive,
72108 appendDots : this . $dots ,
73109 prevArrow : this . $prevArrow ,
74110 nextArrow : this . $nextArrow
75111 } ) ;
76112
77- // out of view for autoplay
78- this . pauseAutoPlayInOutOfView = this . settings . autoplay ;
113+ // sanitize
114+ delete this . clientProps ;
115+ delete this . clientSettings ;
79116 }
80117
81118 /**
82119 * @protected
83120 */
84121 _beforeInitialize ( ) {
85- this . $list . addClass ( this . cssReadyClass ) ;
122+ this . $container . addClass ( this . props . cssReadyClass ) ;
86123 }
87124
88125 /**
89126 * @protected
90127 */
91128 _afterInitialize ( ) {
92- if ( this . pauseAutoPlayInOutOfView && this . settings . autoplay ) {
129+ if ( this . props . pauseAutoPlayInOutOfView && this . settings . autoplay ) {
93130 this . $list . on ( 'inview' , ( event , isInView ) => {
94131 if ( this . isInitialized ) {
95132 if ( isInView ) {
@@ -102,6 +139,7 @@ export class AbstractSlickCarousel extends WebPluginInterface {
102139 } ) ;
103140 this . $list . trigger ( 'inview' ) ;
104141 }
142+ this . $container . addClass ( this . props . cssInitializedClass ) ;
105143 }
106144
107145 initialize ( ) {
@@ -119,21 +157,14 @@ export class AbstractSlickCarousel extends WebPluginInterface {
119157 }
120158 }
121159
122- /**
123- * @type {SlickCarouselSettings }
124- */
125- get defaults ( ) {
126- return super . defaults ;
127- }
128-
129160 // ------------------------------
130161 // extend interface
131162 // ------------------------------
132163
133164 destroy ( ) {
134165 if ( this . isInitialized ) {
135166 this . $list . unslick ( ) ;
136- this . $list . removeClass ( this . cssReadyClass ) ;
167+ this . $list . removeClass ( this . props . cssReadyClass ) ;
137168 }
138169 }
139170
@@ -148,6 +179,17 @@ export class AbstractSlickCarousel extends WebPluginInterface {
148179// Definitions
149180// ----------------------------------------
150181
182+ /**
183+ * @typedef {Object } SlickCarouselProps
184+ * @property {boolean } [pauseAutoPlayInOutOfView] - true,
185+ * @property {string } [cssReadyClass] - 'is-ready',
186+ * @property {string } [cssInitializedClass] - 'is-initialized',
187+ * @property {string } [$listSelector] - '[data-slick-carousel-list]',
188+ * @property {string } [$dotsSelector] - '[data-slick-carousel-dots]',
189+ * @property {string } [$prevArrowSelector] - '[data-slick-carousel-prev-arrow]',
190+ * @property {string } [$nextArrowSelector] - '[data-slick-carousel-next-arrow]'
191+ */
192+
151193/**
152194 * @typedef {Object } SlickCarouselSettings
153195 * @property {boolean } [accessibility=true]
0 commit comments