@egjs/flicking-plugins 4.7.2-beta.1 → 4.7.2-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -51
- package/css/all.css +2 -0
- package/css/arrow.css +2 -2
- package/css/pagination.css +5 -3
- package/declaration/Arrow.d.ts +63 -2
- package/declaration/AutoPlay.d.ts +68 -4
- package/declaration/Fade.d.ts +25 -0
- package/declaration/Parallax.d.ts +25 -0
- package/declaration/Perspective.d.ts +45 -2
- package/declaration/Sync.d.ts +57 -2
- package/declaration/index.d.ts +7 -4
- package/declaration/pagination/Pagination.d.ts +81 -1
- package/declaration/pagination/renderer/Renderer.d.ts +1 -1
- package/declaration/tsdoc-metadata.json +11 -0
- package/dist/arrow.css +2 -2
- package/dist/flicking-plugins.css +23 -8
- package/dist/flicking-plugins.min.css +1 -1
- package/dist/pagination.css +21 -6
- package/dist/pagination.min.css +1 -1
- package/dist/plugins.esm.js +1020 -1535
- package/dist/plugins.esm.js.map +1 -1
- package/dist/plugins.js +1044 -1571
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.min.js +1 -9
- package/dist/plugins.min.js.map +1 -1
- package/package.json +49 -105
- package/src/Arrow.ts +124 -49
- package/src/AutoPlay.ts +110 -31
- package/src/Fade.ts +31 -11
- package/src/Parallax.ts +31 -11
- package/src/Perspective.ts +69 -22
- package/src/Sync.ts +61 -19
- package/src/index.ts +9 -22
- package/src/pagination/Pagination.ts +163 -40
- package/src/pagination/index.ts +2 -6
- package/src/pagination/renderer/BulletRenderer.ts +1 -4
- package/src/pagination/renderer/FractionRenderer.ts +1 -3
- package/src/pagination/renderer/Renderer.ts +14 -13
- package/src/pagination/renderer/ScrollBulletRenderer.ts +5 -12
- package/CONTRIBUTING +0 -58
- package/rollup.config.dev.js +0 -17
- package/rollup.config.js +0 -33
- package/tsconfig.declaration.json +0 -10
- package/tsconfig.eslint.json +0 -8
- package/tsconfig.json +0 -17
- package/tsconfig.test.json +0 -21
package/package.json
CHANGED
|
@@ -1,106 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"license": "MIT",
|
|
52
|
-
"bugs": {
|
|
53
|
-
"url": "https://github.com/naver/egjs-flicking-plugins/issues"
|
|
54
|
-
},
|
|
55
|
-
"browserslist": [
|
|
56
|
-
"last 2 version",
|
|
57
|
-
"ie 9-11",
|
|
58
|
-
"not op_mini all"
|
|
59
|
-
],
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"@egjs/flicking": "^4.11.5-beta.0"
|
|
62
|
-
},
|
|
63
|
-
"devDependencies": {
|
|
64
|
-
"@egjs/build-helper": "0.0.5",
|
|
65
|
-
"@egjs/flicking": "^4.11.5-beta.0",
|
|
66
|
-
"@egjs/release-helper": "0.0.3",
|
|
67
|
-
"@types/chai": "^4.0.10",
|
|
68
|
-
"@types/karma-chai": "^0.1.1",
|
|
69
|
-
"@types/mocha": "^5.2.5",
|
|
70
|
-
"@types/node": "^14.0.27",
|
|
71
|
-
"@types/sinon": "^7.0.3",
|
|
72
|
-
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
73
|
-
"@typescript-eslint/eslint-plugin-tslint": "^4.22.0",
|
|
74
|
-
"@typescript-eslint/parser": "^4.22.0",
|
|
75
|
-
"autoprefixer": "^9.8.6",
|
|
76
|
-
"bulma": "^0.9.2",
|
|
77
|
-
"chai": "^4.2.0",
|
|
78
|
-
"concurrently": "^6.2.0",
|
|
79
|
-
"coveralls": "^3.1.0",
|
|
80
|
-
"cpx": "^1.5.0",
|
|
81
|
-
"eslint": "^7.25.0",
|
|
82
|
-
"eslint-plugin-import": "^2.22.1",
|
|
83
|
-
"eslint-plugin-jsdoc": "^33.0.0",
|
|
84
|
-
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
85
|
-
"gh-pages": "^2.0.1",
|
|
86
|
-
"hammer-simulator": "^0.0.1",
|
|
87
|
-
"http-serve": "^1.0.1",
|
|
88
|
-
"karma": "^3.1.4",
|
|
89
|
-
"karma-chai": "^0.1.0",
|
|
90
|
-
"karma-chrome-launcher": "^2.2.0",
|
|
91
|
-
"karma-mocha": "^1.3.0",
|
|
92
|
-
"karma-mocha-reporter": "^2.2.5",
|
|
93
|
-
"karma-sinon": "^1.0.5",
|
|
94
|
-
"karma-typescript-egjs": "^4.0.0",
|
|
95
|
-
"karma-viewport": "^1.0.4",
|
|
96
|
-
"mocha": "^5.2.0",
|
|
97
|
-
"postcss-clean": "^1.2.2",
|
|
98
|
-
"postcss-js": "^3.0.3",
|
|
99
|
-
"print-coveralls": "^1.2.2",
|
|
100
|
-
"print-sizes": "^0.1.0",
|
|
101
|
-
"sinon": "^7.2.3",
|
|
102
|
-
"tslib": "^2.3.0",
|
|
103
|
-
"tslint": "^5.13.1",
|
|
104
|
-
"typescript": "^4.2.3"
|
|
105
|
-
}
|
|
106
|
-
}
|
|
2
|
+
"name": "@egjs/flicking-plugins",
|
|
3
|
+
"version": "4.7.2-beta.10",
|
|
4
|
+
"description": "Ready-to-use plugins for @egjs/flicking",
|
|
5
|
+
"module": "./dist/plugins.esm.js",
|
|
6
|
+
"main": "./dist/plugins.js",
|
|
7
|
+
"types": "./declaration/index.d.ts",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"flicking",
|
|
13
|
+
"plugins",
|
|
14
|
+
"carousel",
|
|
15
|
+
"slide",
|
|
16
|
+
"swipe",
|
|
17
|
+
"parallax",
|
|
18
|
+
"fade",
|
|
19
|
+
"autoplay",
|
|
20
|
+
"egjs"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "NAVER Corp."
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/naver/egjs-flicking",
|
|
28
|
+
"directory": "packages/flicking-plugins"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@egjs/flicking": "^4.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@egjs/flicking": "~4.15.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"dev": "vite --config vite.dev.config.ts",
|
|
39
|
+
"dev:preview": "vite --config vite.dev.config.ts --mode production",
|
|
40
|
+
"start": "vite build --watch",
|
|
41
|
+
"build": "run-s build:bundle build:css build:declaration printsizes",
|
|
42
|
+
"build:bundle": "rm -rf ./dist && concurrently \"vite build\" \"VITE_BUILD_FORMAT=umd vite build\" \"VITE_BUILD_FORMAT=umd-min vite build\"",
|
|
43
|
+
"build:css": "run-s build:css-process build:css-bundle",
|
|
44
|
+
"build:css-process": "node ../../config/build-plugins-css.js",
|
|
45
|
+
"build:css-bundle": "cat dist/arrow.css dist/pagination.css > dist/flicking-plugins.css && postcss dist/flicking-plugins.css --use postcss-clean --no-map --output dist/flicking-plugins.min.css",
|
|
46
|
+
"build:declaration": "tsc -p tsconfig.declaration.json",
|
|
47
|
+
"printsizes": "print-sizes ./dist --exclude=\\.map",
|
|
48
|
+
"lint": "biome check src/"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/Arrow.ts
CHANGED
|
@@ -1,22 +1,47 @@
|
|
|
1
1
|
import Flicking, { EVENTS, FlickingError, Plugin } from "@egjs/flicking";
|
|
2
|
-
|
|
3
|
-
import { BROWSER } from "./event";
|
|
4
2
|
import { ARROW } from "./const";
|
|
3
|
+
import { BROWSER } from "./event";
|
|
5
4
|
import { addClass, getElement, removeClass } from "./utils";
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Options for the {@link Arrow} plugin
|
|
8
|
+
*/
|
|
9
|
+
export interface ArrowOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The parent element to search for arrow elements. If `null`, the Flicking element is used
|
|
12
|
+
* @defaultValue null
|
|
13
|
+
*/
|
|
8
14
|
parentEl: HTMLElement | null;
|
|
15
|
+
/**
|
|
16
|
+
* CSS selector for the "previous" arrow element
|
|
17
|
+
* @defaultValue ".flicking-arrow-prev"
|
|
18
|
+
*/
|
|
9
19
|
prevElSelector: string;
|
|
20
|
+
/**
|
|
21
|
+
* CSS selector for the "next" arrow element
|
|
22
|
+
* @defaultValue ".flicking-arrow-next"
|
|
23
|
+
*/
|
|
10
24
|
nextElSelector: string;
|
|
25
|
+
/**
|
|
26
|
+
* CSS class added to an arrow element when it is disabled (at the start/end of non-circular Flicking)
|
|
27
|
+
* @defaultValue "flicking-arrow-disabled"
|
|
28
|
+
*/
|
|
11
29
|
disabledClass: string;
|
|
30
|
+
/**
|
|
31
|
+
* Number of panels to move when an arrow is clicked
|
|
32
|
+
* @defaultValue 1
|
|
33
|
+
*/
|
|
12
34
|
moveCount: number;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to move by viewport size instead of panel count
|
|
37
|
+
* @defaultValue false
|
|
38
|
+
*/
|
|
13
39
|
moveByViewportSize: boolean;
|
|
14
40
|
}
|
|
15
41
|
|
|
16
42
|
/**
|
|
17
|
-
* A plugin to easily create prev/
|
|
18
|
-
* @
|
|
19
|
-
* @memberof Flicking.Plugins
|
|
43
|
+
* A plugin to easily create prev/next arrow buttons for Flicking
|
|
44
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/arrow | Demo: Arrow}
|
|
20
45
|
*/
|
|
21
46
|
class Arrow implements Plugin {
|
|
22
47
|
/* Internal Values */
|
|
@@ -32,31 +57,86 @@ class Arrow implements Plugin {
|
|
|
32
57
|
private _moveCount: ArrowOptions["moveCount"];
|
|
33
58
|
private _moveByViewportSize: ArrowOptions["moveByViewportSize"];
|
|
34
59
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
public get
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
public
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
+
/** The "previous" arrow HTMLElement
|
|
61
|
+
* @readonly
|
|
62
|
+
*/
|
|
63
|
+
public get prevEl() {
|
|
64
|
+
return this._prevEl;
|
|
65
|
+
}
|
|
66
|
+
/** The "next" arrow HTMLElement
|
|
67
|
+
* @readonly
|
|
68
|
+
*/
|
|
69
|
+
public get nextEl() {
|
|
70
|
+
return this._nextEl;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Current value of the {@link ArrowOptions.parentEl | parentEl} option. */
|
|
74
|
+
public get parentEl() {
|
|
75
|
+
return this._parentEl;
|
|
76
|
+
}
|
|
77
|
+
/** Current value of the {@link ArrowOptions.prevElSelector | prevElSelector} option. */
|
|
78
|
+
public get prevElSelector() {
|
|
79
|
+
return this._prevElSelector;
|
|
80
|
+
}
|
|
81
|
+
/** Current value of the {@link ArrowOptions.nextElSelector | nextElSelector} option. */
|
|
82
|
+
public get nextElSelector() {
|
|
83
|
+
return this._nextElSelector;
|
|
84
|
+
}
|
|
85
|
+
/** Current value of the {@link ArrowOptions.disabledClass | disabledClass} option. */
|
|
86
|
+
public get disabledClass() {
|
|
87
|
+
return this._disabledClass;
|
|
88
|
+
}
|
|
89
|
+
/** Current value of the {@link ArrowOptions.moveCount | moveCount} option. */
|
|
90
|
+
public get moveCount() {
|
|
91
|
+
return this._moveCount;
|
|
92
|
+
}
|
|
93
|
+
/** Current value of the {@link ArrowOptions.moveByViewportSize | moveByViewportSize} option. */
|
|
94
|
+
public get moveByViewportSize() {
|
|
95
|
+
return this._moveByViewportSize;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Sets {@link ArrowOptions.parentEl | parentEl}. */
|
|
99
|
+
public set parentEl(val: ArrowOptions["parentEl"]) {
|
|
100
|
+
this._parentEl = val;
|
|
101
|
+
}
|
|
102
|
+
/** Sets {@link ArrowOptions.prevElSelector | prevElSelector}. */
|
|
103
|
+
public set prevElSelector(val: ArrowOptions["prevElSelector"]) {
|
|
104
|
+
this._prevElSelector = val;
|
|
105
|
+
}
|
|
106
|
+
/** Sets {@link ArrowOptions.nextElSelector | nextElSelector}. */
|
|
107
|
+
public set nextElSelector(val: ArrowOptions["nextElSelector"]) {
|
|
108
|
+
this._nextElSelector = val;
|
|
109
|
+
}
|
|
110
|
+
/** Sets {@link ArrowOptions.disabledClass | disabledClass}. */
|
|
111
|
+
public set disabledClass(val: ArrowOptions["disabledClass"]) {
|
|
112
|
+
this._disabledClass = val;
|
|
113
|
+
}
|
|
114
|
+
/** Sets {@link ArrowOptions.moveCount | moveCount}. */
|
|
115
|
+
public set moveCount(val: ArrowOptions["moveCount"]) {
|
|
116
|
+
this._moveCount = val;
|
|
117
|
+
}
|
|
118
|
+
/** Sets {@link ArrowOptions.moveByViewportSize | moveByViewportSize}. */
|
|
119
|
+
public set moveByViewportSize(val: ArrowOptions["moveByViewportSize"]) {
|
|
120
|
+
this._moveByViewportSize = val;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @param options - Options for the Arrow instance
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* flicking.addPlugins(new Arrow({ parentEl: null, prevElSelector: ".flicking-arrow-prev", nextElSelector: ".flicking-arrow-next" }));
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
public constructor(options: Partial<ArrowOptions> = {}) {
|
|
131
|
+
const {
|
|
132
|
+
parentEl = null,
|
|
133
|
+
prevElSelector = ARROW.PREV_SELECTOR,
|
|
134
|
+
nextElSelector = ARROW.NEXT_SELECTOR,
|
|
135
|
+
disabledClass = ARROW.DISABLED_CLASS,
|
|
136
|
+
moveCount = 1,
|
|
137
|
+
moveByViewportSize = false
|
|
138
|
+
} = options;
|
|
139
|
+
|
|
60
140
|
this._parentEl = parentEl;
|
|
61
141
|
this._prevElSelector = prevElSelector;
|
|
62
142
|
this._nextElSelector = nextElSelector;
|
|
@@ -65,6 +145,9 @@ class Arrow implements Plugin {
|
|
|
65
145
|
this._moveByViewportSize = moveByViewportSize;
|
|
66
146
|
}
|
|
67
147
|
|
|
148
|
+
/** Initialize the plugin and attach arrow event listeners to the Flicking instance.
|
|
149
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
150
|
+
*/
|
|
68
151
|
public init(flicking: Flicking): void {
|
|
69
152
|
if (this._flicking) {
|
|
70
153
|
this.destroy();
|
|
@@ -92,6 +175,7 @@ class Arrow implements Plugin {
|
|
|
92
175
|
this.update();
|
|
93
176
|
}
|
|
94
177
|
|
|
178
|
+
/** Destroy the plugin and remove all arrow event listeners. */
|
|
95
179
|
public destroy(): void {
|
|
96
180
|
const flicking = this._flicking;
|
|
97
181
|
|
|
@@ -114,6 +198,7 @@ class Arrow implements Plugin {
|
|
|
114
198
|
this._flicking = null;
|
|
115
199
|
}
|
|
116
200
|
|
|
201
|
+
/** Update the arrow disabled/enabled state based on the current camera position. */
|
|
117
202
|
public update(): void {
|
|
118
203
|
this._updateClass(this._flicking!.camera.position);
|
|
119
204
|
}
|
|
@@ -133,8 +218,7 @@ class Arrow implements Plugin {
|
|
|
133
218
|
const moveCount = this._moveCount;
|
|
134
219
|
|
|
135
220
|
if (this._moveByViewportSize) {
|
|
136
|
-
flicking.control.moveToPosition(camera.position - camera.size, flicking.duration)
|
|
137
|
-
.catch(this._onCatch);
|
|
221
|
+
flicking.control.moveToPosition(camera.position - camera.size, flicking.duration).catch(this._onCatch);
|
|
138
222
|
} else {
|
|
139
223
|
if (flicking.circularEnabled) {
|
|
140
224
|
let targetPanel = flicking.currentPanel;
|
|
@@ -145,11 +229,9 @@ class Arrow implements Plugin {
|
|
|
145
229
|
|
|
146
230
|
targetPanel.focus().catch(this._onCatch);
|
|
147
231
|
} else if (flicking.index > firstAnchor.panel.index) {
|
|
148
|
-
flicking.moveTo(Math.max(flicking.index - moveCount, firstAnchor.panel.index))
|
|
149
|
-
.catch(this._onCatch);
|
|
232
|
+
flicking.moveTo(Math.max(flicking.index - moveCount, firstAnchor.panel.index)).catch(this._onCatch);
|
|
150
233
|
} else if (camera.position > camera.range.min) {
|
|
151
|
-
flicking.moveTo(flicking.index)
|
|
152
|
-
.catch(this._onCatch);
|
|
234
|
+
flicking.moveTo(flicking.index).catch(this._onCatch);
|
|
153
235
|
}
|
|
154
236
|
}
|
|
155
237
|
};
|
|
@@ -166,8 +248,7 @@ class Arrow implements Plugin {
|
|
|
166
248
|
const moveCount = this._moveCount;
|
|
167
249
|
|
|
168
250
|
if (this._moveByViewportSize) {
|
|
169
|
-
flicking.control.moveToPosition(camera.position + camera.size, flicking.duration)
|
|
170
|
-
.catch(this._onCatch);
|
|
251
|
+
flicking.control.moveToPosition(camera.position + camera.size, flicking.duration).catch(this._onCatch);
|
|
171
252
|
} else {
|
|
172
253
|
if (flicking.circularEnabled) {
|
|
173
254
|
let targetPanel = flicking.currentPanel;
|
|
@@ -178,11 +259,9 @@ class Arrow implements Plugin {
|
|
|
178
259
|
|
|
179
260
|
targetPanel.focus().catch(this._onCatch);
|
|
180
261
|
} else if (flicking.index < lastAnchor.panel.index) {
|
|
181
|
-
flicking.moveTo(Math.min(flicking.index + moveCount, lastAnchor.panel.index))
|
|
182
|
-
.catch(this._onCatch);
|
|
262
|
+
flicking.moveTo(Math.min(flicking.index + moveCount, lastAnchor.panel.index)).catch(this._onCatch);
|
|
183
263
|
} else if (camera.position > camera.range.min) {
|
|
184
|
-
flicking.moveTo(flicking.index)
|
|
185
|
-
.catch(this._onCatch);
|
|
264
|
+
flicking.moveTo(flicking.index).catch(this._onCatch);
|
|
186
265
|
}
|
|
187
266
|
}
|
|
188
267
|
};
|
|
@@ -206,12 +285,8 @@ class Arrow implements Plugin {
|
|
|
206
285
|
const nextEl = this._nextEl;
|
|
207
286
|
const cameraRange = flicking.camera.range;
|
|
208
287
|
|
|
209
|
-
const stopAtPrevEdge = flicking.circularEnabled
|
|
210
|
-
|
|
211
|
-
: pos <= cameraRange.min;
|
|
212
|
-
const stopAtNextEdge = flicking.circularEnabled
|
|
213
|
-
? false
|
|
214
|
-
: pos >= cameraRange.max;
|
|
288
|
+
const stopAtPrevEdge = flicking.circularEnabled ? false : pos <= cameraRange.min;
|
|
289
|
+
const stopAtNextEdge = flicking.circularEnabled ? false : pos >= cameraRange.max;
|
|
215
290
|
|
|
216
291
|
if (stopAtPrevEdge) {
|
|
217
292
|
addClass(prevEl, disabledClass);
|
package/src/AutoPlay.ts
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
import Flicking, {
|
|
1
|
+
import Flicking, { DIRECTION, EVENTS, MOVE_TYPE, Plugin } from "@egjs/flicking";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Options for the {@link AutoPlay} plugin
|
|
5
|
+
*/
|
|
6
|
+
export interface AutoPlayOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Time to wait before moving on to the next panel (ms)
|
|
9
|
+
* @defaultValue 2000
|
|
10
|
+
*/
|
|
4
11
|
duration: number;
|
|
12
|
+
/**
|
|
13
|
+
* Duration of the panel move animation (ms). If `undefined`, the Flicking instance's `duration` is used
|
|
14
|
+
* @defaultValue undefined
|
|
15
|
+
*/
|
|
5
16
|
animationDuration: number | undefined;
|
|
6
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The direction in which the panel moves
|
|
19
|
+
* @defaultValue "NEXT"
|
|
20
|
+
*/
|
|
21
|
+
direction: (typeof DIRECTION)["NEXT"] | (typeof DIRECTION)["PREV"];
|
|
22
|
+
/**
|
|
23
|
+
* Whether to stop when the mouse hovers over the element
|
|
24
|
+
* @defaultValue false
|
|
25
|
+
*/
|
|
7
26
|
stopOnHover: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Whether to stop autoplay when the plugin is first initialized
|
|
29
|
+
* @defaultValue false
|
|
30
|
+
*/
|
|
31
|
+
stopOnInit: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If `stopOnHover` is true, time to wait before resuming after mouse leaves (ms)
|
|
34
|
+
* @defaultValue Same as `duration`
|
|
35
|
+
*/
|
|
8
36
|
delayAfterHover: number;
|
|
9
37
|
}
|
|
10
38
|
|
|
11
39
|
/**
|
|
12
|
-
* Plugin that
|
|
13
|
-
* @
|
|
14
|
-
* @memberof Flicking.Plugins
|
|
40
|
+
* Plugin that allows you to automatically move to the next/previous panel on a specific time basis
|
|
41
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/autoplay | Demo: AutoPlay}
|
|
15
42
|
*/
|
|
16
43
|
class AutoPlay implements Plugin {
|
|
17
44
|
/* Options */
|
|
@@ -19,6 +46,7 @@ class AutoPlay implements Plugin {
|
|
|
19
46
|
private _animationDuration: AutoPlayOptions["animationDuration"];
|
|
20
47
|
private _direction: AutoPlayOptions["direction"];
|
|
21
48
|
private _stopOnHover: AutoPlayOptions["stopOnHover"];
|
|
49
|
+
private _stopOnInit: AutoPlayOptions["stopOnInit"];
|
|
22
50
|
private _delayAfterHover: AutoPlayOptions["delayAfterHover"];
|
|
23
51
|
|
|
24
52
|
/* Internal Values */
|
|
@@ -27,45 +55,90 @@ class AutoPlay implements Plugin {
|
|
|
27
55
|
private _mouseEntered = false;
|
|
28
56
|
private _playing = false;
|
|
29
57
|
|
|
30
|
-
|
|
31
|
-
public get
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
public get
|
|
58
|
+
/** Current value of the {@link AutoPlayOptions.duration | duration} option. */
|
|
59
|
+
public get duration() {
|
|
60
|
+
return this._duration;
|
|
61
|
+
}
|
|
62
|
+
/** Current value of the {@link AutoPlayOptions.animationDuration | animationDuration} option. */
|
|
63
|
+
public get animationDuration() {
|
|
64
|
+
return this._animationDuration;
|
|
65
|
+
}
|
|
66
|
+
/** Current value of the {@link AutoPlayOptions.direction | direction} option. */
|
|
67
|
+
public get direction() {
|
|
68
|
+
return this._direction;
|
|
69
|
+
}
|
|
70
|
+
/** Current value of the {@link AutoPlayOptions.stopOnHover | stopOnHover} option. */
|
|
71
|
+
public get stopOnHover() {
|
|
72
|
+
return this._stopOnHover;
|
|
73
|
+
}
|
|
74
|
+
/** Current value of the {@link AutoPlayOptions.stopOnInit | stopOnInit} option. */
|
|
75
|
+
public get stopOnInit() {
|
|
76
|
+
return this._stopOnInit;
|
|
77
|
+
}
|
|
78
|
+
/** Current value of the {@link AutoPlayOptions.delayAfterHover | delayAfterHover} option. */
|
|
79
|
+
public get delayAfterHover() {
|
|
80
|
+
return this._delayAfterHover;
|
|
81
|
+
}
|
|
82
|
+
/** Whether the autoplay is currently active
|
|
83
|
+
* @readonly
|
|
84
|
+
*/
|
|
85
|
+
public get playing() {
|
|
86
|
+
return this._playing;
|
|
87
|
+
}
|
|
36
88
|
|
|
37
|
-
|
|
38
|
-
public set
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
89
|
+
/** Sets {@link AutoPlayOptions.duration | duration}. */
|
|
90
|
+
public set duration(val: number) {
|
|
91
|
+
this._duration = val;
|
|
92
|
+
}
|
|
93
|
+
/** Sets {@link AutoPlayOptions.animationDuration | animationDuration}. */
|
|
94
|
+
public set animationDuration(val: number | undefined) {
|
|
95
|
+
this._animationDuration = val;
|
|
96
|
+
}
|
|
97
|
+
/** Sets {@link AutoPlayOptions.direction | direction}. */
|
|
98
|
+
public set direction(val: AutoPlayOptions["direction"]) {
|
|
99
|
+
this._direction = val;
|
|
100
|
+
}
|
|
101
|
+
/** Sets {@link AutoPlayOptions.stopOnHover | stopOnHover}. */
|
|
102
|
+
public set stopOnHover(val: boolean) {
|
|
103
|
+
this._stopOnHover = val;
|
|
104
|
+
}
|
|
105
|
+
/** Sets {@link AutoPlayOptions.stopOnInit | stopOnInit}. */
|
|
106
|
+
public set stopOnInit(val: boolean) {
|
|
107
|
+
this._stopOnInit = val;
|
|
108
|
+
}
|
|
109
|
+
/** Sets {@link AutoPlayOptions.delayAfterHover | delayAfterHover}. */
|
|
110
|
+
public set delayAfterHover(val: number) {
|
|
111
|
+
this._delayAfterHover = val;
|
|
112
|
+
}
|
|
42
113
|
|
|
43
114
|
/**
|
|
44
|
-
* @param
|
|
45
|
-
* @param {number} options.duration Time to wait before moving on to the next panel.<ko>다음 패널로 움직이기까지 대기 시간</ko>
|
|
46
|
-
* @param {number | undefined} options.animationDuration Duration of animation of moving to the next panel. If undefined, duration option of the Flicking instance is used instead.<ko>패널이 움직이는 애니메이션의 지속 시간, undefined라면 Flicking 인스턴스의 duration 값을 사용한다</ko>
|
|
47
|
-
* @param {"PREV" | "NEXT"} options.direction The direction in which the panel moves.<ko>패널이 움직이는 방향</ko>
|
|
48
|
-
* @param {boolean} options.stopOnHover Whether to stop when mouse hover upon the element.<ko>엘리먼트에 마우스를 올렸을 때 AutoPlay를 정지할지 여부</ko>
|
|
49
|
-
* @param {number} options.delayAfterHover If stopOnHover is true, the amount of time to wait before moving on to the next panel when mouse leaves the element.<ko>stopOnHover를 사용한다면 마우스가 엘리먼트로부터 나간 뒤 다음 패널로 움직이기까지 대기 시간</ko>
|
|
115
|
+
* @param options - Options for the AutoPlay instance
|
|
50
116
|
* @example
|
|
51
117
|
* ```ts
|
|
52
118
|
* flicking.addPlugins(new AutoPlay({ duration: 2000, direction: "NEXT" }));
|
|
53
119
|
* ```
|
|
54
120
|
*/
|
|
55
|
-
public constructor({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
121
|
+
public constructor(options: Partial<AutoPlayOptions> = {}) {
|
|
122
|
+
const {
|
|
123
|
+
duration = 2000,
|
|
124
|
+
animationDuration = undefined,
|
|
125
|
+
direction = DIRECTION.NEXT,
|
|
126
|
+
stopOnHover = false,
|
|
127
|
+
stopOnInit = false,
|
|
128
|
+
delayAfterHover
|
|
129
|
+
} = options;
|
|
130
|
+
|
|
62
131
|
this._duration = duration;
|
|
63
132
|
this._animationDuration = animationDuration;
|
|
64
133
|
this._direction = direction;
|
|
65
134
|
this._stopOnHover = stopOnHover;
|
|
135
|
+
this._stopOnInit = stopOnInit;
|
|
66
136
|
this._delayAfterHover = delayAfterHover ?? duration;
|
|
67
137
|
}
|
|
68
138
|
|
|
139
|
+
/** Initialize the plugin and start autoplay on the given Flicking instance.
|
|
140
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
141
|
+
*/
|
|
69
142
|
public init(flicking: Flicking): void {
|
|
70
143
|
if (this._flicking) {
|
|
71
144
|
this.destroy();
|
|
@@ -85,9 +158,12 @@ class AutoPlay implements Plugin {
|
|
|
85
158
|
targetEl.addEventListener("mouseleave", this._onMouseLeave, false);
|
|
86
159
|
}
|
|
87
160
|
|
|
88
|
-
this.
|
|
161
|
+
if (!this._stopOnInit) {
|
|
162
|
+
this.play();
|
|
163
|
+
}
|
|
89
164
|
}
|
|
90
165
|
|
|
166
|
+
/** Destroy the plugin, stop autoplay, and remove all event listeners. */
|
|
91
167
|
public destroy(): void {
|
|
92
168
|
const flicking = this._flicking;
|
|
93
169
|
|
|
@@ -110,14 +186,17 @@ class AutoPlay implements Plugin {
|
|
|
110
186
|
this._flicking = null;
|
|
111
187
|
}
|
|
112
188
|
|
|
189
|
+
/** Update the plugin state. This is a no-op for AutoPlay. */
|
|
113
190
|
public update(): void {
|
|
114
191
|
// DO-NOTHING
|
|
115
192
|
}
|
|
116
193
|
|
|
194
|
+
/** Start the autoplay timer. Panels will move automatically after the configured {@link AutoPlayOptions.duration | duration}. */
|
|
117
195
|
public play = () => {
|
|
118
196
|
this._movePanel(this._duration);
|
|
119
197
|
};
|
|
120
198
|
|
|
199
|
+
/** Stop the autoplay timer and cancel any pending panel movement. */
|
|
121
200
|
public stop = () => {
|
|
122
201
|
this._playing = false;
|
|
123
202
|
clearTimeout(this._timerId);
|