rytm-webflow 2.2.3 → 2.2.4

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": "rytm-webflow",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "rytm webflow pack - ASwap, ShowUp",
5
5
  "main": "scripts/index.js",
6
6
  "scripts": {
@@ -50,7 +50,19 @@ class View {
50
50
  * fired only if ControllerImgLoad is used
51
51
  */
52
52
  loadImagesComplete(container) {
53
- }
53
+ }
54
+ /**
55
+ * check if DOM element belongs to view
56
+ * exclude elements belonging to nested views
57
+ */
58
+ elementBelongsToView = (el) => {
59
+ let result = false;
60
+ const elContainer = el.closest('[data-as-view]');
61
+ if (elContainer && elContainer.dataset.asId === this.id) {
62
+ result = true;
63
+ }
64
+ return result;
65
+ }
54
66
  }
55
67
 
56
68
  export default View;
@@ -6,6 +6,7 @@ import { CLASS_NAME_WEBSCROLL_FIRED } from './WebflowView';
6
6
  // data-webscroll-... (scroll magic)
7
7
  const DATA_ATTR_WEBSCROLL_INIT = "webscroll-initial";
8
8
  const DATA_ATTR_WEBSCROLL_SHOW = "webscroll-show";
9
+ const DATA_ATTR_WEBSCROLL_HIDE = "webscroll-hide";
9
10
  const DATA_ATTR_SETUP = "webset";
10
11
  const DEFAULT_STAGGER = .05;
11
12
 
@@ -24,7 +25,7 @@ class WebflowListView extends View {
24
25
  console.warn("Unknown selector for WebflowListView", this);
25
26
  return;
26
27
  }
27
- const list = [...container.querySelectorAll(this.webset.selector)];
28
+ const list = [...container.querySelectorAll(this.webset.selector)].filter(this.elementBelongsToView);
28
29
  list.forEach(this.listElementShow.bind(this));
29
30
  }
30
31
  /**
@@ -32,6 +33,13 @@ class WebflowListView extends View {
32
33
  **/
33
34
  hide(container) {
34
35
  super.hide(container);
36
+ this.webset = parseProps(container.dataset[DATA_ATTR_SETUP]);
37
+ if (!this.webset.selector) {
38
+ console.warn("Unknown selector for WebflowListView", this);
39
+ return;
40
+ }
41
+ const list = [...container.querySelectorAll(this.webset.selector)].filter(this.elementBelongsToView);
42
+ list.forEach(this.listElementHide.bind(this));
35
43
  }
36
44
  /**
37
45
  * ############
@@ -45,7 +53,7 @@ class WebflowListView extends View {
45
53
  const stagger = this.webset.stagger ? parseFloat(this.webset.stagger) : DEFAULT_STAGGER;
46
54
  const delay = index * stagger;
47
55
  // search for all webscroll elements
48
- const list = [...el.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')];
56
+ const list = [...el.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')].filter(this.elementBelongsToView);
49
57
  list.forEach((el) => {
50
58
  this.webScrollElementShow(el, delay);
51
59
  })
@@ -68,6 +76,36 @@ class WebflowListView extends View {
68
76
  });
69
77
  }
70
78
  }
79
+ /**
80
+ * ############
81
+ * ### HIDE ###
82
+ * ############
83
+ */
84
+ // show list element
85
+ listElementHide(el, index) {
86
+ // check if element is in viewport
87
+ if (!this.isElementInViewport(el)) return;
88
+ const stagger = this.webset.stagger ? parseFloat(this.webset.stagger) : DEFAULT_STAGGER;
89
+ const delay = index * stagger;
90
+ // search for all webscroll elements
91
+ const list = [...el.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')].filter(this.elementBelongsToView);
92
+ list.forEach((el) => {
93
+ this.webScrollElementHide(el, delay);
94
+ })
95
+ }
96
+ // show web scroll element
97
+ webScrollElementHide(el, delay) {
98
+ const propsHide = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_HIDE);
99
+ if (propsHide) {
100
+ delay = delay + (propsHide.tween.delay || 0);
101
+ gsap.killTweensOf(el);
102
+ gsap.to(el, {
103
+ duration: propsHide.time,
104
+ ...propsHide.tween,
105
+ delay,
106
+ });
107
+ }
108
+ }
71
109
  /**
72
110
  * ###############
73
111
  * ### HELPERS ###
@@ -55,6 +55,7 @@ class WebflowView extends View {
55
55
  * animate out (hide)
56
56
  **/
