@total_onion/onion-library 3.0.48 → 3.1.0

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,6 +1,6 @@
1
- export default function modalformv3Js ( options = {} ) {
1
+ export default function modalformv3Js(options = {}) {
2
2
  try {
3
- const { block } = options;
3
+ const {block} = options;
4
4
 
5
5
  // form logic
6
6
  function validateFormFields(block) {
@@ -9,7 +9,9 @@ export default function modalformv3Js ( options = {} ) {
9
9
  );
10
10
 
11
11
  inputs.forEach((input) => {
12
- const wrapper = input.closest('.cdb_form_field, .cdb_form_gdpr_information, .cdb_form_privacypolicy_information');
12
+ const wrapper = input.closest(
13
+ '.cdb_form_field, .cdb_form_gdpr_information, .cdb_form_privacypolicy_information'
14
+ );
13
15
 
14
16
  if (!wrapper) return;
15
17
 
@@ -41,18 +43,17 @@ export default function modalformv3Js ( options = {} ) {
41
43
  });
42
44
  }
43
45
 
44
-
45
- const submit = block.querySelector(
46
- '.cdb-submit'
47
- );
48
-
46
+ const submit = block.querySelector('.cdb-submit');
47
+ if (!submit) {
48
+ console.error('could not find submit button');
49
+ return;
50
+ }
49
51
  submit.classList.add('cmpl-cta-style-11', 'cmpl-cta-animation-style-1');
50
52
 
51
53
  submit.addEventListener('click', (e) => {
52
54
  validateFormFields(block);
53
55
  });
54
-
55
- } catch ( error ) {
56
- console.error( error );
56
+ } catch (error) {
57
+ console.error(error);
57
58
  }
58
59
  }
@@ -1,4 +1,4 @@
1
- // import videocontroller from '@total_onion/onion-videocontroller/onion-videocontroller.js';
1
+ // import videocontroller from '../../onion-videocontroller/onion-videocontroller.js';
2
2
 
3
3
  export default function postinfov3Js(options = {}) {
4
4
  const {block} = options;
@@ -1,4 +1,4 @@
1
- import videocontroller from '@total_onion/onion-videocontroller/onion-videocontroller.js';
1
+ import videocontroller from '../../onion-videocontroller/onion-videocontroller.js';
2
2
 
3
3
  export default function videocontentv3Js(options = {}) {
4
4
  try {
@@ -0,0 +1,2 @@
1
+ # onion-modalcontroller
2
+ Pop up modal controller
@@ -0,0 +1,183 @@
1
+ export default class modalController {
2
+ constructor(settings = {}) {
3
+ let defaultGlobalSettings = {
4
+ bodyClass: "modal-active",
5
+ activeStateClass: "modal-active",
6
+ enableDebugLogs: true,
7
+ userInteracted: false,
8
+ addCloseButton: true,
9
+ closeSelector: "#modal-controller-popup__close-btn",
10
+ closeDelay: 1,
11
+ closingClass: "something",
12
+ activateDelay: 0,
13
+ lenis: false,
14
+ };
15
+ this.scanForNewTriggers();
16
+
17
+ console.log("hello!");
18
+
19
+ if (modalController.instance instanceof modalController) {
20
+ return modalController.instance;
21
+ }
22
+ modalController.instance = this;
23
+ this.globalSettings = { ...defaultGlobalSettings, ...settings };
24
+ this.enableDebugLogs = this.globalSettings.enableDebugLogs;
25
+ this.handleModalTriggers();
26
+ this.handleBgClicks();
27
+ }
28
+
29
+ scanForNewTriggers() {
30
+ this.globalModalTriggers = document.body.querySelectorAll(
31
+ "[data-modalpopuptrigger]",
32
+ );
33
+ }
34
+ handleBgClicks() {
35
+ window.addEventListener("click", (event) => {
36
+ const modalPopup = document.getElementById("modal-controller-popup");
37
+ this.closePopupOnClickOutside(event, modalPopup);
38
+ });
39
+ }
40
+ handleCloseButtonClicks() {
41
+ const modalPopup = document.getElementById("modal-controller-popup");
42
+ if (!modalPopup) {
43
+ return;
44
+ }
45
+ const closeButtons = modalPopup.querySelectorAll(
46
+ this.globalSettings.closeSelector || "#modal-controller-popup__close-btn",
47
+ );
48
+ closeButtons.forEach((closeButton) => {
49
+ if (closeButton.dataset.modalpopupCloseBound === "true") {
50
+ return;
51
+ }
52
+ closeButton.dataset.modalpopupCloseBound = "true";
53
+ closeButton.addEventListener("click", () => {
54
+ const modalPopup = document.getElementById("modal-controller-popup");
55
+ this.closePopup(modalPopup);
56
+ });
57
+ });
58
+ }
59
+ handleModalTriggers() {
60
+ this.globalModalTriggers.forEach((trigger) => {
61
+ trigger.addEventListener("click", () => {
62
+ this.triggerModalPopup(trigger.dataset.modalpopuptrigger);
63
+ });
64
+ });
65
+ }
66
+ triggerModalPopup(triggerName) {
67
+ let modalPopup = document.getElementById("modal-controller-popup");
68
+ if (!modalPopup) {
69
+ const modalPopupHtml = `<div class="modal-controller-popup" id="modal-controller-popup">
70
+ <div class="modal-controller-popup__container">
71
+ ${this.globalSettings.addCloseButton ? '<span class="modal-controller-popup__close-btn" id="modal-controller-popup__close-btn"></span>' : ""}
72
+ <div class="modal-controller-popup__content"></div>
73
+ </div>
74
+ </div>`;
75
+ document.body.insertAdjacentHTML("beforeend", modalPopupHtml);
76
+ modalPopup = document.getElementById("modal-controller-popup");
77
+ }
78
+
79
+ if (!modalPopup) {
80
+ return;
81
+ }
82
+
83
+ const popupContent = document.querySelector(
84
+ ".modal-controller-popup__content",
85
+ );
86
+
87
+ if (!popupContent) {
88
+ return;
89
+ }
90
+
91
+ let templateContent;
92
+
93
+ const modalPopupContent = document.querySelector(
94
+ `[data-modalpopupcontent=${triggerName}]`,
95
+ );
96
+
97
+ if (!modalPopupContent) {
98
+ this.closePopup(modalPopup);
99
+ return;
100
+ }
101
+
102
+ //Check if the actual content element is already in the popup content container, if not - move it there.
103
+ if (
104
+ !popupContent.querySelector(`[data-modalpopupcontent=${triggerName}]`)
105
+ ) {
106
+ if (modalPopupContent) {
107
+ templateContent = modalPopupContent;
108
+ }
109
+
110
+ if (modalPopupContent.nodeName === "TEMPLATE") {
111
+ templateContent = modalPopupContent.content;
112
+ }
113
+
114
+ popupContent.appendChild(templateContent);
115
+ } else {
116
+ templateContent = popupContent.querySelector(
117
+ `[data-modalpopupcontent=${triggerName}]`,
118
+ );
119
+ }
120
+
121
+ const activateDelay = Number(this.globalSettings.activateDelay) || 0;
122
+ if (activateDelay > 0) {
123
+ templateContent.classList.remove("active");
124
+ window.setTimeout(() => {
125
+ templateContent.classList.add("active");
126
+ }, activateDelay);
127
+ } else {
128
+ templateContent.classList.add("active");
129
+ }
130
+ requestAnimationFrame(() => {
131
+ modalPopup.classList.add("open");
132
+ document.documentElement.classList.add("lock-position");
133
+ if (this.globalSettings.lenis) {
134
+ document.body.dataset.lenisPrevent = "true";
135
+ }
136
+ });
137
+ this.handleCloseButtonClicks();
138
+ }
139
+ closePopup(modalPopup) {
140
+ if (!modalPopup) {
141
+ return;
142
+ }
143
+ modalPopup.classList.remove("open");
144
+ document.documentElement.classList.remove("lock-position");
145
+ if (this.globalSettings.lenis) {
146
+ delete document.body.dataset.lenisPrevent;
147
+ }
148
+ const popupContent = modalPopup.querySelector(
149
+ ".modal-controller-popup__content",
150
+ );
151
+
152
+ if (popupContent) {
153
+ const activeContents = popupContent.querySelectorAll(
154
+ "[data-modalpopupcontent].active",
155
+ );
156
+ const closeDelay = Number(this.globalSettings.closeDelay) || 0;
157
+ const closingClass = this.globalSettings.closingClass;
158
+
159
+ if (closeDelay > 0 && closingClass) {
160
+ activeContents.forEach((activeContent) => {
161
+ activeContent.classList.add(closingClass);
162
+ });
163
+ setTimeout(() => {
164
+ activeContents.forEach((activeContent) => {
165
+ activeContent.classList.remove(closingClass);
166
+ });
167
+ }, closeDelay);
168
+ }
169
+
170
+ activeContents.forEach((activeContent) => {
171
+ activeContent.classList.remove("active");
172
+ });
173
+ }
174
+ }
175
+ closePopupOnClickOutside(event, modalPopup) {
176
+ if (event.target === modalPopup) {
177
+ this.closePopup(modalPopup);
178
+ }
179
+ }
180
+ setGlobalSettings(settings = {}) {
181
+ this.globalSettings = { ...this.globalSettings, ...settings };
182
+ }
183
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "useTabs": true,
3
+ "overrides": [
4
+ {
5
+ "files": "*.test.js",
6
+ "options": {
7
+ "semi": true
8
+ }
9
+ },
10
+ {
11
+ "files": ["*.js", "*.css", "*.scss"],
12
+ "options": {
13
+ "useTabs": true,
14
+ "semi": true,
15
+ "singleQuote": true,
16
+ "trailingComma": "none",
17
+ "tabWidth": 4,
18
+ "bracketSpacing": false
19
+ }
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,89 @@
1
+ # onion-videocontroller
2
+
3
+ Multi format video player with optional modal pop up.
4
+ The videocontroller houses multiple video implementations as modules which it calls upon depending on the type of video the user wishes to play. This way all the necessary code plus lazyloading optimisations can be implemented separately for each video type.
5
+ Given that the videocontroller builds a dictionary of all the video containers and video triggers that have been passed to it, it can do things like stop currently playing videos when a new video is started, regardless of which type of video they might be.
6
+
7
+ ## Install via npm or yarn with:
8
+
9
+ `npm install @pernod-ricard-global-cms/onion-videocontroller`
10
+ or
11
+ `yarn add @pernod-ricard-global-cms/onion-videocontroller`
12
+
13
+ ## Import the module in your js file with:
14
+
15
+ `import onion-videocontroller from '@pernod-ricard-global-cms/onion-videocontroller';`
16
+
17
+ Instantiate the class in your js file and pass a reference to an html element that is a parent of the video container.
18
+ In a typical cbl block js file this would be the block element, so it might look something like this.
19
+
20
+ `const videoController = new onion-videocontroller(block);`
21
+
22
+ ## HTML/Twig
23
+
24
+ To get the most functionality out of the box, this package should be installed along with the the cbl component library.
25
+
26
+ https://github.com/Chivas-Brothers/cbl-component-library
27
+
28
+ If you install the fields: video from the component library you will receive 2 twig files with the standardized selection of variables already wired up to attributes in the html. By default they will be copied to the views/components folder but you can choose to not run the install command for the video fields and copy the twigs to wherever you would prefer.
29
+
30
+ `video-component.twig`
31
+ `video-trigger-button.twig`
32
+
33
+ You can then call the twig snippets with an include like this.
34
+
35
+ `<section>`
36
+
37
+ {{ include("components/video-trigger-button.twig", {fields : fields, block : block, blockClassName: blockClassName}, with_context = false) }}
38
+
39
+ {{ include("components/video-component.twig", {fields : fields, block : block, blockClassName: blockClassName}, with_context = false) }}
40
+
41
+ `</section>`
42
+
43
+ The snippets don't need to be positioned in any special relationship to each other except that you need to put them somewhere within the container you intend to pass to the video controller.
44
+
45
+ The included twig files will receive the acf fields that are being passed to the block. Although it can work fine as it is, it is advisable to pass another variable with the classname of your block which will make handling the styling a little easier. You can do this by assigning the string of the classname to the blockClassName twig variable.
46
+ eg:
47
+
48
+ `<section>`
49
+
50
+ {% set blockClassName = 'simple-video-block' %}
51
+
52
+ {{ include("components/video-trigger-button.twig", {fields : fields, block : block, blockClassName: blockClassName}, with_context = false) }}
53
+
54
+ {{ include("components/video-component.twig", {fields : fields, block : block, blockClassName: blockClassName}, with_context = false) }}
55
+
56
+ `</section>`
57
+
58
+ ## Styling
59
+
60
+ You can choose to do all the styling yourself in which case there is nothing left to import. However, there are some basic styles exported as mixins which are very easy to override and can get you to a workable result very quickly. You can import them directly from the package folder into your scss file and then include the mixin in the scope of your parent block class.
61
+
62
+ `@use 'NodeModules/@pernod-ricard-global-cms/onion-videocontroller/vc-styles';`
63
+
64
+ `.parent-block-class { @include vc-styles.basic(); }`
65
+
66
+ There is also a mixin for adding default styling to the pop up modal which can be very handy. You can import that in a similar way, only this time it should be scoped to the html. The modal will be added and removed from the body tag, but overflow will need to added to the html in order to prevent scrolling. This is all build in to the modal styles
67
+
68
+ `@use 'NodeModules/@pernod-ricard-global-cms/onion-videocontroller/vc-styles';`
69
+
70
+ `html { @include vc-styles.modal(); }`
71
+
72
+ ## ACF Fields
73
+
74
+ All the fields in the twig video-component template are intended to correspond to the fields in the generic video field group in the acf custom field groups. This video group can be injected into blocks within a tab or cloned into more nested sections of blocks.
75
+ It is recommended to use this field group as otherwise some of the features of the controller may not work. If you can't use the acf field group for some reason you can still hard code all the variables into the html attribute slots on the video component and trigger. It won't be dynamic but it can still work.
76
+
77
+ ## Other useful features
78
+
79
+ Because it works as a singleton you can instantiate the videocontroller anywhere in your site and access some global methods.
80
+ Eg. Anywhere in the javascript on the page you can do,
81
+
82
+ `const videoController = new videcontroller();`
83
+ `videoController.stopAllVideos();`
84
+
85
+ These methods include:
86
+
87
+ - stopAllVideos(): This will stop all the videos on the page except for ones that have been assigned to autoplay.
88
+ - getGlobalSettings(): Returns the global videcontroller settings.
89
+ - getObjects(): Returns the collection of video containers and triggers that have been found by the controller.
@@ -0,0 +1,6 @@
1
+ //Breakpoints
2
+ $mobile: 375px;
3
+ $tabPortrait: 768px;
4
+ $tabLandscape: 1024px;
5
+ $desktop: 1440px;
6
+ $desktop-fullhd: 1920px;
@@ -0,0 +1,30 @@
1
+ @use './breakpoints';
2
+ @use 'sass:math';
3
+
4
+ @function fontSize($size-px, $screen: '') {
5
+ @if $screen == 'static' {
6
+ @return calc(
7
+ (
8
+ ($size-px / var(--desktop-design-reference)) *
9
+ var(--screen-width-static)
10
+ ) * var(--font-size-multiplier)
11
+ );
12
+ } @else {
13
+ @return calc(
14
+ (($size-px / var(--design-reference)) * var(--font-reference)) *
15
+ var(--font-size-multiplier)
16
+ );
17
+ }
18
+ }
19
+ @function fluidSize($size-px, $screen: '') {
20
+ @if $screen == 'static' {
21
+ @return calc(
22
+ (($size-px / var(--desktop-design-reference))) *
23
+ var(--screen-width-static)
24
+ );
25
+ } @else {
26
+ @return calc(
27
+ (($size-px / var(--design-reference)) * var(--screen-width))
28
+ );
29
+ }
30
+ }