@@ -55,7 +55,7 @@ export class AbstractSlickCarousel extends WebPluginInterface {
5555 */
5656 get defaultProps ( ) {
5757 return {
58- pauseAutoPlayInOutOfView : true ,
58+ pauseAutoplayInOutOfView : false ,
5959 cssReadyClass : 'is-ready' ,
6060 cssInitializedClass : 'is-initialized' ,
6161 $listSelector : '[data-slick-carousel-list]' ,
@@ -126,18 +126,8 @@ export class AbstractSlickCarousel extends WebPluginInterface {
126126 * @protected
127127 */
128128 _afterInitialize ( ) {
129- if ( this . props . pauseAutoPlayInOutOfView && this . settings . autoplay ) {
130- this . $list . on ( 'inview' , ( event , isInView ) => {
131- if ( this . isInitialized ) {
132- if ( isInView ) {
133- this . update ( ) ;
134- this . $list . slick ( 'slickPlay' ) ;
135- } else {
136- this . $list . slick ( 'slickPause' ) ;
137- }
138- }
139- } ) ;
140- this . $list . trigger ( 'inview' ) ;
129+ if ( this . props . pauseAutoplayInOutOfView && this . settings . autoplay ) {
130+ this . _autoplayInViewObserver ( ) ;
141131 }
142132 this . $container . addClass ( this . props . cssInitializedClass ) ;
143133 }
@@ -149,22 +139,43 @@ export class AbstractSlickCarousel extends WebPluginInterface {
149139 if ( this . firstInitialize ) {
150140 this . _setup ( ) ;
151141 this . firstInitialize = false ;
142+ this . _beforeInitialize ( ) ;
152143 }
153- this . _beforeInitialize ( ) ;
144+
154145 this . $list . slick ( this . settings ) ;
155146 this . isInitialized = true ;
156- this . _afterInitialize ( ) ;
147+
148+ if ( this . firstInitialize ) {
149+ this . _afterInitialize ( ) ;
150+ }
157151 }
158152 }
159153
160154 // ------------------------------
161155 // extend interface
162156 // ------------------------------
163157
158+ /**
159+ * @protected
160+ */
161+ _autoplayInViewObserver ( ) {
162+ this . $list . on ( 'inview' , ( event , isInView ) => {
163+ if ( this . isInitialized ) {
164+ if ( isInView ) {
165+ this . update ( ) ;
166+ this . $list . slick ( 'slickPlay' ) ;
167+ } else {
168+ this . $list . slick ( 'slickPause' ) ;
169+ }
170+ }
171+ } ) ;
172+ this . $list . trigger ( 'inview' ) ;
173+ }
174+
164175 destroy ( ) {
165176 if ( this . isInitialized ) {
166177 this . $list . unslick ( ) ;
167- this . $list . removeClass ( this . props . cssReadyClass ) ;
178+ this . isInitialized = false ;
168179 }
169180 }
170181
@@ -181,7 +192,7 @@ export class AbstractSlickCarousel extends WebPluginInterface {
181192
182193/**
183194 * @typedef {Object } SlickCarouselProps
184- * @property {boolean } [pauseAutoPlayInOutOfView ] - true,
195+ * @property {boolean } [pauseAutoplayInOutOfView ] - true,
185196 * @property {string } [cssReadyClass] - 'is-ready',
186197 * @property {string } [cssInitializedClass] - 'is-initialized',
187198 * @property {string } [$listSelector] - '[data-slick-carousel-list]',
0 commit comments