@pernod-ricard-global-cms/jsutils 1.7.0 → 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/cypress/fixtures/example.json +5 -0
- package/cypress/integration/getPercent.spec.js +13 -0
- package/cypress/integration/isEmailValid.spec.js +22 -0
- package/cypress/plugins/index.js +22 -0
- package/cypress/support/commands.js +25 -0
- package/cypress/support/index.js +20 -0
- package/cypress.json +1 -0
- package/{jsutils.js → jsutils.mjs} +97 -99
- package/package.json +7 -7
- package/spec/isEmailValid.spec.js +0 -10
- package/spec/isInViewport.spec.js +0 -7
- package/spec/support/jasmine.json +0 -12
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getPercent } from '../../jsutils';
|
|
2
|
+
|
|
3
|
+
describe('A suite to test getPercent()', () => {
|
|
4
|
+
it('passes by rounding down', () => {
|
|
5
|
+
expect(getPercent(30, 10)).to.eq(33);
|
|
6
|
+
});
|
|
7
|
+
it('passes with various numbers', () => {
|
|
8
|
+
expect(getPercent(100, 10)).to.eq(10);
|
|
9
|
+
});
|
|
10
|
+
it('passes by rounding up', () => {
|
|
11
|
+
expect(getPercent(30, 20)).to.eq(67);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import jsutils from '../../jsutils';
|
|
2
|
+
|
|
3
|
+
describe('A suite', () => {
|
|
4
|
+
it('passes with mixed case letters and numbers', () => {
|
|
5
|
+
expect(jsutils.isEmailValid('aS93scFFx@jKoO0908ahdb.com')).to.eq(true);
|
|
6
|
+
});
|
|
7
|
+
it('fails on a string of letters', () => {
|
|
8
|
+
expect(jsutils.isEmailValid('jkahdb')).to.eq(false);
|
|
9
|
+
});
|
|
10
|
+
it('fails with mixed case letters and numbers and no @', () => {
|
|
11
|
+
expect(jsutils.isEmailValid('aS93scFFxjKoO0908ahdb.com')).to.eq(false);
|
|
12
|
+
});
|
|
13
|
+
it('fails with a space in the string', () => {
|
|
14
|
+
expect(jsutils.isEmailValid('hello@te st.com')).to.eq(false);
|
|
15
|
+
});
|
|
16
|
+
it('fails with a £ symbol', () => {
|
|
17
|
+
expect(jsutils.isEmailValid('hello@te£st.com')).to.eq(false);
|
|
18
|
+
});
|
|
19
|
+
it('fails with a § symbol', () => {
|
|
20
|
+
expect(jsutils.isEmailValid('hello@te£st.com')).to.eq(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="cypress" />
|
|
2
|
+
// ***********************************************************
|
|
3
|
+
// This example plugins/index.js can be used to load plugins
|
|
4
|
+
//
|
|
5
|
+
// You can change the location of this file or turn off loading
|
|
6
|
+
// the plugins file with the 'pluginsFile' configuration option.
|
|
7
|
+
//
|
|
8
|
+
// You can read more here:
|
|
9
|
+
// https://on.cypress.io/plugins-guide
|
|
10
|
+
// ***********************************************************
|
|
11
|
+
|
|
12
|
+
// This function is called when a project is opened or re-opened (e.g. due to
|
|
13
|
+
// the project's config changing)
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @type {Cypress.PluginConfig}
|
|
17
|
+
*/
|
|
18
|
+
// eslint-disable-next-line no-unused-vars
|
|
19
|
+
module.exports = (on, config) => {
|
|
20
|
+
// `on` is used to hook into various events Cypress emits
|
|
21
|
+
// `config` is the resolved Cypress config
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// ***********************************************
|
|
2
|
+
// This example commands.js shows you how to
|
|
3
|
+
// create various custom commands and overwrite
|
|
4
|
+
// existing commands.
|
|
5
|
+
//
|
|
6
|
+
// For more comprehensive examples of custom
|
|
7
|
+
// commands please read more here:
|
|
8
|
+
// https://on.cypress.io/custom-commands
|
|
9
|
+
// ***********************************************
|
|
10
|
+
//
|
|
11
|
+
//
|
|
12
|
+
// -- This is a parent command --
|
|
13
|
+
// Cypress.Commands.add('login', (email, password) => { ... })
|
|
14
|
+
//
|
|
15
|
+
//
|
|
16
|
+
// -- This is a child command --
|
|
17
|
+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
|
|
18
|
+
//
|
|
19
|
+
//
|
|
20
|
+
// -- This is a dual command --
|
|
21
|
+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
|
|
22
|
+
//
|
|
23
|
+
//
|
|
24
|
+
// -- This will overwrite an existing command --
|
|
25
|
+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// ***********************************************************
|
|
2
|
+
// This example support/index.js is processed and
|
|
3
|
+
// loaded automatically before your test files.
|
|
4
|
+
//
|
|
5
|
+
// This is a great place to put global configuration and
|
|
6
|
+
// behavior that modifies Cypress.
|
|
7
|
+
//
|
|
8
|
+
// You can change the location of this file or turn off
|
|
9
|
+
// automatically serving support files with the
|
|
10
|
+
// 'supportFile' configuration option.
|
|
11
|
+
//
|
|
12
|
+
// You can read more here:
|
|
13
|
+
// https://on.cypress.io/configuration
|
|
14
|
+
// ***********************************************************
|
|
15
|
+
|
|
16
|
+
// Import commands.js using ES2015 syntax:
|
|
17
|
+
import './commands'
|
|
18
|
+
|
|
19
|
+
// Alternatively you can use CommonJS syntax:
|
|
20
|
+
// require('./commands')
|
package/cypress.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Function for check whether the code is running within the Wordpress admin page. Checks for wp-admin class.
|
|
6
|
+
* @returns {Boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function isWpAdmin() {
|
|
9
|
+
return document.body.classList.contains("wp-admin") ? true : false;
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
/**
|
|
5
13
|
* This function accepts an html element and returns the position of that element on the page.
|
|
6
14
|
*
|
|
@@ -17,8 +25,8 @@ export function getPosition(element) {
|
|
|
17
25
|
element = element.offsetParent;
|
|
18
26
|
}
|
|
19
27
|
// Quirks mode safety - in case of missing DOCTYPE
|
|
20
|
-
if (scrollElementTag ===
|
|
21
|
-
yPosition += document.querySelector(
|
|
28
|
+
if (scrollElementTag === "BODY") {
|
|
29
|
+
yPosition += document.querySelector("body").scrollTop;
|
|
22
30
|
}
|
|
23
31
|
return { x: xPosition, y: yPosition };
|
|
24
32
|
}
|
|
@@ -30,21 +38,21 @@ export function getPosition(element) {
|
|
|
30
38
|
*/
|
|
31
39
|
export function toggleClassByValidity(input, button) {
|
|
32
40
|
try {
|
|
33
|
-
input.addEventListener(
|
|
41
|
+
input.addEventListener("input", () => {
|
|
34
42
|
if (input.validity.valid && input.value) {
|
|
35
|
-
if (!button.classList.contains(
|
|
36
|
-
button.classList.add(
|
|
43
|
+
if (!button.classList.contains("valid")) {
|
|
44
|
+
button.classList.add("valid");
|
|
37
45
|
}
|
|
38
|
-
if (!input.classList.contains(
|
|
39
|
-
input.classList.add(
|
|
46
|
+
if (!input.classList.contains("valid")) {
|
|
47
|
+
input.classList.add("valid");
|
|
40
48
|
}
|
|
41
49
|
} else {
|
|
42
|
-
button.classList.remove(
|
|
43
|
-
input.classList.remove(
|
|
50
|
+
button.classList.remove("valid");
|
|
51
|
+
input.classList.remove("valid");
|
|
44
52
|
}
|
|
45
53
|
});
|
|
46
54
|
} catch (error) {
|
|
47
|
-
console.error(
|
|
55
|
+
console.error("jsutils.js ~ toggleClassByValidity ~ error", error);
|
|
48
56
|
}
|
|
49
57
|
}
|
|
50
58
|
|
|
@@ -92,16 +100,16 @@ export function loadCss(assetKey, options = { css: true }) {
|
|
|
92
100
|
export function checkDevice() {
|
|
93
101
|
try {
|
|
94
102
|
const deviceAgent = navigator.userAgent.toLowerCase();
|
|
95
|
-
const htmlElement = document.querySelector(
|
|
103
|
+
const htmlElement = document.querySelector("html");
|
|
96
104
|
if (
|
|
97
|
-
|
|
105
|
+
"ontouchstart" in globalThis &&
|
|
98
106
|
window.screen.width * window.devicePixelRatio >= 2048 &&
|
|
99
107
|
window.screen.width < window.screen.height
|
|
100
108
|
) {
|
|
101
|
-
htmlElement.classList.add(
|
|
109
|
+
htmlElement.classList.add("highResTabletPortrait");
|
|
102
110
|
}
|
|
103
|
-
if (
|
|
104
|
-
htmlElement.classList.add(
|
|
111
|
+
if ("ontouchstart" in globalThis) {
|
|
112
|
+
htmlElement.classList.add("touch");
|
|
105
113
|
}
|
|
106
114
|
if (navigator.connection) {
|
|
107
115
|
htmlElement.classList.add(navigator.connection.effectiveType);
|
|
@@ -109,42 +117,42 @@ export function checkDevice() {
|
|
|
109
117
|
if (navigator.platform) {
|
|
110
118
|
let platform = navigator.platform.toLowerCase();
|
|
111
119
|
let platformArray = [platform];
|
|
112
|
-
if (platform.search(
|
|
113
|
-
platformArray = platform.split(
|
|
120
|
+
if (platform.search("-")) {
|
|
121
|
+
platformArray = platform.split("-");
|
|
114
122
|
}
|
|
115
|
-
if (platform.search(
|
|
116
|
-
platformArray = platform.split(
|
|
123
|
+
if (platform.search(" ")) {
|
|
124
|
+
platformArray = platform.split(" ");
|
|
117
125
|
}
|
|
118
126
|
htmlElement.classList.add(...platformArray);
|
|
119
127
|
}
|
|
120
128
|
if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
|
|
121
|
-
htmlElement.classList.add(
|
|
122
|
-
htmlElement.classList.add(
|
|
129
|
+
htmlElement.classList.add("ios");
|
|
130
|
+
htmlElement.classList.add("mobile");
|
|
123
131
|
}
|
|
124
132
|
if (deviceAgent.match(/(windows)/)) {
|
|
125
|
-
htmlElement.classList.add(
|
|
133
|
+
htmlElement.classList.add("windows");
|
|
126
134
|
}
|
|
127
135
|
if (deviceAgent.match(/(macintosh)/)) {
|
|
128
|
-
htmlElement.classList.add(
|
|
136
|
+
htmlElement.classList.add("mac");
|
|
129
137
|
}
|
|
130
138
|
if (deviceAgent.match(/(android)/)) {
|
|
131
|
-
htmlElement.classList.add(
|
|
139
|
+
htmlElement.classList.add("android");
|
|
132
140
|
}
|
|
133
|
-
if (navigator.userAgent.search(
|
|
134
|
-
htmlElement.classList.add(
|
|
135
|
-
} else if (navigator.userAgent.search(
|
|
136
|
-
htmlElement.classList.add(
|
|
137
|
-
} else if (navigator.userAgent.search(
|
|
138
|
-
htmlElement.classList.add(
|
|
139
|
-
} else if (navigator.userAgent.search(
|
|
140
|
-
htmlElement.classList.add(
|
|
141
|
+
if (navigator.userAgent.search("MSIE") >= 0) {
|
|
142
|
+
htmlElement.classList.add("ie");
|
|
143
|
+
} else if (navigator.userAgent.search("Edge") >= 0) {
|
|
144
|
+
htmlElement.classList.add("edge-legacy");
|
|
145
|
+
} else if (navigator.userAgent.search("Chrome") >= 0) {
|
|
146
|
+
htmlElement.classList.add("chrome");
|
|
147
|
+
} else if (navigator.userAgent.search("Firefox") >= 0) {
|
|
148
|
+
htmlElement.classList.add("firefox");
|
|
141
149
|
} else if (
|
|
142
|
-
navigator.userAgent.search(
|
|
143
|
-
navigator.userAgent.search(
|
|
150
|
+
navigator.userAgent.search("Safari") >= 0 &&
|
|
151
|
+
navigator.userAgent.search("Chrome") < 0
|
|
144
152
|
) {
|
|
145
|
-
htmlElement.classList.add(
|
|
146
|
-
} else if (navigator.userAgent.search(
|
|
147
|
-
htmlElement.classList.add(
|
|
153
|
+
htmlElement.classList.add("safari");
|
|
154
|
+
} else if (navigator.userAgent.search("Opera") >= 0) {
|
|
155
|
+
htmlElement.classList.add("opera");
|
|
148
156
|
}
|
|
149
157
|
} catch (error) {
|
|
150
158
|
console.error(error);
|
|
@@ -161,22 +169,22 @@ export function checkDevice() {
|
|
|
161
169
|
export async function waitForLoad(img, delayedFunction) {
|
|
162
170
|
const loaded = new Promise((resolve) => {
|
|
163
171
|
if (img.complete) {
|
|
164
|
-
if (typeof delayedFunction ===
|
|
172
|
+
if (typeof delayedFunction === "function") {
|
|
165
173
|
delayedFunction();
|
|
166
174
|
}
|
|
167
175
|
return resolve(true);
|
|
168
176
|
}
|
|
169
177
|
img.addEventListener(
|
|
170
|
-
|
|
178
|
+
"load",
|
|
171
179
|
() => {
|
|
172
|
-
if (typeof delayedFunction ===
|
|
180
|
+
if (typeof delayedFunction === "function") {
|
|
173
181
|
delayedFunction();
|
|
174
182
|
}
|
|
175
183
|
return resolve(true);
|
|
176
184
|
},
|
|
177
185
|
{ once: true }
|
|
178
186
|
);
|
|
179
|
-
}).catch((error) => console.log(error,
|
|
187
|
+
}).catch((error) => console.log(error, "could not load the image", img));
|
|
180
188
|
return loaded;
|
|
181
189
|
}
|
|
182
190
|
|
|
@@ -189,7 +197,7 @@ export async function supportsWebp() {
|
|
|
189
197
|
// eslint-disable-next-line no-restricted-globals
|
|
190
198
|
if (!self.createImageBitmap) return false;
|
|
191
199
|
const webpData =
|
|
192
|
-
|
|
200
|
+
"data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
|
|
193
201
|
const blob = await fetch(webpData).then((r) => r.blob());
|
|
194
202
|
return createImageBitmap(blob).then(
|
|
195
203
|
() => true,
|
|
@@ -213,7 +221,7 @@ export function footerIntersection(entries, element) {
|
|
|
213
221
|
const { height } = entry.boundingClientRect;
|
|
214
222
|
element.style.bottom = `${height}px`;
|
|
215
223
|
} else {
|
|
216
|
-
element.style.bottom =
|
|
224
|
+
element.style.bottom = "0px";
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
});
|
|
@@ -223,21 +231,13 @@ export function footerIntersection(entries, element) {
|
|
|
223
231
|
* Dynamically retrieves the swiper css and js and returns a resolved promise when they have both been successfully fetched.
|
|
224
232
|
* @returns {promise}
|
|
225
233
|
*/
|
|
226
|
-
export function
|
|
234
|
+
export function getSwiperAssetsV2(options = { css: "bundle" }) {
|
|
227
235
|
const getSwiperJs = () =>
|
|
228
|
-
import(/* webpackChunkName: 'swiper' */
|
|
229
|
-
|
|
230
|
-
const getSwiperCss = () =>
|
|
231
|
-
import(
|
|
232
|
-
/* webpackChunkName: 'swiper' */
|
|
233
|
-
'../../swiper/swiper-bundle.min.css'
|
|
234
|
-
);
|
|
236
|
+
import(/* webpackChunkName: 'swiper' */ "swiper/swiper.esm");
|
|
235
237
|
|
|
236
|
-
const promisedJs = Promise.all([getSwiperJs()
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
);
|
|
238
|
+
const promisedJs = Promise.all([getSwiperJs()]).then((values) => {
|
|
239
|
+
return values;
|
|
240
|
+
});
|
|
241
241
|
return promisedJs;
|
|
242
242
|
}
|
|
243
243
|
|
|
@@ -248,9 +248,7 @@ export function getSwiperAssets() {
|
|
|
248
248
|
export function getJquery() {
|
|
249
249
|
if (!window.jQuery) {
|
|
250
250
|
const importCode = () =>
|
|
251
|
-
import(
|
|
252
|
-
/* webpackChunkName: 'jquery' */ '../../jquery/dist/jquery.min.js'
|
|
253
|
-
);
|
|
251
|
+
import(/* webpackChunkName: 'jquery' */ "jquery/dist/jquery.min.js");
|
|
254
252
|
return importCode();
|
|
255
253
|
}
|
|
256
254
|
return Promise.resolve();
|
|
@@ -262,13 +260,13 @@ export function getJquery() {
|
|
|
262
260
|
*/
|
|
263
261
|
export function getGsap() {
|
|
264
262
|
const gsapCore = () =>
|
|
265
|
-
import(
|
|
263
|
+
import("gsap/dist/gsap.min.js").then((gsapObj) => {
|
|
266
264
|
const { gsap } = gsapObj;
|
|
267
265
|
return gsap;
|
|
268
266
|
});
|
|
269
267
|
|
|
270
268
|
const gsapPlugin = () =>
|
|
271
|
-
import(
|
|
269
|
+
import("gsap/dist/ScrollTrigger.min.js").then((scrollObj) => {
|
|
272
270
|
const ScrollTrigger = scrollObj;
|
|
273
271
|
return ScrollTrigger;
|
|
274
272
|
});
|
|
@@ -318,7 +316,7 @@ export function mobileCheck() {
|
|
|
318
316
|
*/
|
|
319
317
|
export function resizeDebouncer(debouncedFunction, time = 250) {
|
|
320
318
|
let resizeTimer;
|
|
321
|
-
window.addEventListener(
|
|
319
|
+
window.addEventListener("resize", () => {
|
|
322
320
|
clearTimeout(resizeTimer);
|
|
323
321
|
resizeTimer = setTimeout(() => {
|
|
324
322
|
debouncedFunction();
|
|
@@ -358,14 +356,14 @@ export function injectYouTubeIframeScript() {
|
|
|
358
356
|
if (globalThis.YT) {
|
|
359
357
|
return resolve();
|
|
360
358
|
}
|
|
361
|
-
const tag = document.createElement(
|
|
362
|
-
tag.id =
|
|
363
|
-
tag.src =
|
|
359
|
+
const tag = document.createElement("script");
|
|
360
|
+
tag.id = "iframe-api";
|
|
361
|
+
tag.src = "https://www.youtube.com/iframe_api";
|
|
364
362
|
|
|
365
|
-
const firstScriptTag = document.getElementsByTagName(
|
|
363
|
+
const firstScriptTag = document.getElementsByTagName("script")[0];
|
|
366
364
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
|
367
365
|
|
|
368
|
-
tag.addEventListener(
|
|
366
|
+
tag.addEventListener("load", () => {
|
|
369
367
|
if (!YT.loaded) {
|
|
370
368
|
const loadingCheck = setInterval(() => {
|
|
371
369
|
if (YT.loaded) {
|
|
@@ -383,34 +381,34 @@ export function injectYouTubeIframeScript() {
|
|
|
383
381
|
}
|
|
384
382
|
|
|
385
383
|
export function fallbackCopyToClipboard(text) {
|
|
386
|
-
const textArea = document.createElement(
|
|
384
|
+
const textArea = document.createElement("textarea");
|
|
387
385
|
textArea.value = text;
|
|
388
386
|
|
|
389
387
|
// Avoid scrolling to bottom
|
|
390
|
-
textArea.style.top =
|
|
391
|
-
textArea.style.left =
|
|
392
|
-
textArea.style.position =
|
|
388
|
+
textArea.style.top = "0";
|
|
389
|
+
textArea.style.left = "0";
|
|
390
|
+
textArea.style.position = "fixed";
|
|
393
391
|
|
|
394
392
|
document.body.appendChild(textArea);
|
|
395
393
|
textArea.focus();
|
|
396
394
|
textArea.select();
|
|
397
395
|
|
|
398
396
|
try {
|
|
399
|
-
const successful = document.execCommand(
|
|
400
|
-
const msg = successful ?
|
|
397
|
+
const successful = document.execCommand("copy");
|
|
398
|
+
const msg = successful ? "successful" : "unsuccessful";
|
|
401
399
|
console.log(`Fallback: Copying text command was ${msg}`);
|
|
402
400
|
} catch (err) {
|
|
403
|
-
console.error(
|
|
401
|
+
console.error("Fallback: Oops, unable to copy", err);
|
|
404
402
|
}
|
|
405
403
|
|
|
406
404
|
document.body.removeChild(textArea);
|
|
407
405
|
}
|
|
408
406
|
|
|
409
407
|
export function copyToClipboard() {
|
|
410
|
-
const copyLinks = document.querySelectorAll(
|
|
408
|
+
const copyLinks = document.querySelectorAll(".copy-to-clipboard");
|
|
411
409
|
let timeout;
|
|
412
410
|
copyLinks.forEach((link) => {
|
|
413
|
-
link.addEventListener(
|
|
411
|
+
link.addEventListener("click", function () {
|
|
414
412
|
const copyToClipboardDone = link.nextElementSibling;
|
|
415
413
|
if (!navigator.clipboard) {
|
|
416
414
|
fallbackCopyToClipboard(this.dataset.url);
|
|
@@ -419,23 +417,23 @@ export function copyToClipboard() {
|
|
|
419
417
|
|
|
420
418
|
navigator.clipboard.writeText(this.dataset.url).then(
|
|
421
419
|
function () {
|
|
422
|
-
console.log(
|
|
420
|
+
console.log("Copying to clipboard was successful!");
|
|
423
421
|
},
|
|
424
422
|
function (err) {
|
|
425
|
-
console.error(
|
|
423
|
+
console.error("Could not copy text: ", err);
|
|
426
424
|
}
|
|
427
425
|
);
|
|
428
426
|
|
|
429
427
|
if (
|
|
430
428
|
copyToClipboardDone &&
|
|
431
429
|
copyToClipboardDone.classList &&
|
|
432
|
-
copyToClipboardDone.classList.contains(
|
|
430
|
+
copyToClipboardDone.classList.contains("sharing__clipboard-done")
|
|
433
431
|
) {
|
|
434
432
|
clearTimeout(timeout);
|
|
435
|
-
copyToClipboardDone.classList.remove(
|
|
433
|
+
copyToClipboardDone.classList.remove("hidden");
|
|
436
434
|
|
|
437
435
|
timeout = setTimeout(() => {
|
|
438
|
-
copyToClipboardDone.classList.add(
|
|
436
|
+
copyToClipboardDone.classList.add("hidden");
|
|
439
437
|
}, 2000);
|
|
440
438
|
}
|
|
441
439
|
});
|
|
@@ -515,13 +513,13 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
515
513
|
|
|
516
514
|
if (Math.abs(delx) > pixels || Math.abs(dely) > pixels) {
|
|
517
515
|
if (Math.abs(delx) > Math.abs(dely)) {
|
|
518
|
-
if (delx > 0) return
|
|
519
|
-
else return
|
|
516
|
+
if (delx > 0) return "right";
|
|
517
|
+
else return "left";
|
|
520
518
|
} else if (Math.abs(delx) < Math.abs(dely)) {
|
|
521
|
-
if (dely > 0) return
|
|
522
|
-
else return
|
|
519
|
+
if (dely > 0) return "down";
|
|
520
|
+
else return "up";
|
|
523
521
|
}
|
|
524
|
-
} else return
|
|
522
|
+
} else return "tap";
|
|
525
523
|
}
|
|
526
524
|
|
|
527
525
|
function touchStart(event) {
|
|
@@ -529,10 +527,10 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
529
527
|
touchstartY = event.changedTouches[0].screenY;
|
|
530
528
|
}
|
|
531
529
|
|
|
532
|
-
element.addEventListener(
|
|
530
|
+
element.addEventListener("touchstart", () => touchStart(event), false);
|
|
533
531
|
|
|
534
532
|
element.addEventListener(
|
|
535
|
-
|
|
533
|
+
"touchend",
|
|
536
534
|
function (event) {
|
|
537
535
|
touchendX = event.changedTouches[0].screenX;
|
|
538
536
|
touchendY = event.changedTouches[0].screenY;
|
|
@@ -540,9 +538,9 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
540
538
|
},
|
|
541
539
|
false
|
|
542
540
|
);
|
|
543
|
-
if (removeHandlers ===
|
|
544
|
-
element.removeEventListener(
|
|
545
|
-
element.removeEventListener(
|
|
541
|
+
if (removeHandlers === "remove") {
|
|
542
|
+
element.removeEventListener("touchstart", touchStart);
|
|
543
|
+
element.removeEventListener("touchend", handleGesture);
|
|
546
544
|
return;
|
|
547
545
|
}
|
|
548
546
|
}
|
|
@@ -554,12 +552,12 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
554
552
|
*/
|
|
555
553
|
export function checkIosVersion() {
|
|
556
554
|
const agent = window.navigator.userAgent,
|
|
557
|
-
start = agent.indexOf(
|
|
555
|
+
start = agent.indexOf("OS ");
|
|
558
556
|
if (
|
|
559
|
-
(agent.indexOf(
|
|
557
|
+
(agent.indexOf("iPhone") > -1 || agent.indexOf("iPad") > -1) &&
|
|
560
558
|
start > -1
|
|
561
559
|
) {
|
|
562
|
-
return window.Number(agent.substr(start + 3, 3).replace(
|
|
560
|
+
return window.Number(agent.substr(start + 3, 3).replace("_", "."));
|
|
563
561
|
}
|
|
564
562
|
return 0;
|
|
565
563
|
}
|
|
@@ -572,11 +570,11 @@ export function checkIosVersion() {
|
|
|
572
570
|
export function appendPreconnect(domain) {
|
|
573
571
|
try {
|
|
574
572
|
if (!domain) {
|
|
575
|
-
console.log(
|
|
573
|
+
console.log("The domain was missing or broken...");
|
|
576
574
|
return;
|
|
577
575
|
}
|
|
578
|
-
const link = document.createElement(
|
|
579
|
-
link.rel =
|
|
576
|
+
const link = document.createElement("link");
|
|
577
|
+
link.rel = "preconnect";
|
|
580
578
|
link.href = domain;
|
|
581
579
|
document.head.appendChild(link);
|
|
582
580
|
return;
|
|
@@ -592,9 +590,9 @@ const api = {
|
|
|
592
590
|
eventListenerDebouncer,
|
|
593
591
|
footerIntersection,
|
|
594
592
|
getPosition,
|
|
595
|
-
getSwiperAssets,
|
|
596
593
|
getGsap,
|
|
597
594
|
getJquery,
|
|
595
|
+
getSwiperAssetsV2,
|
|
598
596
|
inCriticalCssConfig,
|
|
599
597
|
injectYouTubeIframeScript,
|
|
600
598
|
isEmailValid,
|
|
@@ -609,6 +607,6 @@ const api = {
|
|
|
609
607
|
getElementStyles,
|
|
610
608
|
getPercent,
|
|
611
609
|
checkIosVersion,
|
|
612
|
-
appendPreconnect
|
|
610
|
+
appendPreconnect,
|
|
613
611
|
};
|
|
614
612
|
export default api;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pernod-ricard-global-cms/jsutils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Handy collection of Javascript utility functions",
|
|
5
|
-
"type": "
|
|
6
|
-
"main": "jsutils.
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"main": "jsutils.mjs",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "cypress"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/Chivas-Brothers/jsUtils#readme",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"gsap": "^3.
|
|
21
|
+
"gsap": "^3.10.4",
|
|
22
22
|
"jquery": "^3.6.0",
|
|
23
23
|
"prettier": "^2.5.1",
|
|
24
|
-
"swiper": "^
|
|
24
|
+
"swiper": "^8.1.4"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"
|
|
27
|
+
"cypress": "^9.6.1",
|
|
28
28
|
"jsdoc": "^3.6.7"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import jsutils from "../jsutils.js";
|
|
2
|
-
|
|
3
|
-
describe("A suite", function() {
|
|
4
|
-
it("fails on a string of letters", function() {
|
|
5
|
-
expect(jsutils.isEmailValid('jkahdb')).toBe(false);
|
|
6
|
-
});
|
|
7
|
-
it("passes with mixed case letters and numbers", function() {
|
|
8
|
-
expect(jsutils.isEmailValid('aS93scFFx@jKoO0908ahdb.com')).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
});
|