@total_onion/onion-library 2.0.32 → 2.0.34

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,4 +1,3 @@
1
- import scrollingbannerJs from 'Assets/js/modules/library-modules/scrolling-banner/scrolling-banner';
2
1
  export default function scrollingbannerv3Js(options = {}) {
3
2
  try {
4
3
  const {block} = options;
@@ -7,3 +6,126 @@ export default function scrollingbannerv3Js(options = {}) {
7
6
  console.error(error);
8
7
  }
9
8
  }
9
+
10
+ const initializedBanners = new WeakMap(); // key = element, value = { animations } //cleaner way
11
+ function scrollingbannerJs(block) {
12
+ if (!block) {
13
+ return;
14
+ }
15
+
16
+ const bannerElement = block.querySelector('.scrolling-banner-v3');
17
+ if (!bannerElement) {
18
+ return;
19
+ }
20
+
21
+ try {
22
+ // only if it is not already done
23
+ if (!initializedBanners.has(bannerElement)) {
24
+ bannerInit(bannerElement);
25
+ }
26
+
27
+ // resize observer instead of resizeDebouncer because the later
28
+ // caused the issue mentionned in MLDB-7
29
+ const wrapper = bannerElement.querySelector(
30
+ '.scrolling-banner-v3__wrapper'
31
+ );
32
+ if (wrapper) {
33
+ if (window.ResizeObserver) {
34
+ const resizeObserver = new ResizeObserver(() => {
35
+ resetBanner(bannerElement);
36
+ bannerInit(bannerElement);
37
+ });
38
+ resizeObserver.observe(wrapper);
39
+ } else {
40
+ // Fallback simple
41
+ window.addEventListener('resize', () => {
42
+ resetBanner(bannerElement);
43
+ bannerInit(bannerElement);
44
+ });
45
+ }
46
+ }
47
+ } catch (error) {
48
+ console.error(error);
49
+ }
50
+
51
+ function bannerInit(bannerElement) {
52
+ if (initializedBanners.has(bannerElement)) {
53
+ return;
54
+ }
55
+ // console.log('bannerInit');
56
+
57
+ const container = bannerElement.querySelector(
58
+ '.scrolling-banner-v3__container'
59
+ );
60
+ const wrapper = bannerElement.querySelector(
61
+ '.scrolling-banner-v3__wrapper'
62
+ );
63
+ const inner = bannerElement.querySelector(
64
+ '.scrolling-banner-v3__inner'
65
+ );
66
+ const speed = bannerElement.dataset.speed ?? 5;
67
+
68
+ const wrapperWidth = wrapper.clientWidth;
69
+ const innerContentWidth = inner.clientWidth;
70
+ const multiplier = Number(Math.round(wrapperWidth / innerContentWidth));
71
+
72
+ for (let index = 0; index < multiplier; index++) {
73
+ const newInner = inner.cloneNode(true);
74
+ newInner.classList.add('clone');
75
+ container.appendChild(newInner);
76
+ }
77
+
78
+ const containerHeight = inner.clientHeight;
79
+ wrapper.setAttribute('style', `min-height: ${containerHeight}px`);
80
+
81
+ const newTickerContainer = container.cloneNode(true);
82
+ newTickerContainer.classList.add('clone');
83
+ wrapper.appendChild(newTickerContainer);
84
+
85
+ const animation = [
86
+ {transform: `translateX(0%)`},
87
+ {transform: `translateX(-200%)`}
88
+ ];
89
+
90
+ const time = 100000 / speed;
91
+
92
+ let timing = {
93
+ duration: time,
94
+ iterations: Infinity
95
+ };
96
+ let timing2 = {
97
+ duration: time,
98
+ delay: time / 2,
99
+ iterations: Infinity
100
+ };
101
+ const containers = bannerElement.querySelectorAll(
102
+ '.scrolling-banner-v3__container'
103
+ );
104
+
105
+ const anim1 = containers[0].animate(animation, timing);
106
+ const anim2 = containers[1].animate(animation, timing2);
107
+
108
+ // set as initialized and store animation for a possible cleanup
109
+ initializedBanners.set(bannerElement, {anim1, anim2});
110
+ }
111
+
112
+ function resetBanner(bannerElement) {
113
+ // if already initialized, anims get reset
114
+ const data = initializedBanners.get(bannerElement);
115
+ if (data) {
116
+ data.anim1?.cancel();
117
+ data.anim2?.cancel();
118
+ initializedBanners.delete(bannerElement);
119
+ }
120
+
121
+ bannerElement
122
+ .querySelectorAll(
123
+ '.scrolling-banner-v3__container.clone, .scrolling-banner-v3__inner.clone'
124
+ )
125
+ .forEach((el) => el.remove());
126
+
127
+ bannerElement
128
+ .querySelector('.scrolling-banner-v3__wrapper')
129
+ .removeAttribute('style');
130
+ }
131
+ }
@@ -1,6 +1,6 @@
1
- @use 'NodeModules/@total_onion/onion-library/components/fields-core-functions-v3/core-functions-v3';
2
- @use 'NodeModules/@total_onion/onion-library/components/fields-core-mixins-v3/core-mixins-v3';
3
- @use 'NodeModules/@total_onion/onion-library/breakpoints';
1
+ @use '../fields-core-functions-v3/core-functions-v3';
2
+ @use '../fields-core-mixins-v3/core-mixins-v3';
3
+ @use '../../breakpoints';
4
4
 
5
5
  .scrolling-banner-v3 {
6
6
  position: relative;
@@ -14,7 +14,6 @@
14
14
  text-transform: uppercase;
15
15
  height: auto;
16
16
  z-index: 99;
17
- grid-area: main;
18
17
  place-self: var(--position);
19
18
 
20
19
  &__wrapper {
@@ -1,6 +1,5 @@
1
1
  {% set blockClassName = "scrolling-banner-v3" %}
2
2
  {% set classNameEntryPoint = include('entry-points/entry-point-classes.twig', { fields: fields, block: block }, with_context = false) %}
3
- {# {% set htmlEntryPoint = include('entry-points/entry-point-html-v3.twig', { fields: fields, block: block, blockClassName, blockClassName }, with_context = false) %} #}
4
3
  {% set dataAttributeEntryPoint = include('entry-points/entry-point-data-attribute.twig', { fields: fields, block: block }, with_context = false) %}
5
4
  {% set styleEntryPoint = include('entry-points/entry-point-style-v3.twig', { fields: fields, block: block, is_preview }, with_context = false) %}
6
5
  {% set previewEntryPoint = include('entry-points/entry-point-preview-info.twig', { fields, block, displaytype, is_preview }, with_context = false) %}
@@ -13,9 +12,8 @@
13
12
  {{sectionStyles}}
14
13
  }
15
14
  </style>
16
- <section {{block.anchor ? "id=" ~ block.anchor : ''}} class="{{blockClassName}} {{block.className}} {{classNameEntryPoint}} {{block.id}} lazy-fade" {{dataAttributeEntryPoint}} data-blockid="{{block.id}}" data-assetkey="{{blockClassName}}">
15
+ <section {{block.anchor ? "id=" ~ block.anchor : ''}} class="{{blockClassName}} {{classNameEntryPoint}} {{block.id}} lazy-fade" {{dataAttributeEntryPoint}} data-blockid="{{block.id}}" data-assetkey="{{blockClassName}}">
17
16
 
18
- {% set className = 'scrolling-banner' %}
19
17
  {% set bannerText = fields.scrolling_banner_text %}
20
18
  {% set enableScrolling = fields.enable_scrolling_banner %}
21
19
  {% set bannerSpeed = fields.scrolling_banner_speed %}
@@ -28,23 +26,19 @@
28
26
  {% set bannerTextStyles = textSizeDesktop ~ textSizePortrait ~ textSizeMobile ~ positioning ~ textColour %}
29
27
 
30
28
  {% if fields.enable_text_shadow %}
31
- {% set textShadowClassName = className ~ "--text-shadow" %}
29
+ {% set textShadowClassName = blockClassName ~ "--text-shadow" %}
32
30
  {% set textShadowStyle = "--text-shadow-offset-x:" ~ (fields.text_shadow_horizontal_offset|default(0)) ~ "; --text-shadow-offset-y: " ~ (fields.text_shadow_vertical_offset|default(0)) ~ "; --text-shadow-blur: " ~ (fields.text_shadow_blur|default(0)) ~ "; --text-shadow-colour: " ~ (fields.text_shadow_colour|default("#000000")) ~ ";" %}
33
31
  {% endif %}
34
-
35
32
  {% if enableScrolling %}
36
- <div class="{{className}}" data-speed="{{bannerSpeed}}" style="{{bannerTextStyles ~ textShadowStyle}}">
37
- <div class="{{className}}__wrapper">
38
- <div class="{{className}}__container">
39
- <div class="{{className}}__inner">
40
- <span class="{{className}}__separator"></span>
41
- <span class="{{className}}__text {{textShadowClassName}}">{{bannerText}}</span>
33
+ <div class="{{blockClassName}}" data-speed="{{bannerSpeed}}" style="{{bannerTextStyles ~ textShadowStyle}}">
34
+ <div class="{{blockClassName}}__wrapper">
35
+ <div class="{{blockClassName}}__container">
36
+ <div class="{{blockClassName}}__inner">
37
+ <span class="{{blockClassName}}__separator"></span>
38
+ <span class="{{blockClassName}}__text {{textShadowClassName}}">{{bannerText}}</span>
42
39
  </div>
43
40
  </div>
44
41
  </div>
45
42
  </div>
46
43
  {% endif %}
47
-
48
-
49
- {# {{htmlEntryPoint}} #}
50
44
  </section>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@total_onion/onion-library",
3
- "version": "2.0.32",
3
+ "version": "2.0.34",
4
4
  "description": "Component library",
5
5
  "main": "index.js",
6
6
  "scripts": {