Skip to content

Commit b5d604b

Browse files
Merge pull request #4 from dutchenkoOleg/master
3.0.0
2 parents f48b78c + 26cbc1b commit b5d604b

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

index.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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]',

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,22 @@
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/dutchenkoOleg/web-plugin-abstract-slick-carousel.git"
11+
"url": "git+https://github.com/WezomAgency/web-plugin-abstract-slick-carousel.git"
1212
},
1313
"keywords": [],
1414
"author": "Oleg Dutchenko <[email protected]>",
1515
"license": "MIT",
1616
"bugs": {
17-
"url": "https://github.com/dutchenkoOleg/web-plugin-abstract-slick-carousel/issues"
17+
"url": "https://github.com/WezomAgency/web-plugin-abstract-slick-carousel/issues"
1818
},
19-
"homepage": "https://github.com/dutchenkoOleg/web-plugin-abstract-slick-carousel#readme",
19+
"homepage": "https://github.com/WezomAgency/web-plugin-abstract-slick-carousel#readme",
2020
"devDependencies": {
2121
"eslint-config-wezom-relax": "^1.1.0"
2222
},
2323
"dependencies": {
2424
"jquery": "^3.3.1",
2525
"jquery-inview": "^1.1.2",
2626
"slick-carousel": "^1.8.1",
27-
"web-plugin-interface": "^3.0.0"
27+
"web-plugin-interface": "^3.0.1"
2828
}
2929
}

0 commit comments

Comments
 (0)