@pernod-ricard-global-cms/jsutils 1.7.1 → 2.1.2
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} +90 -101
- 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
|
+
{}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @returns {Boolean}
|
|
7
7
|
*/
|
|
8
8
|
export function isWpAdmin() {
|
|
9
|
-
return document.body.classList.contains(
|
|
9
|
+
return document.body.classList.contains("wp-admin") ? true : false;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -25,8 +25,8 @@ export function getPosition(element) {
|
|
|
25
25
|
element = element.offsetParent;
|
|
26
26
|
}
|
|
27
27
|
// Quirks mode safety - in case of missing DOCTYPE
|
|
28
|
-
if (scrollElementTag ===
|
|
29
|
-
yPosition += document.querySelector(
|
|
28
|
+
if (scrollElementTag === "BODY") {
|
|
29
|
+
yPosition += document.querySelector("body").scrollTop;
|
|
30
30
|
}
|
|
31
31
|
return { x: xPosition, y: yPosition };
|
|
32
32
|
}
|
|
@@ -38,21 +38,21 @@ export function getPosition(element) {
|
|
|
38
38
|
*/
|
|
39
39
|
export function toggleClassByValidity(input, button) {
|
|
40
40
|
try {
|
|
41
|
-
input.addEventListener(
|
|
41
|
+
input.addEventListener("input", () => {
|
|
42
42
|
if (input.validity.valid && input.value) {
|
|
43
|
-
if (!button.classList.contains(
|
|
44
|
-
button.classList.add(
|
|
43
|
+
if (!button.classList.contains("valid")) {
|
|
44
|
+
button.classList.add("valid");
|
|
45
45
|
}
|
|
46
|
-
if (!input.classList.contains(
|
|
47
|
-
input.classList.add(
|
|
46
|
+
if (!input.classList.contains("valid")) {
|
|
47
|
+
input.classList.add("valid");
|
|
48
48
|
}
|
|
49
49
|
} else {
|
|
50
|
-
button.classList.remove(
|
|
51
|
-
input.classList.remove(
|
|
50
|
+
button.classList.remove("valid");
|
|
51
|
+
input.classList.remove("valid");
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
} catch (error) {
|
|
55
|
-
console.error(
|
|
55
|
+
console.error("jsutils.js ~ toggleClassByValidity ~ error", error);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
@@ -100,16 +100,16 @@ export function loadCss(assetKey, options = { css: true }) {
|
|
|
100
100
|
export function checkDevice() {
|
|
101
101
|
try {
|
|
102
102
|
const deviceAgent = navigator.userAgent.toLowerCase();
|
|
103
|
-
const htmlElement = document.querySelector(
|
|
103
|
+
const htmlElement = document.querySelector("html");
|
|
104
104
|
if (
|
|
105
|
-
|
|
105
|
+
"ontouchstart" in globalThis &&
|
|
106
106
|
window.screen.width * window.devicePixelRatio >= 2048 &&
|
|
107
107
|
window.screen.width < window.screen.height
|
|
108
108
|
) {
|
|
109
|
-
htmlElement.classList.add(
|
|
109
|
+
htmlElement.classList.add("highResTabletPortrait");
|
|
110
110
|
}
|
|
111
|
-
if (
|
|
112
|
-
htmlElement.classList.add(
|
|
111
|
+
if ("ontouchstart" in globalThis) {
|
|
112
|
+
htmlElement.classList.add("touch");
|
|
113
113
|
}
|
|
114
114
|
if (navigator.connection) {
|
|
115
115
|
htmlElement.classList.add(navigator.connection.effectiveType);
|
|
@@ -117,42 +117,42 @@ export function checkDevice() {
|
|
|
117
117
|
if (navigator.platform) {
|
|
118
118
|
let platform = navigator.platform.toLowerCase();
|
|
119
119
|
let platformArray = [platform];
|
|
120
|
-
if (platform.search(
|
|
121
|
-
platformArray = platform.split(
|
|
120
|
+
if (platform.search("-")) {
|
|
121
|
+
platformArray = platform.split("-");
|
|
122
122
|
}
|
|
123
|
-
if (platform.search(
|
|
124
|
-
platformArray = platform.split(
|
|
123
|
+
if (platform.search(" ")) {
|
|
124
|
+
platformArray = platform.split(" ");
|
|
125
125
|
}
|
|
126
126
|
htmlElement.classList.add(...platformArray);
|
|
127
127
|
}
|
|
128
128
|
if (deviceAgent.match(/(iphone|ipod|ipad)/)) {
|
|
129
|
-
htmlElement.classList.add(
|
|
130
|
-
htmlElement.classList.add(
|
|
129
|
+
htmlElement.classList.add("ios");
|
|
130
|
+
htmlElement.classList.add("mobile");
|
|
131
131
|
}
|
|
132
132
|
if (deviceAgent.match(/(windows)/)) {
|
|
133
|
-
htmlElement.classList.add(
|
|
133
|
+
htmlElement.classList.add("windows");
|
|
134
134
|
}
|
|
135
135
|
if (deviceAgent.match(/(macintosh)/)) {
|
|
136
|
-
htmlElement.classList.add(
|
|
136
|
+
htmlElement.classList.add("mac");
|
|
137
137
|
}
|
|
138
138
|
if (deviceAgent.match(/(android)/)) {
|
|
139
|
-
htmlElement.classList.add(
|
|
139
|
+
htmlElement.classList.add("android");
|
|
140
140
|
}
|
|
141
|
-
if (navigator.userAgent.search(
|
|
142
|
-
htmlElement.classList.add(
|
|
143
|
-
} else if (navigator.userAgent.search(
|
|
144
|
-
htmlElement.classList.add(
|
|
145
|
-
} else if (navigator.userAgent.search(
|
|
146
|
-
htmlElement.classList.add(
|
|
147
|
-
} else if (navigator.userAgent.search(
|
|
148
|
-
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");
|
|
149
149
|
} else if (
|
|
150
|
-
navigator.userAgent.search(
|
|
151
|
-
navigator.userAgent.search(
|
|
150
|
+
navigator.userAgent.search("Safari") >= 0 &&
|
|
151
|
+
navigator.userAgent.search("Chrome") < 0
|
|
152
152
|
) {
|
|
153
|
-
htmlElement.classList.add(
|
|
154
|
-
} else if (navigator.userAgent.search(
|
|
155
|
-
htmlElement.classList.add(
|
|
153
|
+
htmlElement.classList.add("safari");
|
|
154
|
+
} else if (navigator.userAgent.search("Opera") >= 0) {
|
|
155
|
+
htmlElement.classList.add("opera");
|
|
156
156
|
}
|
|
157
157
|
} catch (error) {
|
|
158
158
|
console.error(error);
|
|
@@ -169,22 +169,22 @@ export function checkDevice() {
|
|
|
169
169
|
export async function waitForLoad(img, delayedFunction) {
|
|
170
170
|
const loaded = new Promise((resolve) => {
|
|
171
171
|
if (img.complete) {
|
|
172
|
-
if (typeof delayedFunction ===
|
|
172
|
+
if (typeof delayedFunction === "function") {
|
|
173
173
|
delayedFunction();
|
|
174
174
|
}
|
|
175
175
|
return resolve(true);
|
|
176
176
|
}
|
|
177
177
|
img.addEventListener(
|
|
178
|
-
|
|
178
|
+
"load",
|
|
179
179
|
() => {
|
|
180
|
-
if (typeof delayedFunction ===
|
|
180
|
+
if (typeof delayedFunction === "function") {
|
|
181
181
|
delayedFunction();
|
|
182
182
|
}
|
|
183
183
|
return resolve(true);
|
|
184
184
|
},
|
|
185
185
|
{ once: true }
|
|
186
186
|
);
|
|
187
|
-
}).catch((error) => console.log(error,
|
|
187
|
+
}).catch((error) => console.log(error, "could not load the image", img));
|
|
188
188
|
return loaded;
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -197,7 +197,7 @@ export async function supportsWebp() {
|
|
|
197
197
|
// eslint-disable-next-line no-restricted-globals
|
|
198
198
|
if (!self.createImageBitmap) return false;
|
|
199
199
|
const webpData =
|
|
200
|
-
|
|
200
|
+
"data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA=";
|
|
201
201
|
const blob = await fetch(webpData).then((r) => r.blob());
|
|
202
202
|
return createImageBitmap(blob).then(
|
|
203
203
|
() => true,
|
|
@@ -221,7 +221,7 @@ export function footerIntersection(entries, element) {
|
|
|
221
221
|
const { height } = entry.boundingClientRect;
|
|
222
222
|
element.style.bottom = `${height}px`;
|
|
223
223
|
} else {
|
|
224
|
-
element.style.bottom =
|
|
224
|
+
element.style.bottom = "0px";
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
});
|
|
@@ -231,21 +231,12 @@ export function footerIntersection(entries, element) {
|
|
|
231
231
|
* Dynamically retrieves the swiper css and js and returns a resolved promise when they have both been successfully fetched.
|
|
232
232
|
* @returns {promise}
|
|
233
233
|
*/
|
|
234
|
-
export function
|
|
235
|
-
const getSwiperJs = () =>
|
|
236
|
-
import(/* webpackChunkName: 'swiper' */ '../../swiper/swiper-bundle.js');
|
|
237
|
-
|
|
238
|
-
const getSwiperCss = () =>
|
|
239
|
-
import(
|
|
240
|
-
/* webpackChunkName: 'swiper' */
|
|
241
|
-
'../../swiper/swiper-bundle.min.css'
|
|
242
|
-
);
|
|
234
|
+
export function getSwiperAssetsV2(options = { css: "bundle" }) {
|
|
235
|
+
const getSwiperJs = () => import(/* webpackChunkName: 'swiper' */ "swiper");
|
|
243
236
|
|
|
244
|
-
const promisedJs = Promise.all([getSwiperJs()
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
);
|
|
237
|
+
const promisedJs = Promise.all([getSwiperJs()]).then((values) => {
|
|
238
|
+
return values;
|
|
239
|
+
});
|
|
249
240
|
return promisedJs;
|
|
250
241
|
}
|
|
251
242
|
|
|
@@ -256,9 +247,7 @@ export function getSwiperAssets() {
|
|
|
256
247
|
export function getJquery() {
|
|
257
248
|
if (!window.jQuery) {
|
|
258
249
|
const importCode = () =>
|
|
259
|
-
import(
|
|
260
|
-
/* webpackChunkName: 'jquery' */ '../../jquery/dist/jquery.min.js'
|
|
261
|
-
);
|
|
250
|
+
import(/* webpackChunkName: 'jquery' */ "jquery/dist/jquery.min.js");
|
|
262
251
|
return importCode();
|
|
263
252
|
}
|
|
264
253
|
return Promise.resolve();
|
|
@@ -270,13 +259,13 @@ export function getJquery() {
|
|
|
270
259
|
*/
|
|
271
260
|
export function getGsap() {
|
|
272
261
|
const gsapCore = () =>
|
|
273
|
-
import(
|
|
262
|
+
import("gsap/dist/gsap.min.js").then((gsapObj) => {
|
|
274
263
|
const { gsap } = gsapObj;
|
|
275
264
|
return gsap;
|
|
276
265
|
});
|
|
277
266
|
|
|
278
267
|
const gsapPlugin = () =>
|
|
279
|
-
import(
|
|
268
|
+
import("gsap/dist/ScrollTrigger.min.js").then((scrollObj) => {
|
|
280
269
|
const ScrollTrigger = scrollObj;
|
|
281
270
|
return ScrollTrigger;
|
|
282
271
|
});
|
|
@@ -326,7 +315,7 @@ export function mobileCheck() {
|
|
|
326
315
|
*/
|
|
327
316
|
export function resizeDebouncer(debouncedFunction, time = 250) {
|
|
328
317
|
let resizeTimer;
|
|
329
|
-
window.addEventListener(
|
|
318
|
+
window.addEventListener("resize", () => {
|
|
330
319
|
clearTimeout(resizeTimer);
|
|
331
320
|
resizeTimer = setTimeout(() => {
|
|
332
321
|
debouncedFunction();
|
|
@@ -366,14 +355,14 @@ export function injectYouTubeIframeScript() {
|
|
|
366
355
|
if (globalThis.YT) {
|
|
367
356
|
return resolve();
|
|
368
357
|
}
|
|
369
|
-
const tag = document.createElement(
|
|
370
|
-
tag.id =
|
|
371
|
-
tag.src =
|
|
358
|
+
const tag = document.createElement("script");
|
|
359
|
+
tag.id = "iframe-api";
|
|
360
|
+
tag.src = "https://www.youtube.com/iframe_api";
|
|
372
361
|
|
|
373
|
-
const firstScriptTag = document.getElementsByTagName(
|
|
362
|
+
const firstScriptTag = document.getElementsByTagName("script")[0];
|
|
374
363
|
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
|
|
375
364
|
|
|
376
|
-
tag.addEventListener(
|
|
365
|
+
tag.addEventListener("load", () => {
|
|
377
366
|
if (!YT.loaded) {
|
|
378
367
|
const loadingCheck = setInterval(() => {
|
|
379
368
|
if (YT.loaded) {
|
|
@@ -391,34 +380,34 @@ export function injectYouTubeIframeScript() {
|
|
|
391
380
|
}
|
|
392
381
|
|
|
393
382
|
export function fallbackCopyToClipboard(text) {
|
|
394
|
-
const textArea = document.createElement(
|
|
383
|
+
const textArea = document.createElement("textarea");
|
|
395
384
|
textArea.value = text;
|
|
396
385
|
|
|
397
386
|
// Avoid scrolling to bottom
|
|
398
|
-
textArea.style.top =
|
|
399
|
-
textArea.style.left =
|
|
400
|
-
textArea.style.position =
|
|
387
|
+
textArea.style.top = "0";
|
|
388
|
+
textArea.style.left = "0";
|
|
389
|
+
textArea.style.position = "fixed";
|
|
401
390
|
|
|
402
391
|
document.body.appendChild(textArea);
|
|
403
392
|
textArea.focus();
|
|
404
393
|
textArea.select();
|
|
405
394
|
|
|
406
395
|
try {
|
|
407
|
-
const successful = document.execCommand(
|
|
408
|
-
const msg = successful ?
|
|
396
|
+
const successful = document.execCommand("copy");
|
|
397
|
+
const msg = successful ? "successful" : "unsuccessful";
|
|
409
398
|
console.log(`Fallback: Copying text command was ${msg}`);
|
|
410
399
|
} catch (err) {
|
|
411
|
-
console.error(
|
|
400
|
+
console.error("Fallback: Oops, unable to copy", err);
|
|
412
401
|
}
|
|
413
402
|
|
|
414
403
|
document.body.removeChild(textArea);
|
|
415
404
|
}
|
|
416
405
|
|
|
417
406
|
export function copyToClipboard() {
|
|
418
|
-
const copyLinks = document.querySelectorAll(
|
|
407
|
+
const copyLinks = document.querySelectorAll(".copy-to-clipboard");
|
|
419
408
|
let timeout;
|
|
420
409
|
copyLinks.forEach((link) => {
|
|
421
|
-
link.addEventListener(
|
|
410
|
+
link.addEventListener("click", function () {
|
|
422
411
|
const copyToClipboardDone = link.nextElementSibling;
|
|
423
412
|
if (!navigator.clipboard) {
|
|
424
413
|
fallbackCopyToClipboard(this.dataset.url);
|
|
@@ -427,23 +416,23 @@ export function copyToClipboard() {
|
|
|
427
416
|
|
|
428
417
|
navigator.clipboard.writeText(this.dataset.url).then(
|
|
429
418
|
function () {
|
|
430
|
-
console.log(
|
|
419
|
+
console.log("Copying to clipboard was successful!");
|
|
431
420
|
},
|
|
432
421
|
function (err) {
|
|
433
|
-
console.error(
|
|
422
|
+
console.error("Could not copy text: ", err);
|
|
434
423
|
}
|
|
435
424
|
);
|
|
436
425
|
|
|
437
426
|
if (
|
|
438
427
|
copyToClipboardDone &&
|
|
439
428
|
copyToClipboardDone.classList &&
|
|
440
|
-
copyToClipboardDone.classList.contains(
|
|
429
|
+
copyToClipboardDone.classList.contains("sharing__clipboard-done")
|
|
441
430
|
) {
|
|
442
431
|
clearTimeout(timeout);
|
|
443
|
-
copyToClipboardDone.classList.remove(
|
|
432
|
+
copyToClipboardDone.classList.remove("hidden");
|
|
444
433
|
|
|
445
434
|
timeout = setTimeout(() => {
|
|
446
|
-
copyToClipboardDone.classList.add(
|
|
435
|
+
copyToClipboardDone.classList.add("hidden");
|
|
447
436
|
}, 2000);
|
|
448
437
|
}
|
|
449
438
|
});
|
|
@@ -523,13 +512,13 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
523
512
|
|
|
524
513
|
if (Math.abs(delx) > pixels || Math.abs(dely) > pixels) {
|
|
525
514
|
if (Math.abs(delx) > Math.abs(dely)) {
|
|
526
|
-
if (delx > 0) return
|
|
527
|
-
else return
|
|
515
|
+
if (delx > 0) return "right";
|
|
516
|
+
else return "left";
|
|
528
517
|
} else if (Math.abs(delx) < Math.abs(dely)) {
|
|
529
|
-
if (dely > 0) return
|
|
530
|
-
else return
|
|
518
|
+
if (dely > 0) return "down";
|
|
519
|
+
else return "up";
|
|
531
520
|
}
|
|
532
|
-
} else return
|
|
521
|
+
} else return "tap";
|
|
533
522
|
}
|
|
534
523
|
|
|
535
524
|
function touchStart(event) {
|
|
@@ -537,10 +526,10 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
537
526
|
touchstartY = event.changedTouches[0].screenY;
|
|
538
527
|
}
|
|
539
528
|
|
|
540
|
-
element.addEventListener(
|
|
529
|
+
element.addEventListener("touchstart", () => touchStart(event), false);
|
|
541
530
|
|
|
542
531
|
element.addEventListener(
|
|
543
|
-
|
|
532
|
+
"touchend",
|
|
544
533
|
function (event) {
|
|
545
534
|
touchendX = event.changedTouches[0].screenX;
|
|
546
535
|
touchendY = event.changedTouches[0].screenY;
|
|
@@ -548,9 +537,9 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
548
537
|
},
|
|
549
538
|
false
|
|
550
539
|
);
|
|
551
|
-
if (removeHandlers ===
|
|
552
|
-
element.removeEventListener(
|
|
553
|
-
element.removeEventListener(
|
|
540
|
+
if (removeHandlers === "remove") {
|
|
541
|
+
element.removeEventListener("touchstart", touchStart);
|
|
542
|
+
element.removeEventListener("touchend", handleGesture);
|
|
554
543
|
return;
|
|
555
544
|
}
|
|
556
545
|
}
|
|
@@ -562,12 +551,12 @@ export function detectSwipe(element, callback, removeHandlers = false) {
|
|
|
562
551
|
*/
|
|
563
552
|
export function checkIosVersion() {
|
|
564
553
|
const agent = window.navigator.userAgent,
|
|
565
|
-
start = agent.indexOf(
|
|
554
|
+
start = agent.indexOf("OS ");
|
|
566
555
|
if (
|
|
567
|
-
(agent.indexOf(
|
|
556
|
+
(agent.indexOf("iPhone") > -1 || agent.indexOf("iPad") > -1) &&
|
|
568
557
|
start > -1
|
|
569
558
|
) {
|
|
570
|
-
return window.Number(agent.substr(start + 3, 3).replace(
|
|
559
|
+
return window.Number(agent.substr(start + 3, 3).replace("_", "."));
|
|
571
560
|
}
|
|
572
561
|
return 0;
|
|
573
562
|
}
|
|
@@ -580,11 +569,11 @@ export function checkIosVersion() {
|
|
|
580
569
|
export function appendPreconnect(domain) {
|
|
581
570
|
try {
|
|
582
571
|
if (!domain) {
|
|
583
|
-
console.log(
|
|
572
|
+
console.log("The domain was missing or broken...");
|
|
584
573
|
return;
|
|
585
574
|
}
|
|
586
|
-
const link = document.createElement(
|
|
587
|
-
link.rel =
|
|
575
|
+
const link = document.createElement("link");
|
|
576
|
+
link.rel = "preconnect";
|
|
588
577
|
link.href = domain;
|
|
589
578
|
document.head.appendChild(link);
|
|
590
579
|
return;
|
|
@@ -600,9 +589,9 @@ const api = {
|
|
|
600
589
|
eventListenerDebouncer,
|
|
601
590
|
footerIntersection,
|
|
602
591
|
getPosition,
|
|
603
|
-
getSwiperAssets,
|
|
604
592
|
getGsap,
|
|
605
593
|
getJquery,
|
|
594
|
+
getSwiperAssetsV2,
|
|
606
595
|
inCriticalCssConfig,
|
|
607
596
|
injectYouTubeIframeScript,
|
|
608
597
|
isEmailValid,
|
|
@@ -617,6 +606,6 @@ const api = {
|
|
|
617
606
|
getElementStyles,
|
|
618
607
|
getPercent,
|
|
619
608
|
checkIosVersion,
|
|
620
|
-
appendPreconnect
|
|
609
|
+
appendPreconnect,
|
|
621
610
|
};
|
|
622
611
|
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.2",
|
|
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
|
-
});
|