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/src/waterfall.ts CHANGED
@@ -18,99 +18,122 @@ import { controllerConfig } from "./modules/controller";
18
18
  import { SwiperOptions } from "swiper/types";
19
19
  import { accessibilityConfig } from "./modules/accessibility";
20
20
  import { addSlides } from "./modules/manipulation";
21
+ import { zoomConfig } from "./modules/zoom";
22
+
23
+ import {
24
+ ATTR_WATERFALL_PRELOAD,
25
+ ATTR_WATERFALL,
26
+ ATTR_WATERFALL_POSTLOAD,
27
+ ATTR_DEBUG_MODE,
28
+ ATTR_ADVANCED_DEBUG_MODE,
29
+ ATTR_PLAYBACK_MODE,
30
+ ATTR_THUMBS,
31
+ } from "./lib/attributes";
21
32
 
22
33
  console.log(`🚿 Hello from Wellflow Waterfall v${APP_VERSION}`);
23
34
 
24
35
  const waterfalls: Waterfall[] = [];
25
36
  window.waterfalls = waterfalls;
26
37
 
38
+ export * from "./lib/attributes";
39
+
40
+ /**
41
+ * Utility: Runs initConfig for a NodeList
42
+ */
43
+ function initAll(selector: string) {
44
+ document.querySelectorAll(selector).forEach((el, index) => {
45
+ initConfig(el as HTMLElement, index);
46
+ });
47
+ }
48
+
27
49
  // Initialize Thumb Sliders first
28
- $('[waterfall][waterfall-preload="true"]').each((index, el) => initConfig(el, index));
50
+ initAll(`[${ATTR_WATERFALL}][${ATTR_WATERFALL_PRELOAD}="true"]`);
29
51
 
30
52
  // Initialize all other sliders
31
- $("[waterfall]")
32
- .not('[waterfall-preload="true"]')
33
- .not('[waterfall-postload="true"]')
34
- .each((index, el) => initConfig(el, index));
53
+ document.querySelectorAll(`[${ATTR_WATERFALL}]`).forEach((el, index) => {
54
+ if (el.getAttribute(ATTR_WATERFALL_PRELOAD) === "true" || el.getAttribute(ATTR_WATERFALL_POSTLOAD) === "true") return;
55
+
56
+ initConfig(el as HTMLElement, index);
57
+ });
35
58
 
36
- $('[waterfall][waterfall-postload="true"]').each((index, el) => initConfig(el, index));
59
+ // Initialize Postload sliders
60
+ initAll(`[${ATTR_WATERFALL}][${ATTR_WATERFALL_POSTLOAD}="true"]`);
37
61
 
