rytm-webflow 2.0.9 → 2.1.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # rytm-webflow
2
2
  Rytm webflow pack is used to make websites rendered on the server (using a PHP or other back-end) more dynamic.
3
3
  A static website can be transformed into something we call a *pseudo single page application* (SPA). The pack includes [ASwap](#aswap) - a framework under developement by Rytm.Digital since 2016 which uses *AJAX* / *fetch* to first load and then *swap* the page's content in user's browser.
4
- This package comes with a handy [WebflowView](#webflowview).
4
+ This package comes with a handy [WebflowView](#webflowview) and [WebflowListView](#webflowlistview).
5
5
  Another future rytm-webflow includes is [ShowUp](#showup) - a ScrollMagic.js wrapper which can be integrated with ASwap.
6
6
 
7
7
 
@@ -269,7 +269,30 @@ Scroll-triggered-animations of any element inside the *WebflowView* container. U
269
269
  ...
270
270
  </div>
271
271
  ```
272
+ ## <a name="webflowlistview">WebflowListView</a> ##
273
+ The WebflowListView enables staggered *show* animation for elements which implement the WebflowView Scrollmagic animations.
274
+ ### Basic usage example
275
+ Define the route:
276
+ ```js
277
+ import RytmWebflow from 'rytm-webflow'
272
278
 
279
+ RytmWebflow.aswap.init({
280
+ routes: {
281
+ "list" : {
282
+ controller: RytmWebflow.Controller,
283
+ view: RytmWebflow.WebflowListView
284
+ }
285
+ }
286
+ })
287
+ ```
288
+ Add data attributes to the cointainer element. Inside the container place elements that include the `webscroll` data attributes (initial, show, hide):
289
+ ```html
290
+ <div id="stage">
291
+ <ul data-as-view="list" data-as-id="uid" data-webset="selector:li,stagger:.1">
292
+ <li data-webscroll-initial="o:0" data-webscroll-show="o:1,t:.5" data-webscroll-hide="o:0,t.4">...</li>
293
+ </ul>
294
+ </div>
295
+ ```
273
296
 
274
297
 
275
298
  ## <a name="showup">ShowUp</a> ##
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rytm-webflow",
3
- "version": "2.0.9",
3
+ "version": "2.1.1",
4
4
  "description": "rytm webflow pack - ASwap, ShowUp",
5
5
  "main": "scripts/index.js",
6
6
  "scripts": {
@@ -0,0 +1,77 @@
1
+ import gsap from 'gsap';
2
+ import View from './View';
3
+ import { getWebflowAnimationProps, parseProps } from './../lib/dataTweenParser';
4
+
5
+ // data-webscroll-... (scroll magic)
6
+ const DATA_ATTR_WEBSCROLL_INIT = "webscroll-initial";
7
+ const DATA_ATTR_WEBSCROLL_SHOW = "webscroll-show";
8
+ const DATA_ATTR_SETUP = "webset";
9
+ const DEFAULT_STAGGER = .05;
10
+
11
+ class WebflowListView extends View {
12
+
13
+ constructor(id) {
14
+ super(id);
15
+ }
16
+ /**
17
+ * animate in (show)
18
+ **/
19
+ show(container) {
20
+ super.show(container);
21
+ this.webset = parseProps(container.dataset[DATA_ATTR_SETUP]);
22
+ if (!this.webset.selector) {
23
+ console.warn("Unknown selector for WebflowListView", this);
24
+ return;
25
+ }
26
+ const list = [...container.querySelectorAll(this.webset.selector)];
27
+ list.forEach(this.listElementShow.bind(this));
28
+ }
29
+ /**
30
+ * animate out (hide)
31
+ **/
32
+ hide(container) {
33
+ super.hide(container);
34
+ }
35
+ /**
36
+ * ############
37
+ * ### SHOW ###
38
+ * ############
39
+ */
40
+ // show list element
41
+ listElementShow(el, index) {
42
+ const stagger = this.webset.stagger ? parseFloat(this.webset.stagger) : DEFAULT_STAGGER;
43
+ const delay = index * stagger;
44
+ // search for all webscroll elements
45
+ const list = [...el.querySelectorAll('*[data-' + DATA_ATTR_WEBSCROLL_SHOW + ']')];
46
+ list.forEach((el) => {
47
+ this.webScrollElementShow(el, delay);
48
+ })
49
+ }
50
+ // show web scroll element
51
+ webScrollElementShow(el, delay) {
52
+ const propsInitial = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_INIT);
53
+ const propsShow = this.getTweenProps(el, DATA_ATTR_WEBSCROLL_SHOW);
54
+ if (propsInitial && propsShow) {
55
+ delay = delay + (propsShow.tween.delay || 0);
56
+ gsap.killTweensOf(el);
57
+ gsap.set(el, {...propsInitial.tween});
58
+ gsap.to(el, {duration: propsShow.time, ...propsShow.tween, delay});
59
+ }
60
+ }
61
+ /**
62
+ * ###############
63
+ * ### HELPERS ###
64
+ * ###############
65
+ */
66
+ // get animation props
67
+ getTweenProps(el, name) {
68
+ const dataAttrName = this.getDataAttributeName(name);
69
+ return getWebflowAnimationProps(el.dataset[dataAttrName]);
70
+ }
71
+ // replace data-x with dataX
72
+ getDataAttributeName(name) {
73
+ return name.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
74
+ }
75
+
76
+ }
77
+ export default WebflowListView
package/scripts/index.js CHANGED
@@ -3,6 +3,7 @@ import Controller from './aswap/Controller'
3
3
  import ControllerImgLoad from './aswap/ControllerImgLoad'
4
4
  import View from './aswap/View'
5
5
  import WebflowView from './aswap/WebflowView'
6
+ import WebflowListView from './aswap/WebflowListView'
6
7
  // Bootstrap v5 helper
7
8
  import bootsrap5 from './bootstrap/v5/Bootstrap5'
8
9
  // showup
@@ -17,6 +18,7 @@ export default {
17
18
  ControllerImgLoad,
18
19
  View,
19
20
  WebflowView,
21
+ WebflowListView,
20
22
  // boottstrap
21
23
  bootsrap5,
22
24
  // showup