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.
@@ -1,118 +1,92 @@
1
- import { getUniqueClasses, parseAttr } from '../util';
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($this: JQuery<HTMLElement>) {
4
- let paginationType = parseAttr($this, 'pagination-type', '');
26
+ export function paginationConfig(element: HTMLElement) {
27
+ const paginationType = parseAttr(element, ATTR_PAGINATION_TYPE, "");
5
28
 
6
- let $paginationBullet = $this.find("[waterfall-el='pagination-bullet']");
7
- let paginationBulletActive = $this.find(
8
- "[waterfall-el='pagination-bullet-active']",
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: getUniqueClasses(
13
- paginationBulletActive,
14
- $paginationBullet,
15
- ),
16
- bulletClass: $paginationBullet.attr('class'),
17
- bulletElement: $paginationBullet.prop('tagName')?.toLowerCase() || 'span', //ISSUE HERE
18
- clickable: parseAttr($this, 'pagination-clickable', false),
19
- clickableClass: parseAttr(
20
- $this,
21
- 'pagination-clickable-class',
22
- 'swiper-pagination-clickable',
23
- ),
24
- currentClass: parseAttr(
25
- $this,
26
- 'pagination-current-class',
27
- 'swiper-pagination-current',
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
- $this,
62
- 'pagination-disabled-class',
63
- 'swiper-pagination-disabled',
53
+ element,
54
+ ATTR_PAGINATION_PAGINATION_DISABLED_CLASS,
55
+ "swiper-pagination-disabled",
64
56
  ),
65
57
  progressbarFillClass: parseAttr(
66
- $this,
67
- 'pagination-progressbar-fill-class',
68
- 'swiper-pagination-progressbar-fill',
58
+ element,
59
+ ATTR_PAGINATION_PROGRESSBAR_FILL_CLASS,
60
+ "swiper-pagination-progressbar-fill",
69
61
  ),
70
62
  progressbarOpposite: parseAttr(
71
- $this,
72
- 'pagination-progressbar-opposite',
73
- 'swiper-pagination-progressbar-opposite',
63
+ element,
64
+ ATTR_PAGINATION_PROGRESSBAR_OPPOSITE,
65
+ "swiper-pagination-progressbar-opposite",
74
66
  ),
75
67
  renderBullet: customRenderBullet(),
76
- //renderCustom: null,
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 === 'numberBullets') {
96
- renderBullet = function (index, className) {
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 === 'bullets') {
101
- renderBullet = function (index, className) {
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 === 'numberBullets' || paginationType === 'bullets')
111
- return 'bullets';
112
- if (paginationType === 'fraction') return 'fraction';
113
- if (paginationType === 'progressbar') return 'progressbar';
114
- if (paginationType === 'custom') return 'custom';
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
 
@@ -1,34 +1,45 @@
1
- import { parseAttr } from '../util';
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($this: JQuery<HTMLElement>) {
4
- const autoplayMode = parseAttr($this, 'autoplay-mode', false);
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
- $("[smooth-autoplay='true']")
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($this, 'delay', 3000),
12
- disableOnInteraction: parseAttr($this, 'disable-on-interaction', false), // documentation says default is true, doesn't appear to be correct
13
- reverseDirection: parseAttr($this, 'reverse-direction', false),
14
- pauseOnMouseEnter: parseAttr($this, 'pause-on-mouse-enter', false),
15
- stopOnLastSlide: parseAttr($this, 'stop-on-last-slide', false),
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($this: JQuery<HTMLElement>) {
34
+ export function freeModeConfig(el: HTMLElement) {
20
35
  return {
21
- enabled: parseAttr($this, 'free-mode-enabled', false),
22
- minimumVelocity: parseAttr($this, 'free-mode-minimum-velocity', 0.02),
23
- momentum: parseAttr($this, 'free-mode-momentum', true),
24
- momentumBounce: parseAttr($this, 'free-mode-momentum-bounce', true),
25
- momentumBounceRatio: parseAttr($this, 'free-mode-momentum-bounce-ratio', 1),
26
- momentumRatio: parseAttr($this, 'free-mode-momentum-ratio', 1),
27
- momentumVelocityRatio: parseAttr(
28
- $this,
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
  }
@@ -1,36 +1,34 @@
1
- import { parseAttr } from '../util';
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($this: JQuery<HTMLElement>) {
4
- const $scrollbar = $this.find("[waterfall-el='scrollbar']");
5
- const $scrollbarDrag = $($scrollbar).find("[waterfall-el='scrollbar-drag']");
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: $scrollbarDrag.attr('class'),
9
- dragSize: parseAttr($this, 'scrollbar-drag-size', 'auto'),
10
- draggable: parseAttr($this, 'scrollbar-draggable', false),
11
- el: $scrollbar[0],
12
- enabled: parseAttr($this, 'scrollbar-enabled', null),
13
- hide: parseAttr($this, 'scrollbar-hide', true),
14
- horizontalClass: parseAttr(
15
- $this,
16
- 'scrollbar-horizontal-class',
17
- 'swiper-scrollbar-horizontal',
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('.swiper-wrapper').forEach((swiperWrapper) => {
6
- swiperWrapper.querySelectorAll('.swiper-slide').forEach((slide, index) => {
7
- const countEl = slide.querySelector('[waterfall-el="slide-count"]');
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
  }
@@ -1,41 +1,35 @@
1
- import { ThumbsOptions } from 'swiper/types';
2
- import { parseAttr, parseBoolean, parseNumber, parseString } from '../util';
3
- import { Waterfall } from 'types/waterfall';
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: JQuery<HTMLElement>,
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('A matching thumbs waterfall was not found for ', sliderName);
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: JQuery<HTMLElement>, swipers: Waterfall[]) {
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, 'auto-scroll-offset', 0),
27
- multipleActiveThumbs: parseBoolean(el, 'multiple-active-thumbs', false),
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
  }
@@ -1,21 +1,22 @@
1
- import { parseAttr } from '../util';
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($el: JQuery<HTMLElement>) {
12
+ export function zoomConfig(el: HTMLElement) {
4
13
  return {
5
- containerClass: parseAttr(
6
- $el,
7
- 'zoom-container-class',
8
- 'swiper-zoom-container',
9
- ),
10
- limitToOriginalSize: parseAttr($el, 'zoom-limit-to-original-size', false),
11
- maxRatio: parseAttr($el, 'zoom-max-ratio', 3),
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 'swiper';
2
- import { Waterfall } from 'types/waterfall';
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, ': ', el);
6
+ console.log(`${str}:`, el);
7
7
  }
8
8
 
9
- export function getUniqueClasses(
10
- targetElement: JQuery<HTMLElement>,
11
- comparisonElement: JQuery<HTMLElement>,
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
- let targetClasses = (targetElement.attr('class') || '').split(/\s+/);
16
- let comparisonClasses = (comparisonElement.attr('class') || '').split(/\s+/);
13
+ const targetClasses = Array.from(targetElement.classList);
14
+ const comparisonClasses = Array.from(comparisonElement.classList);
17
15
 
18
- let filtered = targetClasses.filter(
19
- (className) => className && !comparisonClasses.includes(className),
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
- export function parseString(
26
- el: JQuery<HTMLElement>,
27
- attrName: string,
28
- defaultValue: string,
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
- export function parseNumber(
38
- el: JQuery<HTMLElement>,
39
- attrName: string,
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 === defaultValue ? undefined : parsedValue;
36
+ return parsedValue;
49
37
  }
50
38
 
51
- export function parseBoolean(
52
- el: JQuery<HTMLElement>,
53
- attrName: string,
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 === 'true') return true;
60
- if (attrValue === 'false') return false;
44
+ if (attrValue === "true") return defaultValue === true ? undefined : true;
45
+ if (attrValue === "false") return defaultValue === false ? undefined : false;
61
46
 
62
- return attrValue === defaultValue.toString() ? undefined : undefined;
47
+ return undefined;
63
48
  }
64
49
 
50
+ // ✅ Generic attribute parser
65
51
  export function parseAttr(
66
- el: JQuery<HTMLElement>,
52
+ el: HTMLElement,
67
53
  attrName: string,
68
54
  defaultValue: string | number | boolean | null,
69
55
  ): string | number | boolean | null {
70
- const attrValue = $(el).attr(attrName);
56
+ const attrValue = el.getAttribute(attrName);
71
57
  if (!attrValue) return null;
72
- // Trim the input to avoid issues with leading/trailing spaces
58
+
73
59
  const trimmedInput = attrValue.trim();
74
60
 
75
- // Check if input is a number
61
+ // Number check
76
62
  if (!isNaN(Number(trimmedInput))) {
77
63
  const parsedNumber = parseFloat(trimmedInput);
78
- if (parsedNumber === defaultValue) {
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
- // Check if input is a boolean
85
- if (trimmedInput.toLowerCase() === 'true') {
86
- if (defaultValue === true) {
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
- // Return null if the input matches the default value (as a string)
98
- if (trimmedInput === String(defaultValue)) {
99
- return null;
100
- }
71
+ // String match check
72
+ return trimmedInput === String(defaultValue) ? null : trimmedInput;
73
+ }
101
74
 
102
- // Return the input as a string
103
- return trimmedInput;
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: any) {
107
- if (typeof obj !== 'object' || obj === null) {
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
- if (obj[key] === null || obj[key] === undefined) {
114
- delete obj[key]; // ✅ Remove `null` or `undefined` keys
115
- } else if (
116
- typeof obj[key] === 'object' &&
117
- !(obj[key] instanceof HTMLElement)
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
- export function getSwipersByName(waterfalls: Waterfall[], selector: string) {
132
- const strArr = splitByUnderscores(selector);
133
- const swipers: Swiper[] = [];
134
-
135
- strArr.forEach((str) => {
136
- const waterfall = waterfalls.find((w) => {
137
- if (w.name === str) return true;
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
  }