38
62
  function initConfig(el: HTMLElement, index: number) {
39
63
  {
40
- const $this = $(el);
41
-
42
- const name = parseString($this, "waterfall", `Swiper ${index}`);
64
+ const name = parseString(el, ATTR_WATERFALL, `Swiper ${index}`);
43
65
  if (!name) return;
44
66
 
45
- const debug = Boolean(parseAttr($this, "debug-mode", false) || false);
46
- const debugAdvanced = Boolean(parseAttr($this, "advanced-debug-mode", false) || false);
67
+ const debug = Boolean(parseAttr(el, ATTR_DEBUG_MODE, false) || false);
68
+ const debugAdvanced = Boolean(parseAttr(el, ATTR_ADVANCED_DEBUG_MODE, false) || false);
47
69
  console.log(`Initializing Waterfall: ${name} ${debug ? `[${debugAdvanced ? "ADVANCED " : ""}DEBUG]` : ""}`);
48
70
 
49
71
  // GENERAL CONFIG
50
- const swiperConfig: any = generalConfig($this);
72
+ const swiperConfig: any = generalConfig(el);
51
73
 
52
74
  // BREAKPOINTS
53
- swiperConfig.breakpoints = breakpointsConfig($this);
75
+ swiperConfig.breakpoints = breakpointsConfig(el);
54
76
 
55
77
  // PLAYBACK
56
- const playbackMode = parseAttr($this, "playback-mode", "none");
78
+ const playbackMode = parseAttr(el, ATTR_PLAYBACK_MODE, "none");
57
79
  if (playbackMode === "loop") swiperConfig.loop = true;
58
80
  if (playbackMode === "rewind") swiperConfig.rewind = true;
59
81
  if (playbackMode === "none") {
60
82
  swiperConfig.loop = false;
61
83
  swiperConfig.rewind = false;
62
84
  }
63
- swiperConfig.autoplay = autoplayConfig($this);
85
+ swiperConfig.autoplay = autoplayConfig(el);
64
86
 
65
87
  // NAVIGATION
66
- swiperConfig.navigation = navigationConfig($this, name);
88
+ swiperConfig.navigation = navigationConfig(el, name);
67
89
 
68
90
  // PAGINATION
69
- let pagination = $this.find("[waterfall-el='pagination-bullet']").length;
70
- if (pagination) swiperConfig.pagination = paginationConfig($this);
91
+ const paginationEl = el.querySelector(`[waterfall-el='pagination-bullet']`);
92
+ if (paginationEl) swiperConfig.pagination = paginationConfig(el);
71
93
 
72
94
  // SCROLLBAR
73
- const $scrollbar = $this.find("[waterfall-el='scrollbar']");
74
- if ($scrollbar) swiperConfig.scrollbar = scrollbarConfig($this);
95
+ const scrollbarEl = el.querySelector(`[waterfall-el='scrollbar']`);
96
+ if (scrollbarEl) swiperConfig.scrollbar = scrollbarConfig(el);
75
97
 
76
98
  // EFFECT
77
- swiperConfig.fadeEffect = fadeConfig($this);
78
- swiperConfig.coverflowEffect = coverflowEffect($this);
79
- swiperConfig.flipEffect = flipEffect($this);
80
- swiperConfig.cardsEffect = cardsEffect($this);
81
- swiperConfig.cubeEffect = cubeEffect($this);
99
+ swiperConfig.fadeEffect = fadeConfig(el);
100
+ swiperConfig.coverflowEffect = coverflowEffect(el);
101
+ swiperConfig.flipEffect = flipEffect(el);
102
+ swiperConfig.cardsEffect = cardsEffect(el);
103
+ swiperConfig.cubeEffect = cubeEffect(el);
82
104
 
83
105
  // FREE MODE
84
- swiperConfig.freeMode = freeModeConfig($this);
106
+ swiperConfig.freeMode = freeModeConfig(el);
85
107
 
86
108
  // GRID
87
- swiperConfig.grid = gridConfig($this);
109
+ swiperConfig.grid = gridConfig(el);
88
110
 
89
111
  // THUMBS
90
- const isThumbs = parseAttr($this, "waterfall-thumbs", null) === true;
91
- if (!isThumbs) swiperConfig.thumbs = thumbsConfig($this, waterfalls);
112
+ const isThumbs = parseAttr(el, ATTR_THUMBS, null) === true;
113
+ if (!isThumbs) swiperConfig.thumbs = thumbsConfig(el, waterfalls);
92
114
 
93
115
  // ZOOM - NOT IMPLEMENTED
116
+ swiperConfig.zoom = zoomConfig(el);
94
117
 
95
118
  // KEYBOARD
96
- swiperConfig.keyboard = keyboardConfig($this);
119
+ swiperConfig.keyboard = keyboardConfig(el);
97
120
 
98
121
  // MOUSE
99
- swiperConfig.mousewheel = mouseConfig($this);
122
+ swiperConfig.mousewheel = mouseConfig(el);
100
123
 
101
124
  // VIRTUAL SLIDES - NOT IMPLEMENTED
102
125
 
103
126
  // HASH NAVIGATION
104
- swiperConfig.hashNavigation = hashNavigationConfig($this);
127
+ swiperConfig.hashNavigation = hashNavigationConfig(el);
105
128
 
106
129
  // HISTORY NAVIGATION
107
- swiperConfig.history = historyNavigationConfig($this);
130
+ swiperConfig.history = historyNavigationConfig(el);
108
131
 
109
132
  // CONTROLLER
110
- swiperConfig.controller = controllerConfig($this, waterfalls);
133
+ swiperConfig.controller = controllerConfig(el, waterfalls);
111
134
 
112
135
  // A11Y
113
- swiperConfig.a11y = accessibilityConfig($this);
136
+ swiperConfig.a11y = accessibilityConfig(el);
114
137
 
115
138
  // Clean up the config and debug
116
139
  if (debugAdvanced) printDebug(debug, "CONFIG (UNCLEANED)", swiperConfig);
@@ -118,19 +141,15 @@ function initConfig(el: HTMLElement, index: number) {
118
141
  printDebug(debug, "CONFIG", config);
119
142
 
120
143
  // Initialize swiper
121
- const $swiperEl = $this.find(".swiper");
122
- const $slides = $swiperEl.find(".swiper-slide");
123
-
124
- // Check if there are slides, return if none are found
125
- if ($slides.length === 0) {
144
+ const swiperEl = el.querySelector(".swiper");
145
+ const slides = swiperEl?.querySelectorAll(".swiper-slide") || [];
146
+ if (slides.length === 0) {
126
147
  console.warn(`Skipping "${name}": no .swiper-slide elements found.`);
127
148
  return;
128
149
  }
129
-
130
- const swiper = new Swiper($swiperEl[0], config);
131
-
132
- // Add to sliders array
133
- waterfalls.push({ name, swiper: swiper });
150
+ // INIT SWIPER
151
+ const swiper = new Swiper(swiperEl as HTMLElement, config);
152
+ waterfalls.push({ name, swiper });
134
153
  }
135
154
  }
136
155
 
@@ -140,5 +159,3 @@ initSlideCount();
140
159
  document.addEventListener("DOMContentLoaded", function () {
141
160
  addSlides();
142
161
  });
143
-
144
- export * from './lib/attributes';
package/tsconfig.json CHANGED
@@ -12,6 +12,9 @@
12
12
  "skipLibCheck": true,
13
13
  "outDir": "package/dist",
14
14
  "baseUrl": "./src",
15
+ "paths": {
16
+ "lib/*": ["./lib/*"]
17
+ },
15
18
  "resolveJsonModule": true,
16
19
  "sourceMap": true,
17
20
  "types": ["jquery"]
package/webpack.config.js CHANGED
@@ -34,6 +34,9 @@ module.exports = {
34
34
  mode: 'development', // Can be 'development' for debugging
35
35
  resolve: {
36
36
  extensions: ['.js', '.ts', '.json'], // Add file extensions you use
37
+ alias: {
38
+ lib: path.resolve(__dirname, 'src/lib'),
39
+ },
37
40
  },
38
41
  plugins: [
39
42
  new webpack.DefinePlugin({