well-waterfall 0.1.38 → 0.1.40

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "well-waterfall",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "description": "An attribute-based wrapper of SwiperJS for Webflow",
5
5
  "main": "waterfall.js",
6
6
  "scripts": {
@@ -0,0 +1,16 @@
1
+ import { parseAttr } from '../util';
2
+
3
+ export function autoplayConfig($this: JQuery<HTMLElement>) {
4
+ // Add CSS for Smooth Autoplay
5
+ $("[smooth-autoplay='true']")
6
+ .find('.swiper-wrapper')
7
+ .css('transition-timing-function', 'linear');
8
+
9
+ return {
10
+ delay: parseAttr($this, 'delay', 3000),
11
+ disableOnInteraction: parseAttr($this, 'disable-on-interaction', false), // documentation says default is true, doesn't appear to be correct
12
+ reverseDirection: parseAttr($this, 'reverse-direction', false),
13
+ pauseOnMouseEnter: parseAttr($this, 'pause-on-mouse-enter', false),
14
+ stopOnLastSlide: parseAttr($this, 'stop-on-last-slide', false),
15
+ };
16
+ }
@@ -0,0 +1,22 @@
1
+ import { parseAttr } from '../util';
2
+
3
+ export function navigationConfig($this: JQuery<HTMLElement>, name: string) {
4
+ return {
5
+ disabledClass: parseAttr(
6
+ $this,
7
+ 'nav-disabled-class',
8
+ 'swiper-button-disabled',
9
+ ),
10
+ enabled: parseAttr($this, 'nav-enabled', null),
11
+ hiddenClass: parseAttr($this, 'nav-hidden-class', 'swiper-button-hidden'),
12
+ hideOnClick: parseAttr($this, 'nav-hide-on-click', false),
13
+ lockClass: parseAttr($this, 'nav-lock-class', 'swiper-button-lock'),
14
+ navigationDisabledClass: parseAttr(
15
+ $this,
16
+ 'nav-disabled-class',
17
+ 'swiper-navigation-disabled',
18
+ ),
19
+ nextEl: `[waterfall='${name}'] [waterfall-el='next']`,
20
+ prevEl: `[waterfall='${name}'] [waterfall-el='prev']`,
21
+ };
22
+ }
package/src/util.ts CHANGED
@@ -19,6 +19,18 @@ export function getUniqueClasses(
19
19
  return filtered.join(' '); // Join the remaining classes into a string
20
20
  }
21
21
 
22
+ export function parseString(
23
+ el: JQuery<HTMLElement>,
24
+ attrName: string,
25
+ defaultValue: string,
26
+ ) {
27
+ const attrValue = $(el).attr(attrName)?.trim();
28
+ if (!attrValue) return null;
29
+ // Nullify the attribute if it matches the default value from SwiperJS
30
+ if (attrValue === defaultValue) return null;
31
+ return attrValue;
32
+ }
33
+
22
34
  export function parseAttr(
23
35
  el: JQuery<HTMLElement>,
24
36
  attrName: string,
package/src/waterfall.ts CHANGED
@@ -1,32 +1,29 @@
1
+ import Swiper from 'swiper/bundle';
1
2
  import 'swiper/css/bundle';
2
3
  import {
3
4
  getUniqueClasses,
4
5
  parseAttr,
5
6
  removeNullKeys,
6
7
  printDebug,
8
+ parseString,
7
9
  } from './util';
8
- import Swiper from 'swiper';
10
+ import { navigationConfig } from './modules/navigation';
11
+ import { autoplayConfig } from './modules/autoplay';
9
12
 
10
13
  console.log(`🚿 Hello from Wellflow Waterfall v${APP_VERSION}`);
11
14
 
12
15
  const sliders: any[] = [];
13
16
 
14
- $('[waterfall]:not([thumbs-swiper])').each(function (index) {
15
- const $wtf = $(this);
16
- createConfig($wtf, index);
17
- });
17
+ $('[waterfall]').each(function (index) {
18
+ const $this = $(this);
18
19
 
19
- $('[waterfall][thumbs-swiper]').each(function (index) {
20
- const $wtf = $(this);
21
- console.log('PROCESSING THUMBS:', $wtf);
22
- createConfig($wtf, index);
23
- });
20
+ const name = parseString($this, 'waterfall', `Swiper ${index}`);
21
+ if (!name) return;
24
22
 
25
- function createConfig($this: JQuery<HTMLElement>, index: number) {
26
- const name = parseAttr($this, 'waterfall', `Swiper ${index}`);
27
- console.log(`Initializing Waterfall: ${name}}`);
28
23
  const debug = Boolean(parseAttr($this, 'debug-mode', false) || false);
29
24
 
25
+ console.log(`Initializing Waterfall: ${name} ${debug ? '[DEBUG MODE]' : ''}`);
26
+
30
27
  const swiperConfig: any = {
31
28
  a11y: {
32
29
  prevSlideMessage: parseAttr($this, 'a11y-prev-message', 'Previous Slide'),
@@ -84,6 +81,7 @@ function createConfig($this: JQuery<HTMLElement>, index: number) {
84
81
  longSwipes: parseAttr($this, 'long-swipes', true), // no effect
85
82
  longSwipesMs: parseAttr($this, 'long-swipes-ms', 300), // no effect
86
83
  longSwipesRatio: parseAttr($this, 'long-swipes-ratio', 0.5), // no effect
84
+ loop: parseAttr($this, 'loop-mode', false),
87
85
  loopAddBlankSlides: parseAttr($this, 'loop-add-blank-slides', true),
88
86
  loopAdditionalSlides: parseAttr($this, 'loop-additional-slides', 0),
89
87
  loopPreventsSliding: parseAttr($this, 'loop-prevents-sliding', true),
@@ -119,6 +117,7 @@ function createConfig($this: JQuery<HTMLElement>, index: number) {
119
117
  resistance: parseAttr($this, 'resistance', true),
120
118
  resistanceRatio: parseAttr($this, 'resistance-ratio', 0.85),
121
119
  resizeObserver: parseAttr($this, 'resize-observer', true),
120
+ rewind: parseAttr($this, 'rewind', false),
122
121
  roundLengths: parseAttr($this, 'round-lengths', false),
123
122
  runCallbacksOnInit: parseAttr($this, 'run-callbacks-on-init', true),
124
123
  // scrollbar: null,
@@ -205,84 +204,34 @@ function createConfig($this: JQuery<HTMLElement>, index: number) {
205
204
  478: {
206
205
  centeredSlides: parseAttr($this, 'lmobile-centered-slides', null),
207
206
  slidesPerView: parseAttr($this, 'lmobile-slides-per-view', null),
208
- slidesPerGroup: parseAttr($this, 'lmobile-slides-per-group', null),
209
207
  spaceBetween: parseAttr($this, 'lmobile-space-between', null),
210
208
  },
211
209
  767: {
212
210
  centeredSlides: parseAttr($this, 'tablet-centered-slides', null),
213
211
  slidesPerView: parseAttr($this, 'tablet-slides-per-view', null),
214
- slidesPerGroup: parseAttr($this, 'tablet-slides-per-group', null),
215
212
  spaceBetween: parseAttr($this, 'tablet-space-between', null),
216
213
  },
217
214
  991: {
218
215
  centeredSlides: parseAttr($this, 'desktop-centered-slides', null),
219
216
  slidesPerView: parseAttr($this, 'desktop-slides-per-view', null),
220
- slidesPerGroup: parseAttr($this, 'desktop-slides-per-group', null),
221
217
  spaceBetween: parseAttr($this, 'desktop-space-between', null),
222
218
  },
223
219
  1280: {
224
220
  centeredSlides: parseAttr($this, 'large-centered-slides', null),
225
221
  slidesPerView: parseAttr($this, 'large-slides-per-view', null),
226
- slidesPerGroup: parseAttr($this, 'large-slides-per-group', null),
227
222
  spaceBetween: parseAttr($this, 'large-space-between', null),
228
223
  },
229
224
  1440: {
230
225
  centeredSlides: parseAttr($this, 'xlarge-centered-slides', null),
231
226
  slidesPerView: parseAttr($this, 'xlarge-slides-per-view', null),
232
- slidesPerGroup: parseAttr($this, 'xlarge-slides-per-group', null),
233
227
  spaceBetween: parseAttr($this, 'xlarge-space-between', null),
234
228
  },
235
229
  };
236
230
 
237
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
238
- // --- PLAYBACK -------------------------------
239
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
240
-
241
- const playbackMode = parseAttr($this, 'playback-mode', 'none');
242
- if (playbackMode === 'loop') swiperConfig.loop = true;
243
- if (playbackMode === 'rewind') swiperConfig.rewind = true;
244
- if (playbackMode === 'none') {
245
- swiperConfig.loop = false;
246
- swiperConfig.rewind = false;
247
- }
248
-
249
231
  const autoplayMode = parseAttr($this, 'autoplay-mode', false);
250
- if (autoplayMode) {
251
- swiperConfig.autoplay = {
252
- delay: parseAttr($this, 'delay', 3000),
253
- disableOnInteraction: parseAttr($this, 'disable-on-interaction', false), // documentation says default is true, doesn't appear to be correct
254
- reverseDirection: parseAttr($this, 'reverse-direction', false),
255
- pauseOnMouseEnter: parseAttr($this, 'pause-on-mouse-enter', false),
256
- stopOnLastSlide: parseAttr($this, 'stop-on-last-slide', false),
257
- };
258
- // Add CSS for Smooth Autoplay
259
- $("[smooth-autoplay='true']")
260
- .find('.swiper-wrapper')
261
- .css('transition-timing-function', 'linear');
262
- }
232
+ if (autoplayMode) swiperConfig.autoplay = autoplayConfig($this);
263
233
 
264
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
265
- // --- NAVIGATION -----------------------------
266
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
267
-
268
- swiperConfig.navigation = {
269
- disabledClass: parseAttr(
270
- $this,
271
- 'nav-disabled-class',
272
- 'swiper-button-disabled',
273
- ),
274
- enabled: parseAttr($this, 'nav-enabled', null),
275
- hiddenClass: parseAttr($this, 'nav-hidden-class', 'swiper-button-hidden'),
276
- hideOnClick: parseAttr($this, 'nav-hide-on-click', false),
277
- lockClass: parseAttr($this, 'nav-lock-class', 'swiper-button-lock'),
278
- navigationDisabledClass: parseAttr(
279
- $this,
280
- 'nav-disabled-class',
281
- 'swiper-navigation-disabled',
282
- ),
283
- nextEl: `[waterfall='${name}'] [waterfall-el='next']`,
284
- prevEl: `[waterfall='${name}'] [waterfall-el='prev']`,
285
- };
234
+ swiperConfig.navigation = navigationConfig($this, name);
286
235
 
287
236
  // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
288
237
  // --- PAGINATION -----------------------------
@@ -473,67 +422,16 @@ function createConfig($this: JQuery<HTMLElement>, index: number) {
473
422
  rows: parseAttr($this, 'grid-rows', 1),
474
423
  };
475
424
 
476
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
477
- // --- EFFECT ---------------------------------
478
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
479
-
480
- swiperConfig.fadeEffect = {
481
- crossFade: parseAttr($this, 'fade-cross-fade', false),
482
- };
483
-
484
- swiperConfig.coverflowEffect = {
485
- depth: parseAttr($this, 'coverflow-depth', 100),
486
- modifier: parseAttr($this, 'coverflow-modifier', 1),
487
- rotate: parseAttr($this, 'coverflow-rotate', 50),
488
- scale: parseAttr($this, 'coverflow-scale', 1),
489
- slideShadows: parseAttr($this, 'coverflow-slide-shadows', true),
490
- stretch: parseAttr($this, 'coverflow-stretch', 0),
491
- };
492
-
493
- swiperConfig.flipEffect = {
494
- limitRotation: parseAttr($this, 'flip-limit-rotation', true),
495
- slideShadows: parseAttr($this, 'flip-slide-shadows', true),
496
- };
497
-
498
- swiperConfig.cubeEffect = {
499
- shadow: parseAttr($this, 'cube-shadow', true),
500
- shadowOffset: parseAttr($this, 'cube-shadow-offset', 20),
501
- shadowScale: parseAttr($this, 'cube-shadow-scale', 0.94),
502
- slideShadows: parseAttr($this, 'cube-slide-shadows', true),
503
- };
504
-
505
- swiperConfig.cardsEffect = {
506
- perSlideOffset: parseAttr($this, 'cards-per-slide-offset', 8),
507
- perSlideRotate: parseAttr($this, 'cards-per-slide-rotate', 2),
508
- rotate: parseAttr($this, 'cards-rotate', true),
509
- slideShadows: parseAttr($this, 'cards-slide-shadows', true),
510
- };
511
-
512
- //NOTE - Creative Effect Not implemented
513
-
514
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
515
- // --- THUMBS ---------------------------------
516
- // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
517
-
518
- const thumbsSwiper = parseAttr($this, 'thumbs-swiper', null);
519
- if (thumbsSwiper) {
520
- swiperConfig.thumbs = {
521
- swiper: sliders.find((slider) => slider.name === thumbsSwiper)?.slider,
522
- };
523
- }
524
-
525
425
  // --- CLEANUP AND EXPORT ---
526
426
 
527
427
  const config = removeNullKeys(swiperConfig);
528
- printDebug(debug, `${name} Config:`, config);
428
+ printDebug(debug, 'CONFIG', config);
529
429
 
530
- console.log('THIS', $this);
531
- console.log('SWIPER CHILE: ', $this.find('.swiper')[0]);
430
+ // Initialize swiper
532
431
  const swiper = new Swiper($this.find('.swiper')[0], config);
533
- console.log('SWIPER:', swiper);
534
432
 
535
433
  sliders.push({ name, slider: swiper });
536
- }
434
+ });
537
435
 
538
436
  // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
539
437
  // --- SLIDE COUNT ----------------------------
@@ -547,6 +445,3 @@ document.querySelectorAll('.swiper-wrapper').forEach((swiperWrapper) => {
547
445
  }
548
446
  });
549
447
  });
550
-
551
- // Add the role="listitem" attribute to each slide
552
- $('.swiper-slide').attr('role', 'listitem');