well-waterfall 1.0.4 → 1.0.7
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/.prettierrc +2 -1
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/lib/attributes.ts +278 -3
- package/src/modules/accessibility.ts +33 -52
- package/src/modules/breakpoints.ts +43 -22
- package/src/modules/controller.ts +8 -10
- package/src/modules/effect.ts +42 -23
- package/src/modules/general.ts +194 -161
- package/src/modules/hashhistory.ts +17 -9
- package/src/modules/input.ts +29 -19
- package/src/modules/layout.ts +5 -4
- package/src/modules/manipulation.ts +19 -9
- package/src/modules/navigation.ts +20 -18
- package/src/modules/pagination.ts +66 -92
- package/src/modules/playback.ts +35 -24
- package/src/modules/scrollbar.ts +29 -31
- package/src/modules/slideCount.ts +5 -3
- package/src/modules/thumbs.ts +19 -25
- package/src/modules/zoom.ts +18 -17
- package/src/util.ts +55 -100
- package/src/waterfall.ts +64 -47
- package/tsconfig.json +3 -0
- package/webpack.config.js +3 -0
|
@@ -1,118 +1,92 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ATTR_NAVIGATION_LOCK_CLASS,
|
|
3
|
+
ATTR_PAGINATION,
|
|
4
|
+
ATTR_PAGINATION_BULLET,
|
|
5
|
+
ATTR_PAGINATION_BULLET_ACTIVE,
|
|
6
|
+
ATTR_PAGINATION_CLICKABLE,
|
|
7
|
+
ATTR_PAGINATION_CLICKABLE_CLASS,
|
|
8
|
+
ATTR_PAGINATION_CURRENT_CLASS,
|
|
9
|
+
ATTR_PAGINATION_DYNAMIC_BULLETS,
|
|
10
|
+
ATTR_PAGINATION_DYNAMIC_MAIN_BULLETS,
|
|
11
|
+
ATTR_PAGINATION_ENABLED,
|
|
12
|
+
ATTR_PAGINATION_HIDDEN_CLASS,
|
|
13
|
+
ATTR_PAGINATION_HIDE_ON_CLICK,
|
|
14
|
+
ATTR_PAGINATION_HORIZONTAL_CLASS,
|
|
15
|
+
ATTR_PAGINATION_MODIFIER_CLASS,
|
|
16
|
+
ATTR_PAGINATION_PAGINATION_DISABLED_CLASS,
|
|
17
|
+
ATTR_PAGINATION_PROGRESSBAR_FILL_CLASS,
|
|
18
|
+
ATTR_PAGINATION_PROGRESSBAR_OPPOSITE,
|
|
19
|
+
ATTR_PAGINATION_TOTAL_CLASS,
|
|
20
|
+
ATTR_PAGINATION_TYPE,
|
|
21
|
+
ATTR_PAGINATION_VERTICAL_CLASS,
|
|
22
|
+
ATTR_WATERFALL_ELEMENT,
|
|
23
|
+
} from "lib/attributes";
|
|
24
|
+
import { getUniqueClasses, parseAttr } from "../util";
|
|
2
25
|
|
|
3
|
-
export function paginationConfig(
|
|
4
|
-
|
|
26
|
+
export function paginationConfig(element: HTMLElement) {
|
|
27
|
+
const paginationType = parseAttr(element, ATTR_PAGINATION_TYPE, "");
|
|
5
28
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
29
|
+
const paginationBullet = element.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${ATTR_PAGINATION_BULLET}]`);
|
|
30
|
+
const paginationBulletActive = element.querySelector<HTMLElement>(
|
|
31
|
+
`[${ATTR_WATERFALL_ELEMENT}=${ATTR_PAGINATION_BULLET_ACTIVE}]`,
|
|
9
32
|
);
|
|
33
|
+
const paginationEl = element.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${ATTR_PAGINATION}]`);
|
|
10
34
|
|
|
11
35
|
return {
|
|
12
|
-
bulletActiveClass:
|
|
13
|
-
paginationBulletActive,
|
|
14
|
-
|
|
15
|
-
),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
),
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
),
|
|
29
|
-
dynamicBullets: parseAttr(
|
|
30
|
-
$this,
|
|
31
|
-
'dynamic-bullets',
|
|
32
|
-
'swiper-pagination-current',
|
|
33
|
-
),
|
|
34
|
-
dynamicMainBullets: parseAttr($this, 'dynamic-main-bullets', 1),
|
|
35
|
-
el: $this.find("[waterfall-el='pagination']")[0],
|
|
36
|
-
enabled: parseAttr($this, 'pagination-enabled', null),
|
|
37
|
-
//formatFractionCurrent: null,
|
|
38
|
-
//formatFractionTotal: null,
|
|
39
|
-
hiddenClass: parseAttr(
|
|
40
|
-
$this,
|
|
41
|
-
'pagination-hidden-class',
|
|
42
|
-
'swiper-pagination-hidden',
|
|
43
|
-
),
|
|
44
|
-
hideOnClick: parseAttr($this, 'pagination-hide-on-click', true),
|
|
45
|
-
horizontalClass: parseAttr(
|
|
46
|
-
$this,
|
|
47
|
-
'pagination-horizontal-class',
|
|
48
|
-
'swiper-pagination-horizontal',
|
|
49
|
-
),
|
|
50
|
-
lockClass: parseAttr(
|
|
51
|
-
$this,
|
|
52
|
-
'pagination-lock-class',
|
|
53
|
-
'swiper-pagination-lock',
|
|
54
|
-
),
|
|
55
|
-
modifierClass: parseAttr(
|
|
56
|
-
$this,
|
|
57
|
-
'pagination-modifier-class',
|
|
58
|
-
'swiper-pagination-',
|
|
59
|
-
),
|
|
36
|
+
bulletActiveClass:
|
|
37
|
+
paginationBulletActive && paginationBullet ? getUniqueClasses(paginationBulletActive, paginationBullet) : "",
|
|
38
|
+
bulletClass: paginationBullet?.getAttribute("class") || "",
|
|
39
|
+
bulletElement: paginationBullet?.tagName?.toLowerCase() || "span",
|
|
40
|
+
clickable: parseAttr(element, ATTR_PAGINATION_CLICKABLE, false),
|
|
41
|
+
clickableClass: parseAttr(element, ATTR_PAGINATION_CLICKABLE_CLASS, "swiper-pagination-clickable"),
|
|
42
|
+
currentClass: parseAttr(element, ATTR_PAGINATION_CURRENT_CLASS, "swiper-pagination-current"),
|
|
43
|
+
dynamicBullets: parseAttr(element, ATTR_PAGINATION_DYNAMIC_BULLETS, "swiper-pagination-current"),
|
|
44
|
+
dynamicMainBullets: parseAttr(element, ATTR_PAGINATION_DYNAMIC_MAIN_BULLETS, 1),
|
|
45
|
+
el: paginationEl || null,
|
|
46
|
+
enabled: parseAttr(element, ATTR_PAGINATION_ENABLED, null),
|
|
47
|
+
hiddenClass: parseAttr(element, ATTR_PAGINATION_HIDDEN_CLASS, "swiper-pagination-hidden"),
|
|
48
|
+
hideOnClick: parseAttr(element, ATTR_PAGINATION_HIDE_ON_CLICK, true),
|
|
49
|
+
horizontalClass: parseAttr(element, ATTR_PAGINATION_HORIZONTAL_CLASS, "swiper-pagination-horizontal"),
|
|
50
|
+
lockClass: parseAttr(element, ATTR_NAVIGATION_LOCK_CLASS, "swiper-pagination-lock"),
|
|
51
|
+
modifierClass: parseAttr(element, ATTR_PAGINATION_MODIFIER_CLASS, "swiper-pagination-"),
|
|
60
52
|
paginationDisabledClass: parseAttr(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
element,
|
|
54
|
+
ATTR_PAGINATION_PAGINATION_DISABLED_CLASS,
|
|
55
|
+
"swiper-pagination-disabled",
|
|
64
56
|
),
|
|
65
57
|
progressbarFillClass: parseAttr(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
element,
|
|
59
|
+
ATTR_PAGINATION_PROGRESSBAR_FILL_CLASS,
|
|
60
|
+
"swiper-pagination-progressbar-fill",
|
|
69
61
|
),
|
|
70
62
|
progressbarOpposite: parseAttr(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
element,
|
|
64
|
+
ATTR_PAGINATION_PROGRESSBAR_OPPOSITE,
|
|
65
|
+
"swiper-pagination-progressbar-opposite",
|
|
74
66
|
),
|
|
75
67
|
renderBullet: customRenderBullet(),
|
|
76
|
-
|
|
77
|
-
//renderFraction: null,
|
|
78
|
-
//renderProgressBar: null,
|
|
79
|
-
totalClass: parseAttr(
|
|
80
|
-
$this,
|
|
81
|
-
'pagination-total-class',
|
|
82
|
-
'swiper-pagination-total',
|
|
83
|
-
),
|
|
68
|
+
totalClass: parseAttr(element, ATTR_PAGINATION_TOTAL_CLASS, "swiper-pagination-total"),
|
|
84
69
|
type: getPaginationType(),
|
|
85
|
-
verticalClass: parseAttr(
|
|
86
|
-
$this,
|
|
87
|
-
'pagination-vertical-class',
|
|
88
|
-
'swiper-pagination-vertical',
|
|
89
|
-
),
|
|
70
|
+
verticalClass: parseAttr(element, ATTR_PAGINATION_VERTICAL_CLASS, "swiper-pagination-vertical"),
|
|
90
71
|
};
|
|
91
72
|
|
|
92
|
-
// Custom pagination type rendering functions
|
|
93
73
|
function customRenderBullet() {
|
|
94
74
|
let renderBullet: RenderBulletFunction | null = null;
|
|
95
|
-
if (paginationType ===
|
|
96
|
-
renderBullet =
|
|
97
|
-
return `<span class="${className}">${index + 1}</span>`;
|
|
98
|
-
};
|
|
75
|
+
if (paginationType === "numberBullets") {
|
|
76
|
+
renderBullet = (index, className) => `<span class="${className}">${index + 1}</span>`;
|
|
99
77
|
}
|
|
100
|
-
if (paginationType ===
|
|
101
|
-
renderBullet =
|
|
102
|
-
return `<span class="${className}"></span>`;
|
|
103
|
-
};
|
|
78
|
+
if (paginationType === "bullets") {
|
|
79
|
+
renderBullet = (index, className) => `<span class="${className}"></span>`;
|
|
104
80
|
}
|
|
105
81
|
return renderBullet;
|
|
106
82
|
}
|
|
107
83
|
|
|
108
|
-
// Custom function to get extended pagination types
|
|
109
84
|
function getPaginationType() {
|
|
110
|
-
if (paginationType ===
|
|
111
|
-
|
|
112
|
-
if (paginationType ===
|
|
113
|
-
if (paginationType ===
|
|
114
|
-
|
|
115
|
-
else return 'bullets'; // default
|
|
85
|
+
if (paginationType === "numberBullets" || paginationType === "bullets") return "bullets";
|
|
86
|
+
if (paginationType === "fraction") return "fraction";
|
|
87
|
+
if (paginationType === "progressbar") return "progressbar";
|
|
88
|
+
if (paginationType === "custom") return "custom";
|
|
89
|
+
return "bullets"; // default
|
|
116
90
|
}
|
|
117
91
|
}
|
|
118
92
|
|
package/src/modules/playback.ts
CHANGED
|
@@ -1,34 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ATTR_AUTOPLAY,
|
|
3
|
+
ATTR_DELAY,
|
|
4
|
+
ATTR_DISABLE_ON_INTERACTION,
|
|
5
|
+
ATTR_FREE_MODE_ENABLED,
|
|
6
|
+
ATTR_FREE_MODE_MINIMUM_VELOCITY,
|
|
7
|
+
ATTR_FREE_MODE_MOMENTUM,
|
|
8
|
+
ATTR_FREE_MODE_MOMENTUM_BOUNCE,
|
|
9
|
+
ATTR_FREE_MODE_MOMENTUM_BOUNCE_RATIO,
|
|
10
|
+
ATTR_FREE_MODE_MOMENTUM_RATIO,
|
|
11
|
+
ATTR_FREE_MODE_MOMENTUM_VELOCITY_RATIO,
|
|
12
|
+
ATTR_FREE_MODE_STICKY,
|
|
13
|
+
ATTR_PAUSE_ON_MOUSE_ENTER,
|
|
14
|
+
ATTR_REVERSE_DIRECTION,
|
|
15
|
+
ATTR_SMOOTH_AUTOPLAY,
|
|
16
|
+
ATTR_STOP_ON_LAST_SLIDE,
|
|
17
|
+
} from "lib/attributes";
|
|
18
|
+
import { parseAttr } from "../util";
|
|
2
19
|
|
|
3
|
-
export function autoplayConfig(
|
|
4
|
-
const autoplayMode = parseAttr(
|
|
20
|
+
export function autoplayConfig(el: HTMLElement) {
|
|
21
|
+
const autoplayMode = parseAttr(el, ATTR_AUTOPLAY, false);
|
|
5
22
|
if (!autoplayMode) return null;
|
|
6
23
|
// Add CSS for Smooth Autoplay
|
|
7
|
-
$(
|
|
8
|
-
.find('.swiper-wrapper')
|
|
9
|
-
.css('transition-timing-function', 'linear');
|
|
24
|
+
$(`[${ATTR_SMOOTH_AUTOPLAY}='true']`).find(".swiper-wrapper").css("transition-timing-function", "linear");
|
|
10
25
|
return {
|
|
11
|
-
delay: parseAttr(
|
|
12
|
-
disableOnInteraction: parseAttr(
|
|
13
|
-
reverseDirection: parseAttr(
|
|
14
|
-
pauseOnMouseEnter: parseAttr(
|
|
15
|
-
stopOnLastSlide: parseAttr(
|
|
26
|
+
delay: parseAttr(el, ATTR_DELAY, 3000),
|
|
27
|
+
disableOnInteraction: parseAttr(el, ATTR_DISABLE_ON_INTERACTION, false), // documentation says default is true, doesn't appear to be correct
|
|
28
|
+
reverseDirection: parseAttr(el, ATTR_REVERSE_DIRECTION, false),
|
|
29
|
+
pauseOnMouseEnter: parseAttr(el, ATTR_PAUSE_ON_MOUSE_ENTER, false),
|
|
30
|
+
stopOnLastSlide: parseAttr(el, ATTR_STOP_ON_LAST_SLIDE, false),
|
|
16
31
|
};
|
|
17
32
|
}
|
|
18
33
|
|
|
19
|
-
export function freeModeConfig(
|
|
34
|
+
export function freeModeConfig(el: HTMLElement) {
|
|
20
35
|
return {
|
|
21
|
-
enabled: parseAttr(
|
|
22
|
-
minimumVelocity: parseAttr(
|
|
23
|
-
momentum: parseAttr(
|
|
24
|
-
momentumBounce: parseAttr(
|
|
25
|
-
momentumBounceRatio: parseAttr(
|
|
26
|
-
momentumRatio: parseAttr(
|
|
27
|
-
momentumVelocityRatio: parseAttr(
|
|
28
|
-
|
|
29
|
-
'free-mode-momentum-velocity-ratio',
|
|
30
|
-
1,
|
|
31
|
-
),
|
|
32
|
-
sticky: parseAttr($this, 'free-mode-sticky', false),
|
|
36
|
+
enabled: parseAttr(el, ATTR_FREE_MODE_ENABLED, false),
|
|
37
|
+
minimumVelocity: parseAttr(el, ATTR_FREE_MODE_MINIMUM_VELOCITY, 0.02),
|
|
38
|
+
momentum: parseAttr(el, ATTR_FREE_MODE_MOMENTUM, true),
|
|
39
|
+
momentumBounce: parseAttr(el, ATTR_FREE_MODE_MOMENTUM_BOUNCE, true),
|
|
40
|
+
momentumBounceRatio: parseAttr(el, ATTR_FREE_MODE_MOMENTUM_BOUNCE_RATIO, 1),
|
|
41
|
+
momentumRatio: parseAttr(el, ATTR_FREE_MODE_MOMENTUM_RATIO, 1),
|
|
42
|
+
momentumVelocityRatio: parseAttr(el, ATTR_FREE_MODE_MOMENTUM_VELOCITY_RATIO, 1),
|
|
43
|
+
sticky: parseAttr(el, ATTR_FREE_MODE_STICKY, false),
|
|
33
44
|
};
|
|
34
45
|
}
|
package/src/modules/scrollbar.ts
CHANGED
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ATTR_SCROLLBAR,
|
|
3
|
+
ATTR_SCROLLBAR_DRAG,
|
|
4
|
+
ATTR_SCROLLBAR_DRAG_SIZE,
|
|
5
|
+
ATTR_SCROLLBAR_DRAGGABLE,
|
|
6
|
+
ATTR_SCROLLBAR_ENABLED,
|
|
7
|
+
ATTR_SCROLLBAR_HIDE,
|
|
8
|
+
ATTR_SCROLLBAR_HORIZONTAL_CLASS,
|
|
9
|
+
ATTR_SCROLLBAR_LOCK_CLASS,
|
|
10
|
+
ATTR_SCROLLBAR_SCROLLBAR_DISABLED_CLASS,
|
|
11
|
+
ATTR_SCROLLBAR_SNAP_ON_RELEASE,
|
|
12
|
+
ATTR_SCROLLBAR_VERTICAL_CLASS,
|
|
13
|
+
ATTR_WATERFALL_ELEMENT,
|
|
14
|
+
} from "lib/attributes";
|
|
15
|
+
import { parseAttr } from "../util";
|
|
2
16
|
|
|
3
|
-
export function scrollbarConfig(
|
|
4
|
-
const
|
|
5
|
-
const
|
|
17
|
+
export function scrollbarConfig(element: HTMLElement) {
|
|
18
|
+
const scrollbar = element.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${ATTR_SCROLLBAR}]`);
|
|
19
|
+
const scrollbarDrag = scrollbar?.querySelector<HTMLElement>(`[${ATTR_WATERFALL_ELEMENT}=${ATTR_SCROLLBAR_DRAG}]`);
|
|
6
20
|
|
|
7
21
|
return {
|
|
8
|
-
dragClass:
|
|
9
|
-
dragSize: parseAttr(
|
|
10
|
-
draggable: parseAttr(
|
|
11
|
-
el:
|
|
12
|
-
enabled: parseAttr(
|
|
13
|
-
hide: parseAttr(
|
|
14
|
-
horizontalClass: parseAttr(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
),
|
|
19
|
-
lockClass: parseAttr(
|
|
20
|
-
$this,
|
|
21
|
-
'scrollbar-lock-class',
|
|
22
|
-
'swiper-scrollbar-lock',
|
|
23
|
-
),
|
|
24
|
-
scrollbarDisabledClass: parseAttr(
|
|
25
|
-
$this,
|
|
26
|
-
'scrollbar-disabled-class',
|
|
27
|
-
'swiper-scrollbar-disabled',
|
|
28
|
-
),
|
|
29
|
-
snapOnRelease: parseAttr($this, 'snap-on-release', true), // documentation says default is false, but is lying lmao
|
|
30
|
-
verticalClass: parseAttr(
|
|
31
|
-
$this,
|
|
32
|
-
'scrollbar-vertical-class',
|
|
33
|
-
'swiper-scrollbar-vertical',
|
|
34
|
-
),
|
|
22
|
+
dragClass: scrollbarDrag?.getAttribute("class") || "",
|
|
23
|
+
dragSize: parseAttr(element, ATTR_SCROLLBAR_DRAG_SIZE, "auto"),
|
|
24
|
+
draggable: parseAttr(element, ATTR_SCROLLBAR_DRAGGABLE, false),
|
|
25
|
+
el: scrollbar || null,
|
|
26
|
+
enabled: parseAttr(element, ATTR_SCROLLBAR_ENABLED, null),
|
|
27
|
+
hide: parseAttr(element, ATTR_SCROLLBAR_HIDE, true),
|
|
28
|
+
horizontalClass: parseAttr(element, ATTR_SCROLLBAR_HORIZONTAL_CLASS, "swiper-scrollbar-horizontal"),
|
|
29
|
+
lockClass: parseAttr(element, ATTR_SCROLLBAR_LOCK_CLASS, "swiper-scrollbar-lock"),
|
|
30
|
+
scrollbarDisabledClass: parseAttr(element, ATTR_SCROLLBAR_SCROLLBAR_DISABLED_CLASS, "swiper-scrollbar-disabled"),
|
|
31
|
+
snapOnRelease: parseAttr(element, ATTR_SCROLLBAR_SNAP_ON_RELEASE, true), // doc says false but actually true
|
|
32
|
+
verticalClass: parseAttr(element, ATTR_SCROLLBAR_VERTICAL_CLASS, "swiper-scrollbar-vertical"),
|
|
35
33
|
};
|
|
36
34
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { ATTR_SLIDE_COUNT, ATTR_WATERFALL_ELEMENT } from "lib/attributes";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Creates a Slide Count element that displays the current slide number.
|
|
3
5
|
*/
|
|
4
6
|
export function initSlideCount() {
|
|
5
|
-
document.querySelectorAll(
|
|
6
|
-
swiperWrapper.querySelectorAll(
|
|
7
|
-
const countEl = slide.querySelector(
|
|
7
|
+
document.querySelectorAll(".swiper-wrapper").forEach((swiperWrapper) => {
|
|
8
|
+
swiperWrapper.querySelectorAll(".swiper-slide").forEach((slide, index) => {
|
|
9
|
+
const countEl = slide.querySelector(`[${ATTR_WATERFALL_ELEMENT}=${ATTR_SLIDE_COUNT}]`);
|
|
8
10
|
if (countEl) {
|
|
9
11
|
countEl.textContent = (index + 1).toString();
|
|
10
12
|
}
|
package/src/modules/thumbs.ts
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
|
-
import { ThumbsOptions } from
|
|
2
|
-
import { parseAttr, parseBoolean, parseNumber, parseString } from
|
|
3
|
-
import { Waterfall } from
|
|
1
|
+
import { ThumbsOptions } from "swiper/types";
|
|
2
|
+
import { parseAttr, parseBoolean, parseNumber, parseString } from "../util";
|
|
3
|
+
import { Waterfall } from "types/waterfall";
|
|
4
|
+
import {
|
|
5
|
+
ATTR_THUMBS_AUTO_SCROLL_OFFSET,
|
|
6
|
+
ATTR_THUMBS_CONTAINER_CLASS,
|
|
7
|
+
ATTR_THUMBS_MULTIPLE_ACTIVE_THUMBS,
|
|
8
|
+
ATTR_THUMBS_NAME,
|
|
9
|
+
ATTR_THUMBS_SLIDE_THUMB_ACTIVE_CLASS,
|
|
10
|
+
} from "lib/attributes";
|
|
4
11
|
|
|
5
|
-
function getThumbsSwiper(
|
|
6
|
-
el
|
|
7
|
-
sliders: Waterfall[],
|
|
8
|
-
): Waterfall | null {
|
|
9
|
-
const sliderName = parseAttr(el, 'thumbs-name', null);
|
|
12
|
+
function getThumbsSwiper(el: HTMLElement, sliders: Waterfall[]): Waterfall | null {
|
|
13
|
+
const sliderName = parseAttr(el, ATTR_THUMBS_NAME, null);
|
|
10
14
|
if (sliderName === null) return null;
|
|
11
15
|
|
|
12
|
-
const foundSlider = sliders.find(
|
|
13
|
-
(slider: Waterfall) => slider.name === sliderName,
|
|
14
|
-
);
|
|
16
|
+
const foundSlider = sliders.find((slider: Waterfall) => slider.name === sliderName);
|
|
15
17
|
|
|
16
18
|
if (foundSlider) return foundSlider;
|
|
17
|
-
console.log(
|
|
19
|
+
console.log("A matching thumbs waterfall was not found for ", sliderName);
|
|
18
20
|
return null; // Return null if no match is found
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
export function thumbsConfig(el:
|
|
23
|
+
export function thumbsConfig(el: HTMLElement, swipers: Waterfall[]) {
|
|
22
24
|
const waterfall = getThumbsSwiper(el, swipers);
|
|
23
25
|
if (!waterfall) return;
|
|
24
26
|
|
|
25
27
|
let config: ThumbsOptions = {
|
|
26
|
-
autoScrollOffset: parseNumber(el,
|
|
27
|
-
multipleActiveThumbs: parseBoolean(el,
|
|
28
|
-
slideThumbActiveClass: parseString(
|
|
29
|
-
el,
|
|
30
|
-
'slide-thumb-active-class',
|
|
31
|
-
'swiper-slide-thumb-active',
|
|
32
|
-
),
|
|
28
|
+
autoScrollOffset: parseNumber(el, ATTR_THUMBS_AUTO_SCROLL_OFFSET, 0),
|
|
29
|
+
multipleActiveThumbs: parseBoolean(el, ATTR_THUMBS_MULTIPLE_ACTIVE_THUMBS, false),
|
|
30
|
+
slideThumbActiveClass: parseString(el, ATTR_THUMBS_SLIDE_THUMB_ACTIVE_CLASS, "swiper-slide-thumb-active"),
|
|
33
31
|
swiper: waterfall.swiper,
|
|
34
|
-
thumbsContainerClass: parseString(
|
|
35
|
-
el,
|
|
36
|
-
'thumbs-container-class',
|
|
37
|
-
'swiper-thumbs',
|
|
38
|
-
),
|
|
32
|
+
thumbsContainerClass: parseString(el, ATTR_THUMBS_CONTAINER_CLASS, "swiper-thumbs"),
|
|
39
33
|
};
|
|
40
34
|
return config;
|
|
41
35
|
}
|
package/src/modules/zoom.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ATTR_ZOOM_CONTAINER_CLASS,
|
|
3
|
+
ATTR_ZOOM_LIMIT_TO_ORIGINAL_SIZE,
|
|
4
|
+
ATTR_ZOOM_MAX_RATIO,
|
|
5
|
+
ATTR_ZOOM_MIN_RATIO,
|
|
6
|
+
ATTR_ZOOM_PAN_ON_MOUSE_MOVE,
|
|
7
|
+
ATTR_ZOOM_TOGGLE,
|
|
8
|
+
ATTR_ZOOMED_SLIDE_CLASS,
|
|
9
|
+
} from "lib/attributes";
|
|
10
|
+
import { parseAttr } from "../util";
|
|
2
11
|
|
|
3
|
-
export function zoomConfig(
|
|
12
|
+
export function zoomConfig(el: HTMLElement) {
|
|
4
13
|
return {
|
|
5
|
-
containerClass: parseAttr(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
),
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
minRatio: parseAttr($el, 'zoom-min-ratio', 1),
|
|
13
|
-
panOnMouseMove: parseAttr($el, 'zoom-pan-on-mouse-move', false),
|
|
14
|
-
toggle: parseAttr($el, 'zoom-toggle', true),
|
|
15
|
-
zoomedSlideClass: parseAttr(
|
|
16
|
-
$el,
|
|
17
|
-
'zoomed-slide-class',
|
|
18
|
-
'swiper-slide-zoomed',
|
|
19
|
-
),
|
|
14
|
+
containerClass: parseAttr(el, ATTR_ZOOM_CONTAINER_CLASS, "swiper-zoom-container"),
|
|
15
|
+
limitToOriginalSize: parseAttr(el, ATTR_ZOOM_LIMIT_TO_ORIGINAL_SIZE, false),
|
|
16
|
+
maxRatio: parseAttr(el, ATTR_ZOOM_MAX_RATIO, 3),
|
|
17
|
+
minRatio: parseAttr(el, ATTR_ZOOM_MIN_RATIO, 1),
|
|
18
|
+
panOnMouseMove: parseAttr(el, ATTR_ZOOM_PAN_ON_MOUSE_MOVE, false),
|
|
19
|
+
toggle: parseAttr(el, ATTR_ZOOM_TOGGLE, true),
|
|
20
|
+
zoomedSlideClass: parseAttr(el, ATTR_ZOOMED_SLIDE_CLASS, "swiper-slide-zoomed"),
|
|
20
21
|
};
|
|
21
22
|
}
|
package/src/util.ts
CHANGED
|
@@ -1,147 +1,102 @@
|
|
|
1
|
-
import Swiper from
|
|
2
|
-
import { Waterfall } from
|
|
1
|
+
import Swiper from "swiper";
|
|
2
|
+
import { Waterfall } from "types/waterfall";
|
|
3
3
|
|
|
4
4
|
export function printDebug(debug: boolean, str: string, el: any) {
|
|
5
5
|
if (!debug) return;
|
|
6
|
-
console.log(str
|
|
6
|
+
console.log(`${str}:`, el);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
) {
|
|
13
|
-
if (!targetElement.length) return ''; // If no element, return an empty string
|
|
9
|
+
// ✅ Get unique classes without jQuery
|
|
10
|
+
export function getUniqueClasses(targetElement: HTMLElement, comparisonElement: HTMLElement): string {
|
|
11
|
+
if (!targetElement) return "";
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const targetClasses = Array.from(targetElement.classList);
|
|
14
|
+
const comparisonClasses = Array.from(comparisonElement.classList);
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
);
|
|
21
|
-
// Get the class attribute, split into an array, filter out the classToRemove, and join back into a string
|
|
22
|
-
return filtered.join(' '); // Join the remaining classes into a string
|
|
16
|
+
const filtered = targetClasses.filter((className) => className && !comparisonClasses.includes(className));
|
|
17
|
+
|
|
18
|
+
return filtered.join(" ");
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
attrName
|
|
28
|
-
defaultValue
|
|
29
|
-
) {
|
|
30
|
-
const attrValue = $(el).attr(attrName)?.trim();
|
|
31
|
-
if (!attrValue) return undefined;
|
|
32
|
-
// Nullify the attribute if it matches the default value from SwiperJS
|
|
33
|
-
if (attrValue === defaultValue) return undefined;
|
|
21
|
+
// ✅ Parse attribute as string (ignoring default value)
|
|
22
|
+
export function parseString(el: HTMLElement, attrName: string, defaultValue: string): string | undefined {
|
|
23
|
+
const attrValue = el.getAttribute(attrName)?.trim();
|
|
24
|
+
if (!attrValue || attrValue === defaultValue) return undefined;
|
|
34
25
|
return attrValue;
|
|
35
26
|
}
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
attrName
|
|
40
|
-
defaultValue: number,
|
|
41
|
-
): number | undefined {
|
|
42
|
-
const attrValue = $(el).attr(attrName)?.trim();
|
|
28
|
+
// ✅ Parse attribute as number
|
|
29
|
+
export function parseNumber(el: HTMLElement, attrName: string, defaultValue: number): number | undefined {
|
|
30
|
+
const attrValue = el.getAttribute(attrName)?.trim();
|
|
43
31
|
if (!attrValue) return undefined;
|
|
44
32
|
|
|
45
33
|
const parsedValue = Number(attrValue);
|
|
46
|
-
if (isNaN(parsedValue)) return undefined;
|
|
34
|
+
if (isNaN(parsedValue) || parsedValue === defaultValue) return undefined;
|
|
47
35
|
|
|
48
|
-
return parsedValue
|
|
36
|
+
return parsedValue;
|
|
49
37
|
}
|
|
50
38
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
attrName
|
|
54
|
-
defaultValue: boolean,
|
|
55
|
-
): boolean | undefined {
|
|
56
|
-
const attrValue = $(el).attr(attrName)?.trim()?.toLowerCase();
|
|
39
|
+
// ✅ Parse attribute as boolean
|
|
40
|
+
export function parseBoolean(el: HTMLElement, attrName: string, defaultValue: boolean): boolean | undefined {
|
|
41
|
+
const attrValue = el.getAttribute(attrName)?.trim()?.toLowerCase();
|
|
57
42
|
if (!attrValue) return undefined;
|
|
58
43
|
|
|
59
|
-
if (attrValue ===
|
|
60
|
-
if (attrValue ===
|
|
44
|
+
if (attrValue === "true") return defaultValue === true ? undefined : true;
|
|
45
|
+
if (attrValue === "false") return defaultValue === false ? undefined : false;
|
|
61
46
|
|
|
62
|
-
return
|
|
47
|
+
return undefined;
|
|
63
48
|
}
|
|
64
49
|
|
|
50
|
+
// ✅ Generic attribute parser
|
|
65
51
|
export function parseAttr(
|
|
66
|
-
el:
|
|
52
|
+
el: HTMLElement,
|
|
67
53
|
attrName: string,
|
|
68
54
|
defaultValue: string | number | boolean | null,
|
|
69
55
|
): string | number | boolean | null {
|
|
70
|
-
const attrValue =
|
|
56
|
+
const attrValue = el.getAttribute(attrName);
|
|
71
57
|
if (!attrValue) return null;
|
|
72
|
-
|
|
58
|
+
|
|
73
59
|
const trimmedInput = attrValue.trim();
|
|
74
60
|
|
|
75
|
-
//
|
|
61
|
+
// Number check
|
|
76
62
|
if (!isNaN(Number(trimmedInput))) {
|
|
77
63
|
const parsedNumber = parseFloat(trimmedInput);
|
|
78
|
-
|
|
79
|
-
return null; // Return null if it matches the default value
|
|
80
|
-
}
|
|
81
|
-
return parsedNumber; // Return the parsed number
|
|
64
|
+
return parsedNumber === defaultValue ? null : parsedNumber;
|
|
82
65
|
}
|
|
83
66
|
|
|
84
|
-
//
|
|
85
|
-
if (trimmedInput.toLowerCase() ===
|
|
86
|
-
|
|
87
|
-
return null; // Return null if it matches the default value
|
|
88
|
-
}
|
|
89
|
-
return true;
|
|
90
|
-
} else if (trimmedInput.toLowerCase() === 'false') {
|
|
91
|
-
if (defaultValue === false) {
|
|
92
|
-
return null; // Return null if it matches the default value
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
67
|
+
// Boolean check
|
|
68
|
+
if (trimmedInput.toLowerCase() === "true") return defaultValue === true ? null : true;
|
|
69
|
+
if (trimmedInput.toLowerCase() === "false") return defaultValue === false ? null : false;
|
|
96
70
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
71
|
+
// String match check
|
|
72
|
+
return trimmedInput === String(defaultValue) ? null : trimmedInput;
|
|
73
|
+
}
|
|
101
74
|
|
|
102
|
-
|
|
103
|
-
return
|
|
75
|
+
function isHTMLElement(value: unknown): value is HTMLElement {
|
|
76
|
+
return typeof HTMLElement !== "undefined" && value instanceof HTMLElement;
|
|
104
77
|
}
|
|
105
78
|
|
|
106
|
-
export function removeNullOrUndefinedKeys(obj:
|
|
107
|
-
if (typeof obj !==
|
|
108
|
-
return obj; // Return non-objects or null as is
|
|
109
|
-
}
|
|
79
|
+
export function removeNullOrUndefinedKeys<T extends Record<string, any>>(obj: T): T {
|
|
80
|
+
if (typeof obj !== "object" || obj === null) return obj;
|
|
110
81
|
|
|
111
|
-
// Iterate over the keys in the object
|
|
112
82
|
for (const key in obj) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
// Recursively handle nested objects
|
|
120
|
-
removeNullOrUndefinedKeys(obj[key]);
|
|
121
|
-
// Remove empty objects after recursion
|
|
122
|
-
if (Object.keys(obj[key]).length === 0) {
|
|
123
|
-
delete obj[key];
|
|
124
|
-
}
|
|
83
|
+
const value = obj[key];
|
|
84
|
+
if (value === null || value === undefined) {
|
|
85
|
+
delete obj[key];
|
|
86
|
+
} else if (typeof value === "object" && value !== null && !isHTMLElement(value)) {
|
|
87
|
+
removeNullOrUndefinedKeys(value as Record<string, any>);
|
|
88
|
+
if (Object.keys(value).length === 0) delete obj[key];
|
|
125
89
|
}
|
|
126
90
|
}
|
|
127
91
|
|
|
128
92
|
return obj;
|
|
129
93
|
}
|
|
130
94
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return false;
|
|
139
|
-
});
|
|
140
|
-
if (waterfall) swipers.push(waterfall?.swiper);
|
|
141
|
-
});
|
|
142
|
-
return swipers;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function splitByUnderscores(str: string) {
|
|
146
|
-
return str.split('_');
|
|
95
|
+
// ✅ Get swipers by name
|
|
96
|
+
export function getSwipersByName(waterfalls: Waterfall[], selector: string): Swiper[] {
|
|
97
|
+
return selector.split("_").reduce<Swiper[]>((swipers, name) => {
|
|
98
|
+
const waterfall = waterfalls.find((w) => w.name === name);
|
|
99
|
+
if (waterfall) swipers.push(waterfall.swiper);
|
|
100
|
+
return swipers;
|
|
101
|
+
}, []);
|
|
147
102
|
}
|