@egjs/flicking-plugins 4.8.0-beta.1 → 4.8.1-beta.0
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 +106 -51
- package/declaration/AutoPlay.d.ts +104 -44
- package/declaration/Fade.d.ts +41 -16
- package/declaration/Parallax.d.ts +41 -16
- package/declaration/Perspective.d.ts +71 -28
- package/declaration/Sync.d.ts +93 -37
- package/declaration/const.d.ts +31 -31
- package/declaration/event.d.ts +5 -5
- package/declaration/index.d.ts +13 -10
- package/declaration/pagination/Pagination.d.ts +141 -61
- package/declaration/pagination/index.d.ts +3 -3
- package/declaration/pagination/renderer/BulletRenderer.d.ts +11 -11
- package/declaration/pagination/renderer/FractionRenderer.d.ts +9 -9
- package/declaration/pagination/renderer/Renderer.d.ts +19 -19
- package/declaration/pagination/renderer/ScrollBulletRenderer.d.ts +12 -12
- package/declaration/tsdoc-metadata.json +11 -0
- package/declaration/type.d.ts +9 -9
- package/declaration/utils.d.ts +3 -3
- 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 +1030 -1591
- package/dist/plugins.esm.js.map +1 -1
- package/dist/plugins.js +1047 -1620
- 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 +133 -82
- package/src/AutoPlay.ts +105 -35
- package/src/Fade.ts +31 -11
- package/src/Parallax.ts +31 -11
- package/src/Perspective.ts +69 -22
- package/src/Sync.ts +69 -25
- 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/src/Sync.ts
CHANGED
|
@@ -1,64 +1,105 @@
|
|
|
1
|
+
import type { MoveEndEvent, MoveEvent, MoveStartEvent, Plugin, SelectEvent, WillChangeEvent } from "@egjs/flicking";
|
|
1
2
|
import Flicking, { clamp, EVENTS } from "@egjs/flicking";
|
|
2
|
-
import type { MoveEndEvent, MoveEvent, MoveStartEvent, Plugin, WillChangeEvent, SelectEvent } from "@egjs/flicking";
|
|
3
3
|
|
|
4
4
|
import { SYNC } from "./const";
|
|
5
5
|
import { addClass, removeClass } from "./utils";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @property {SychronizableFlickingOptions} [synchronizedFlickingOptions=[]] Detailed options for syncing Flickings.
|
|
8
|
+
* Options for the {@link Sync} plugin
|
|
10
9
|
*/
|
|
11
10
|
export interface SyncOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Method to synchronize between Flickings. `"camera"` syncs by camera position, `"index"` syncs by panel index
|
|
13
|
+
* @defaultValue "camera"
|
|
14
|
+
*/
|
|
12
15
|
type: typeof SYNC.TYPE.CAMERA | typeof SYNC.TYPE.INDEX;
|
|
16
|
+
/**
|
|
17
|
+
* Detailed options for each Flicking instance to synchronize
|
|
18
|
+
* @defaultValue []
|
|
19
|
+
*/
|
|
13
20
|
synchronizedFlickingOptions: SychronizableFlickingOptions[];
|
|
14
21
|
}
|
|
15
22
|
|
|
16
23
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @property {boolean} [isClickable=false] By enabling this option, clicking the given Flicking's panel will change the given & other Flicking's index
|
|
19
|
-
* @property {boolean} [isSlidable=false] By enabling this option, the given Flicking's scroll with mouse/touch input will change other Flicking's index. Only available for the index type
|
|
20
|
-
* @property {string | undefined} [activeClass=undefined] An extra class for the panels when selected
|
|
24
|
+
* Per-instance synchronization options used in {@link SyncOptions.synchronizedFlickingOptions}
|
|
21
25
|
*/
|
|
22
26
|
export interface SychronizableFlickingOptions {
|
|
27
|
+
/**
|
|
28
|
+
* The Flicking instance to synchronize
|
|
29
|
+
*/
|
|
23
30
|
flicking: Flicking;
|
|
31
|
+
/**
|
|
32
|
+
* Whether clicking this Flicking's panel changes the index of all synced Flickings
|
|
33
|
+
* @defaultValue false
|
|
34
|
+
*/
|
|
24
35
|
isClickable?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether mouse/touch scroll on this Flicking changes other Flickings' index. Only available for the `"index"` type
|
|
38
|
+
* @defaultValue false
|
|
39
|
+
*/
|
|
25
40
|
isSlidable?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* CSS class added to the active (selected) panel
|
|
43
|
+
* @defaultValue undefined
|
|
44
|
+
*/
|
|
26
45
|
activeClass?: string;
|
|
27
46
|
}
|
|
28
47
|
|
|
29
48
|
/**
|
|
30
|
-
* Plugin for synchronizing multiple
|
|
31
|
-
* @
|
|
32
|
-
* @memberof Flicking.Plugins
|
|
49
|
+
* Plugin for synchronizing multiple Flicking instances
|
|
50
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/sync | Demo: Sync}
|
|
33
51
|
*/
|
|
34
52
|
class Sync implements Plugin {
|
|
35
53
|
/* Internal Values */
|
|
36
54
|
private _flicking: Flicking | null = null;
|
|
55
|
+
private _disabledIndex: number[] = [];
|
|
37
56
|
|
|
38
57
|
/* Options */
|
|
39
58
|
private _type: SyncOptions["type"];
|
|
40
59
|
private _synchronizedFlickingOptions: SyncOptions["synchronizedFlickingOptions"];
|
|
41
60
|
|
|
42
|
-
|
|
43
|
-
public get
|
|
61
|
+
/** Current value of the {@link SyncOptions.type | type} option. */
|
|
62
|
+
public get type() {
|
|
63
|
+
return this._type;
|
|
64
|
+
}
|
|
65
|
+
/** Current value of the {@link SyncOptions.synchronizedFlickingOptions | synchronizedFlickingOptions} option. */
|
|
66
|
+
public get synchronizedFlickingOptions() {
|
|
67
|
+
return this._synchronizedFlickingOptions;
|
|
68
|
+
}
|
|
44
69
|
|
|
70
|
+
/** Sets {@link SyncOptions.type | type}. */
|
|
45
71
|
public set type(val: SyncOptions["type"]) {
|
|
46
72
|
this._type = val;
|
|
47
73
|
}
|
|
48
74
|
|
|
75
|
+
/** Sets {@link SyncOptions.synchronizedFlickingOptions | synchronizedFlickingOptions}. */
|
|
49
76
|
public set synchronizedFlickingOptions(val: SyncOptions["synchronizedFlickingOptions"]) {
|
|
50
77
|
this._synchronizedFlickingOptions = val;
|
|
51
78
|
}
|
|
52
79
|
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
80
|
+
/**
|
|
81
|
+
* @param options - Options for the Sync instance
|
|
82
|
+
* @example
|
|
83
|
+
* ```ts
|
|
84
|
+
* flicking.addPlugins(new Sync({
|
|
85
|
+
* type: "camera",
|
|
86
|
+
* synchronizedFlickingOptions: [
|
|
87
|
+
* { flicking: flicking1 },
|
|
88
|
+
* { flicking: flicking2, isClickable: true }
|
|
89
|
+
* ]
|
|
90
|
+
* }));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
public constructor(options: Partial<SyncOptions> = {}) {
|
|
94
|
+
const { type = SYNC.TYPE.CAMERA, synchronizedFlickingOptions = [] } = options;
|
|
95
|
+
|
|
58
96
|
this._type = type;
|
|
59
97
|
this._synchronizedFlickingOptions = synchronizedFlickingOptions;
|
|
60
98
|
}
|
|
61
99
|
|
|
100
|
+
/** Initialize the plugin and set up synchronization event listeners between Flicking instances.
|
|
101
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
102
|
+
*/
|
|
62
103
|
public init(flicking: Flicking): void {
|
|
63
104
|
const synced = this._synchronizedFlickingOptions;
|
|
64
105
|
|
|
@@ -77,6 +118,7 @@ class Sync implements Plugin {
|
|
|
77
118
|
});
|
|
78
119
|
}
|
|
79
120
|
|
|
121
|
+
/** Destroy the plugin and remove all synchronization event listeners. */
|
|
80
122
|
public destroy(): void {
|
|
81
123
|
const flicking = this._flicking;
|
|
82
124
|
|
|
@@ -89,6 +131,7 @@ class Sync implements Plugin {
|
|
|
89
131
|
this._flicking = null;
|
|
90
132
|
}
|
|
91
133
|
|
|
134
|
+
/** Update the active class state for all synchronized Flicking instances. */
|
|
92
135
|
public update(): void {
|
|
93
136
|
this._synchronizedFlickingOptions.forEach(options => {
|
|
94
137
|
this._updateClass(options, options.flicking.index);
|
|
@@ -173,19 +216,20 @@ class Sync implements Plugin {
|
|
|
173
216
|
};
|
|
174
217
|
|
|
175
218
|
private _onMoveStart = (e: MoveStartEvent): void => {
|
|
176
|
-
this.
|
|
177
|
-
|
|
219
|
+
this._disabledIndex = [];
|
|
220
|
+
this._synchronizedFlickingOptions.forEach(({ flicking }, i) => {
|
|
221
|
+
if (flicking !== e.currentTarget && flicking.control.controller.enabled) {
|
|
222
|
+
this._disabledIndex.push(i);
|
|
178
223
|
flicking.disableInput();
|
|
179
224
|
}
|
|
180
225
|
});
|
|
181
226
|
};
|
|
182
227
|
|
|
183
228
|
private _onMoveEnd = (e: MoveEndEvent): void => {
|
|
184
|
-
this.
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
229
|
+
this._disabledIndex.forEach(i => {
|
|
230
|
+
const flicking = this._synchronizedFlickingOptions[i].flicking;
|
|
231
|
+
flicking.enableInput();
|
|
232
|
+
flicking.control.updateInput();
|
|
189
233
|
});
|
|
190
234
|
};
|
|
191
235
|
|
|
@@ -224,7 +268,7 @@ class Sync implements Plugin {
|
|
|
224
268
|
if (!activeClass) return;
|
|
225
269
|
|
|
226
270
|
flicking.panels.forEach(panel => {
|
|
227
|
-
if (panel.index === index)
|
|
271
|
+
if (panel.index === index) {
|
|
228
272
|
addClass(panel.element, activeClass);
|
|
229
273
|
} else {
|
|
230
274
|
removeClass(panel.element, activeClass);
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @namespace Flicking
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* @namespace Flicking.Plugins
|
|
6
|
-
*/
|
|
7
|
-
import Parallax from "./Parallax";
|
|
8
|
-
import Fade from "./Fade";
|
|
9
|
-
import AutoPlay from "./AutoPlay";
|
|
10
1
|
import Arrow from "./Arrow";
|
|
11
|
-
import
|
|
2
|
+
import AutoPlay from "./AutoPlay";
|
|
3
|
+
import Fade from "./Fade";
|
|
4
|
+
import Parallax from "./Parallax";
|
|
12
5
|
import Perspective from "./Perspective";
|
|
6
|
+
import Sync, { SychronizableFlickingOptions, SyncOptions } from "./Sync";
|
|
13
7
|
|
|
14
8
|
export * from "./pagination";
|
|
15
9
|
|
|
16
|
-
export {
|
|
17
|
-
Parallax,
|
|
18
|
-
Fade,
|
|
19
|
-
AutoPlay,
|
|
20
|
-
Arrow,
|
|
21
|
-
Sync,
|
|
22
|
-
Perspective
|
|
23
|
-
};
|
|
10
|
+
export { Parallax, Fade, AutoPlay, Arrow, Sync, Perspective };
|
|
24
11
|
|
|
25
|
-
export type {
|
|
26
|
-
SyncOptions,
|
|
27
|
-
SychronizableFlickingOptions
|
|
28
|
-
};
|
|
12
|
+
export type { SyncOptions, SychronizableFlickingOptions };
|
|
29
13
|
|
|
14
|
+
export type { ArrowOptions } from "./Arrow";
|
|
15
|
+
export type { AutoPlayOptions } from "./AutoPlay";
|
|
30
16
|
export * from "./const";
|
|
17
|
+
export type { PerspectiveOptions } from "./Perspective";
|
|
@@ -2,28 +2,70 @@ import Flicking, { EVENTS, Plugin } from "@egjs/flicking";
|
|
|
2
2
|
|
|
3
3
|
import { PAGINATION } from "../const";
|
|
4
4
|
import ScrollContext from "../type";
|
|
5
|
-
|
|
6
|
-
import Renderer from "./renderer/Renderer";
|
|
7
5
|
import BulletRenderer from "./renderer/BulletRenderer";
|
|
8
6
|
import FractionRenderer from "./renderer/FractionRenderer";
|
|
7
|
+
import Renderer from "./renderer/Renderer";
|
|
9
8
|
import ScrollBulletRenderer from "./renderer/ScrollBulletRenderer";
|
|
10
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Options for the {@link Pagination} plugin
|
|
12
|
+
*/
|
|
11
13
|
export interface PaginationOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The parent element to search for the pagination wrapper. If `null`, the Flicking element is used
|
|
16
|
+
* @defaultValue null
|
|
17
|
+
*/
|
|
12
18
|
parentEl: HTMLElement | null;
|
|
19
|
+
/**
|
|
20
|
+
* CSS selector for the pagination wrapper element
|
|
21
|
+
* @defaultValue ".flicking-pagination"
|
|
22
|
+
*/
|
|
13
23
|
selector: string;
|
|
24
|
+
/**
|
|
25
|
+
* Pagination display type
|
|
26
|
+
* @defaultValue "bullet"
|
|
27
|
+
*/
|
|
14
28
|
type: "bullet" | "fraction" | "scroll";
|
|
29
|
+
/**
|
|
30
|
+
* CSS class prefix for pagination elements
|
|
31
|
+
* @defaultValue "flicking-pagination"
|
|
32
|
+
*/
|
|
15
33
|
classPrefix: string;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum number of bullet indicators displayed at once (only for `"scroll"` type)
|
|
36
|
+
* @defaultValue 5
|
|
37
|
+
*/
|
|
16
38
|
bulletCount: number;
|
|
39
|
+
/**
|
|
40
|
+
* Custom render function for each bullet element
|
|
41
|
+
*/
|
|
17
42
|
renderBullet: (className: string, index: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Custom render function for the fraction display
|
|
45
|
+
*/
|
|
18
46
|
renderFraction: (currentClass: string, totalClass: string) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Custom render function for the active bullet element. If `null`, the default bullet is used
|
|
49
|
+
* @defaultValue null
|
|
50
|
+
*/
|
|
19
51
|
renderActiveBullet: ((className: string, index: number) => string) | null;
|
|
52
|
+
/**
|
|
53
|
+
* Format function for the current index in fraction type
|
|
54
|
+
*/
|
|
20
55
|
fractionCurrentFormat: (index: number) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Format function for the total count in fraction type
|
|
58
|
+
*/
|
|
21
59
|
fractionTotalFormat: (total: number) => string;
|
|
60
|
+
/**
|
|
61
|
+
* Callback invoked when the scroll pagination index changes
|
|
62
|
+
*/
|
|
22
63
|
scrollOnChange: (index: number, ctx: ScrollContext) => any;
|
|
23
64
|
}
|
|
24
65
|
|
|
25
66
|
/**
|
|
26
|
-
*
|
|
67
|
+
* A plugin to add pagination indicators (bullets, fractions, or scrollable bullets) to Flicking
|
|
68
|
+
* @see {@link https://naver.github.io/egjs-flicking/docs/demos/plugins/pagination | Demo: Pagination}
|
|
27
69
|
*/
|
|
28
70
|
class Pagination implements Plugin {
|
|
29
71
|
/* Internal Values */
|
|
@@ -44,43 +86,119 @@ class Pagination implements Plugin {
|
|
|
44
86
|
private _fractionTotalFormat: PaginationOptions["fractionTotalFormat"];
|
|
45
87
|
private _scrollOnChange: PaginationOptions["scrollOnChange"];
|
|
46
88
|
|
|
47
|
-
|
|
48
|
-
public get
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
public get
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
public get
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
public
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
public
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
public
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
/** Current value of the {@link PaginationOptions.parentEl | parentEl} option. */
|
|
90
|
+
public get parentEl() {
|
|
91
|
+
return this._parentEl;
|
|
92
|
+
}
|
|
93
|
+
/** Current value of the {@link PaginationOptions.selector | selector} option. */
|
|
94
|
+
public get selector() {
|
|
95
|
+
return this._selector;
|
|
96
|
+
}
|
|
97
|
+
/** Current value of the {@link PaginationOptions.type | type} option. */
|
|
98
|
+
public get type() {
|
|
99
|
+
return this._type;
|
|
100
|
+
}
|
|
101
|
+
/** Current value of the {@link PaginationOptions.classPrefix | classPrefix} option. */
|
|
102
|
+
public get classPrefix() {
|
|
103
|
+
return this._classPrefix;
|
|
104
|
+
}
|
|
105
|
+
/** Current value of the {@link PaginationOptions.bulletCount | bulletCount} option. */
|
|
106
|
+
public get bulletCount() {
|
|
107
|
+
return this._bulletCount;
|
|
108
|
+
}
|
|
109
|
+
/** Current value of the {@link PaginationOptions.renderBullet | renderBullet} option. */
|
|
110
|
+
public get renderBullet() {
|
|
111
|
+
return this._renderBullet;
|
|
112
|
+
}
|
|
113
|
+
/** Current value of the {@link PaginationOptions.renderActiveBullet | renderActiveBullet} option. */
|
|
114
|
+
public get renderActiveBullet() {
|
|
115
|
+
return this._renderActiveBullet;
|
|
116
|
+
}
|
|
117
|
+
/** Current value of the {@link PaginationOptions.renderFraction | renderFraction} option. */
|
|
118
|
+
public get renderFraction() {
|
|
119
|
+
return this._renderFraction;
|
|
120
|
+
}
|
|
121
|
+
/** Current value of the {@link PaginationOptions.fractionCurrentFormat | fractionCurrentFormat} option. */
|
|
122
|
+
public get fractionCurrentFormat() {
|
|
123
|
+
return this._fractionCurrentFormat;
|
|
124
|
+
}
|
|
125
|
+
/** Current value of the {@link PaginationOptions.fractionTotalFormat | fractionTotalFormat} option. */
|
|
126
|
+
public get fractionTotalFormat() {
|
|
127
|
+
return this._fractionTotalFormat;
|
|
128
|
+
}
|
|
129
|
+
/** Current value of the {@link PaginationOptions.scrollOnChange | scrollOnChange} option. */
|
|
130
|
+
public get scrollOnChange() {
|
|
131
|
+
return this._scrollOnChange;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Sets {@link PaginationOptions.parentEl | parentEl}. */
|
|
135
|
+
public set parentEl(val: PaginationOptions["parentEl"]) {
|
|
136
|
+
this._parentEl = val;
|
|
137
|
+
}
|
|
138
|
+
/** Sets {@link PaginationOptions.selector | selector}. */
|
|
139
|
+
public set selector(val: PaginationOptions["selector"]) {
|
|
140
|
+
this._selector = val;
|
|
141
|
+
}
|
|
142
|
+
/** Sets {@link PaginationOptions.type | type}. */
|
|
143
|
+
public set type(val: PaginationOptions["type"]) {
|
|
144
|
+
this._type = val;
|
|
145
|
+
}
|
|
146
|
+
/** Sets {@link PaginationOptions.classPrefix | classPrefix}. */
|
|
147
|
+
public set bulletWrapperclassPrefixClass(val: PaginationOptions["classPrefix"]) {
|
|
148
|
+
this._classPrefix = val;
|
|
149
|
+
}
|
|
150
|
+
/** Sets {@link PaginationOptions.bulletCount | bulletCount}. */
|
|
151
|
+
public set bulletCount(val: PaginationOptions["bulletCount"]) {
|
|
152
|
+
this._bulletCount = val;
|
|
153
|
+
}
|
|
154
|
+
/** Sets {@link PaginationOptions.renderBullet | renderBullet}. */
|
|
155
|
+
public set renderBullet(val: PaginationOptions["renderBullet"]) {
|
|
156
|
+
this._renderBullet = val;
|
|
157
|
+
}
|
|
158
|
+
/** Sets {@link PaginationOptions.renderActiveBullet | renderActiveBullet}. */
|
|
159
|
+
public set renderActiveBullet(val: PaginationOptions["renderActiveBullet"]) {
|
|
160
|
+
this._renderActiveBullet = val;
|
|
161
|
+
}
|
|
162
|
+
/** Sets {@link PaginationOptions.renderFraction | renderFraction}. */
|
|
163
|
+
public set renderFraction(val: PaginationOptions["renderFraction"]) {
|
|
164
|
+
this._renderFraction = val;
|
|
165
|
+
}
|
|
166
|
+
/** Sets {@link PaginationOptions.fractionCurrentFormat | fractionCurrentFormat}. */
|
|
167
|
+
public set fractionCurrentFormat(val: PaginationOptions["fractionCurrentFormat"]) {
|
|
168
|
+
this._fractionCurrentFormat = val;
|
|
169
|
+
}
|
|
170
|
+
/** Sets {@link PaginationOptions.fractionTotalFormat | fractionTotalFormat}. */
|
|
171
|
+
public set fractionTotalFormat(val: PaginationOptions["fractionTotalFormat"]) {
|
|
172
|
+
this._fractionTotalFormat = val;
|
|
173
|
+
}
|
|
174
|
+
/** Sets {@link PaginationOptions.scrollOnChange | scrollOnChange}. */
|
|
175
|
+
public set scrollOnChange(val: PaginationOptions["scrollOnChange"]) {
|
|
176
|
+
this._scrollOnChange = val;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param options - Options for the Pagination instance
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* flicking.addPlugins(new Pagination({ type: "bullet", selector: ".flicking-pagination" }));
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
public constructor(options: Partial<PaginationOptions> = {}) {
|
|
187
|
+
const {
|
|
188
|
+
parentEl = null,
|
|
189
|
+
selector = PAGINATION.SELECTOR,
|
|
190
|
+
type = PAGINATION.TYPE.BULLET,
|
|
191
|
+
classPrefix = PAGINATION.PREFIX,
|
|
192
|
+
bulletCount = 5,
|
|
193
|
+
renderBullet = (className: string) => `<span class="${className}"></span>`,
|
|
194
|
+
renderActiveBullet = null,
|
|
195
|
+
renderFraction = (currentClass: string, totalClass: string) =>
|
|
196
|
+
`<span class="${currentClass}"></span>/<span class="${totalClass}"></span>`,
|
|
197
|
+
fractionCurrentFormat = (index: number) => index.toString(),
|
|
198
|
+
fractionTotalFormat = (index: number) => index.toString(),
|
|
199
|
+
scrollOnChange = (index: number, ctx: ScrollContext) => ctx.moveTo(index)
|
|
200
|
+
} = options;
|
|
201
|
+
|
|
84
202
|
this._parentEl = parentEl;
|
|
85
203
|
this._selector = selector;
|
|
86
204
|
this._type = type;
|
|
@@ -94,6 +212,9 @@ class Pagination implements Plugin {
|
|
|
94
212
|
this._scrollOnChange = scrollOnChange;
|
|
95
213
|
}
|
|
96
214
|
|
|
215
|
+
/** Initialize the plugin, create the pagination renderer, and attach event listeners to the Flicking instance.
|
|
216
|
+
* @param flicking - The Flicking instance to attach this plugin to
|
|
217
|
+
*/
|
|
97
218
|
public init(flicking: Flicking): void {
|
|
98
219
|
if (this._flicking) {
|
|
99
220
|
this.destroy();
|
|
@@ -120,6 +241,7 @@ class Pagination implements Plugin {
|
|
|
120
241
|
this.update();
|
|
121
242
|
}
|
|
122
243
|
|
|
244
|
+
/** Destroy the plugin, remove all event listeners, and clean up pagination DOM elements. */
|
|
123
245
|
public destroy(): void {
|
|
124
246
|
const flicking = this._flicking;
|
|
125
247
|
|
|
@@ -136,6 +258,7 @@ class Pagination implements Plugin {
|
|
|
136
258
|
this._flicking = null;
|
|
137
259
|
}
|
|
138
260
|
|
|
261
|
+
/** Re-render the pagination indicators to reflect the current panel state. */
|
|
139
262
|
public update = (): void => {
|
|
140
263
|
this._removeAllChilds();
|
|
141
264
|
this._renderer.render();
|
package/src/pagination/index.ts
CHANGED
|
@@ -83,10 +83,7 @@ class BulletRenderer extends Renderer {
|
|
|
83
83
|
if (renderActiveBullet) {
|
|
84
84
|
const prevBullet = bullets[prevIndex];
|
|
85
85
|
if (prevBullet) {
|
|
86
|
-
const newBullet = this._createBulletFromString(
|
|
87
|
-
renderBullet(bulletClass, prevIndex),
|
|
88
|
-
prevIndex
|
|
89
|
-
);
|
|
86
|
+
const newBullet = this._createBulletFromString(renderBullet(bulletClass, prevIndex), prevIndex);
|
|
90
87
|
prevBullet.parentElement!.replaceChild(newBullet, prevBullet);
|
|
91
88
|
bullets[prevIndex] = newBullet;
|
|
92
89
|
}
|
|
@@ -33,9 +33,7 @@ class FractionRenderer extends Renderer {
|
|
|
33
33
|
const pagination = this._pagination;
|
|
34
34
|
|
|
35
35
|
const anchorPoints = flicking.camera.anchorPoints;
|
|
36
|
-
const currentIndex = anchorPoints.length > 0
|
|
37
|
-
? index - anchorPoints[0].panel.index + 1
|
|
38
|
-
: 0;
|
|
36
|
+
const currentIndex = anchorPoints.length > 0 ? index - anchorPoints[0].panel.index + 1 : 0;
|
|
39
37
|
const anchorCount = anchorPoints.length;
|
|
40
38
|
|
|
41
39
|
if (currentIndex === this._prevIndex && anchorCount === this._prevTotal) return;
|
|
@@ -14,11 +14,9 @@ abstract class Renderer {
|
|
|
14
14
|
protected _pagination: Pagination;
|
|
15
15
|
protected _wrapper: HTMLElement;
|
|
16
16
|
|
|
17
|
-
public constructor({
|
|
18
|
-
flicking,
|
|
19
|
-
|
|
20
|
-
wrapper
|
|
21
|
-
}: RendererOptions) {
|
|
17
|
+
public constructor(options: RendererOptions) {
|
|
18
|
+
const { flicking, pagination, wrapper } = options;
|
|
19
|
+
|
|
22
20
|
this._flicking = flicking;
|
|
23
21
|
this._pagination = pagination;
|
|
24
22
|
this._wrapper = wrapper;
|
|
@@ -46,16 +44,19 @@ abstract class Renderer {
|
|
|
46
44
|
e.stopPropagation();
|
|
47
45
|
});
|
|
48
46
|
|
|
49
|
-
bullet.addEventListener(
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
bullet.addEventListener(
|
|
48
|
+
BROWSER.TOUCH_START,
|
|
49
|
+
e => {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
},
|
|
52
|
+
{ passive: true }
|
|
53
|
+
);
|
|
52
54
|
|
|
53
55
|
bullet.addEventListener(BROWSER.CLICK, () => {
|
|
54
|
-
this._flicking.moveTo(panelIndex)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
56
|
+
this._flicking.moveTo(panelIndex).catch(err => {
|
|
57
|
+
if (err instanceof FlickingError) return;
|
|
58
|
+
throw err;
|
|
59
|
+
});
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -37,9 +37,7 @@ class ScrollBulletRenderer extends Renderer {
|
|
|
37
37
|
addClass(wrapper, dynamicWrapperClass);
|
|
38
38
|
wrapper.appendChild(sliderEl);
|
|
39
39
|
|
|
40
|
-
sliderEl.innerHTML = anchorPoints
|
|
41
|
-
.map((_, index) => renderBullet(bulletClass, index))
|
|
42
|
-
.join("\n");
|
|
40
|
+
sliderEl.innerHTML = anchorPoints.map((_, index) => renderBullet(bulletClass, index)).join("\n");
|
|
43
41
|
|
|
44
42
|
const bullets = [].slice.call(sliderEl.children) as HTMLElement[];
|
|
45
43
|
|
|
@@ -50,7 +48,8 @@ class ScrollBulletRenderer extends Renderer {
|
|
|
50
48
|
if (bullets.length <= 0) return;
|
|
51
49
|
|
|
52
50
|
const bulletStyle = getComputedStyle(bullets[0]);
|
|
53
|
-
const bulletSize =
|
|
51
|
+
const bulletSize =
|
|
52
|
+
bullets[0].clientWidth + parseFloat(bulletStyle.marginLeft) + parseFloat(bulletStyle.marginRight);
|
|
54
53
|
|
|
55
54
|
wrapper.style.width = `${bulletSize * pagination.bulletCount}px`;
|
|
56
55
|
|
|
@@ -93,20 +92,14 @@ class ScrollBulletRenderer extends Renderer {
|
|
|
93
92
|
if (renderActiveBullet) {
|
|
94
93
|
const prevBullet = bullets[prevIndex];
|
|
95
94
|
if (prevBullet) {
|
|
96
|
-
const newBullet = this._createBulletFromString(
|
|
97
|
-
renderBullet(bulletClass, prevIndex),
|
|
98
|
-
prevIndex
|
|
99
|
-
);
|
|
95
|
+
const newBullet = this._createBulletFromString(renderBullet(bulletClass, prevIndex), prevIndex);
|
|
100
96
|
prevBullet.parentElement!.replaceChild(newBullet, prevBullet);
|
|
101
97
|
bullets[prevIndex] = newBullet;
|
|
102
98
|
}
|
|
103
99
|
|
|
104
100
|
const activeBullet = bullets[activeIndex];
|
|
105
101
|
if (activeBullet) {
|
|
106
|
-
const newActiveBullet = this._createBulletFromString(
|
|
107
|
-
renderActiveBullet(bulletClass, activeIndex),
|
|
108
|
-
activeIndex
|
|
109
|
-
);
|
|
102
|
+
const newActiveBullet = this._createBulletFromString(renderActiveBullet(bulletClass, activeIndex), activeIndex);
|
|
110
103
|
|
|
111
104
|
activeBullet.parentElement!.replaceChild(newActiveBullet, activeBullet);
|
|
112
105
|
bullets[activeIndex] = newActiveBullet;
|
package/CONTRIBUTING
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# How to contribute to egjs-flicking
|
|
2
|
-
egjs-flicking is opened to everyone and we're welcoming for any kind of contribution.
|
|
3
|
-
We believe that our project can grow with your interests helping others' necessities.
|
|
4
|
-
|
|
5
|
-
## Style Guide
|
|
6
|
-
|
|
7
|
-
egjs-flicking has several style guidelines to follow.
|
|
8
|
-
Before your start, please read attentively below instructions.
|
|
9
|
-
|
|
10
|
-
### Linting and Code Conventions
|
|
11
|
-
We adopted [ESLint](http://eslint.org/) to maintain our code quality. The [rules](https://github.com/naver/eslint-config-naver/tree/master/rules) are modified version based on [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript).
|
|
12
|
-
All rules are described at [.eslintrc](.eslintrc) file.
|
|
13
|
-
|
|
14
|
-
### Commit Log Guidelines
|
|
15
|
-
egjs-flicking use commit logs in many different purposes (like creating CHANGELOG, ease history searching, etc.).
|
|
16
|
-
To not break, you'll be forced to follow our commit log guidelines.
|
|
17
|
-
Before your commit/push, make sure following our commit log guidelines.
|
|
18
|
-
|
|
19
|
-
The outline is as below:
|
|
20
|
-
```
|
|
21
|
-
<type>(<module>): <subject>
|
|
22
|
-
<BLANK LINE>
|
|
23
|
-
<body>
|
|
24
|
-
<BLANK LINE>
|
|
25
|
-
<footer>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
- **Types**
|
|
29
|
-
- **feat**: A new feature
|
|
30
|
-
- **fix**: A bug fix
|
|
31
|
-
- **docs**: Documentation only changes
|
|
32
|
-
- **style**: Changes that do not affect the meaning of the code. Such as white-space, formatting, missing semi-colons, etc... It also possible to change JSHint, JSCS rules of the code.
|
|
33
|
-
- **refactor**: A code change that neither fixes a bug nor adds a feature
|
|
34
|
-
- **test**: Adding missing tests. Changing tests.
|
|
35
|
-
- **demo**: Adding missing demos. Changing demos.
|
|
36
|
-
- **chore**: Changes to the build process or tools and libraries such as documentation generation
|
|
37
|
-
|
|
38
|
-
[See More Commit Log Guidelines](https://github.com/naver/egjs/wiki/Commit-Log-Guidelines)
|
|
39
|
-
|
|
40
|
-
## How to submit Pull Requests
|
|
41
|
-
Steps to submit your pull request:
|
|
42
|
-
|
|
43
|
-
1. Fork `egjs-flicking` on your repository
|
|
44
|
-
2. Create new branch from your egjs master branch (and be sure always to be up-to-date)
|
|
45
|
-
3. Do your work
|
|
46
|
-
4. Create test code for your work (when is possible)
|
|
47
|
-
5. Run `npm run lint` for linting and Code Conventions (update until without any error or warnings)
|
|
48
|
-
6. Run test code by `npm run test OR npm run test:chrome`.
|
|
49
|
-
Make sure tests are all passed at least in Chrome(latest desktop version)
|
|
50
|
-
8. Write commit log following convention and push to your repository branch.
|
|
51
|
-
9. Create a new PR from your branch to egjs-flicking.
|
|
52
|
-
10. Wait for reviews.
|
|
53
|
-
When your contribution is well enough to be accepted, then will be merged to our branch.
|
|
54
|
-
11. All done!
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## License
|
|
58
|
-
By contributing to egjs-flicking, you're agreeing that your contributions will be licensed under its [MIT](https://opensource.org/licenses/MIT) license.
|