57
57
  hide(container) {
58
+ this.container = container;
58
59
  super.hide(container);
59
60
  // hide Aswap webviews
60
61
  this.webViewsHide();
@@ -120,7 +121,7 @@ class WebflowView extends View {
120
121
  console.warn("Unknown container", this);
121
122
  return;
122
123
  }
123
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_SHOW + ']')];
124
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_SHOW + ']')].filter(this.elementBelongsToView);
124
125
  list.forEach(this.webViewElementShow.bind(this));
125
126
  }
126
127
  // showe webview element
@@ -140,7 +141,7 @@ class WebflowView extends View {
140
141
  console.warn("Unknown container", this);
141
142
  return;
142
143
  }
143
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_SHOW + ']')];
144
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_SHOW + ']')].filter(this.elementBelongsToView);
144
145
  list.forEach(this.staggerListShow.bind(this));
145
146
  }
146
147
  staggerListShow(el, index) {
@@ -149,7 +150,7 @@ class WebflowView extends View {
149
150
  console.warn("Unknown selector for webflow stagger", el);
150
151
  return;
151
152
  }
152
- const items = [...el.querySelectorAll(selector)];
153
+ const items = [...el.querySelectorAll(selector)].filter(this.elementBelongsToView);
153
154
  const propsInit = this.getTweenProps(el, DATA_ATTR_STAGGER_INIT);
154
155
  const propsShow = this.getTweenProps(el, DATA_ATTR_STAGGER_SHOW);
155
156
  if (items.length && propsInit && propsShow) {
@@ -165,7 +166,7 @@ class WebflowView extends View {
165
166
  console.warn("Unknown container", this);
166
167
  return;
167
168
  }
168
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')];
169
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')].filter(this.elementBelongsToView);
169
170
  list.forEach(this.hideScrollElement.bind(this));
170
171
  }
171
172
  hideScrollElement(el, index) {
@@ -183,7 +184,7 @@ class WebflowView extends View {
183
184
  console.warn("Unknown container", this);
184
185
  return;
185
186
  }
186
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')];
187
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')].filter(this.elementBelongsToView);
187
188
  list.forEach(this.buildScrollmagicScene.bind(this));
188
189
  }
189
190
  /**
@@ -248,7 +249,7 @@ class WebflowView extends View {
248
249
  console.warn("Unknown container", this);
249
250
  return;
250
251
  }
251
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_HIDE + ']')];
252
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBVIEW_HIDE + ']')].filter(this.elementBelongsToView);
252
253
  list.forEach(this.webViewsElementHide.bind(this));
253
254
  }
254
255
  // showe webview element
@@ -266,7 +267,7 @@ class WebflowView extends View {
266
267
  console.warn("Unknown container", this);
267
268
  return;
268
269
  }
269
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_HIDE + ']')];
270
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_STAGGER_HIDE + ']')].filter(this.elementBelongsToView);
270
271
  list.forEach(this.staggerListHide.bind(this));
271
272
  }
272
273
  // Hide stagger element
@@ -276,7 +277,7 @@ class WebflowView extends View {
276
277
  console.warn("Unknown selector for webflow stagger", el);
277
278
  return;
278
279
  }
279
- const items = [...el.querySelectorAll(selector)];
280
+ const items = [...el.querySelectorAll(selector)].filter(this.elementBelongsToView);
280
281
  const propsHide = this.getTweenProps(el, DATA_ATTR_STAGGER_HIDE);
281
282
  if (items.length && propsHide) {
282
283
  gsap.killTweensOf(items);
@@ -292,7 +293,7 @@ class WebflowView extends View {
292
293
  console.warn("Unknown container", this);
293
294
  return;
294
295
  }
295
- const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_HIDE + ']')];
296
+ const list = [...this.container.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_HIDE + ']')].filter(this.elementBelongsToView);
296
297
  list.forEach(this.hideScrollmagicElement.bind(this));
297
298
  }
298
299
  /**