@pernod-ricard-global-cms/jsutils 4.0.0 → 4.0.3
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/jsutils.mjs +50 -36
- package/package.json +4 -4
- package/cypress/e2e/getPercent.cy.js +0 -13
- package/cypress/e2e/isEmailValid.cy.js +0 -22
- package/cypress/e2e/resizeDebouncer.cy.js +0 -5
- package/cypress/fixtures/example.json +0 -5
- package/cypress/plugins/index.js +0 -22
- package/cypress/support/commands.js +0 -25
- package/cypress/support/e2e.js +0 -20
- package/cypress.config.js +0 -11
package/jsutils.mjs
CHANGED
|
@@ -11,17 +11,17 @@ export function isWpAdmin() {
|
|
|
11
11
|
|
|
12
12
|
export function ttfb() {
|
|
13
13
|
new PerformanceObserver((entryList) => {
|
|
14
|
-
const [pageNav] = entryList.getEntriesByType(
|
|
14
|
+
const [pageNav] = entryList.getEntriesByType("navigation");
|
|
15
15
|
const time = pageNav.responseStart;
|
|
16
16
|
console.log(`TTFB: ${time} new`);
|
|
17
17
|
pushData(time);
|
|
18
|
-
}).observe({type:
|
|
18
|
+
}).observe({ type: "navigation", buffered: true });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function pushData(time) {
|
|
22
22
|
window.dataLayer = window.dataLayer || [];
|
|
23
|
-
window.dataLayer.push({ttfb: time});
|
|
24
|
-
console.log(
|
|
23
|
+
window.dataLayer.push({ ttfb: time });
|
|
24
|
+
console.log("ttfb sent");
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -242,6 +242,19 @@ export function footerIntersection(entries, element) {
|
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
/**
|
|
246
|
+
* Dynamically retrieves the swiper css and js and returns a resolved promise when they have both been successfully fetched.
|
|
247
|
+
* @returns {promise}
|
|
248
|
+
*/
|
|
249
|
+
export function getSwiperAssetsV2(options = { css: "bundle" }) {
|
|
250
|
+
const getSwiperJs = () => import(/* webpackChunkName: 'swiper' */ "swiper");
|
|
251
|
+
|
|
252
|
+
const promisedJs = Promise.all([getSwiperJs()]).then((values) => {
|
|
253
|
+
return values;
|
|
254
|
+
});
|
|
255
|
+
return promisedJs;
|
|
256
|
+
}
|
|
257
|
+
|
|
245
258
|
/**
|
|
246
259
|
* Dynamically retrieves the jQuery and returns a resolved promise when it has been successfully fetched.
|
|
247
260
|
* @returns {promise}
|
|
@@ -599,64 +612,65 @@ export function appendPreconnect(domain) {
|
|
|
599
612
|
}
|
|
600
613
|
|
|
601
614
|
/**
|
|
602
|
-
*
|
|
615
|
+
*
|
|
603
616
|
* @param {string} src The URL src to load
|
|
604
617
|
*/
|
|
605
618
|
async function loadScript(src) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
619
|
+
const script = document.createElement("script");
|
|
620
|
+
script.type = "text/javascript";
|
|
621
|
+
script.src = src;
|
|
622
|
+
script.async = true;
|
|
623
|
+
document.head.appendChild(script);
|
|
624
|
+
await new Promise((resolve, reject) => {
|
|
625
|
+
script.onload = resolve;
|
|
626
|
+
script.onerror = () => reject(new Error(`Script load error for ${src}`));
|
|
627
|
+
});
|
|
615
628
|
}
|
|
616
629
|
|
|
617
630
|
/**
|
|
618
|
-
*
|
|
631
|
+
*
|
|
619
632
|
* @param {object} event The click event object
|
|
620
633
|
*/
|
|
621
634
|
async function handleCTBClick(event) {
|
|
622
|
-
|
|
623
635
|
event.preventDefault();
|
|
624
|
-
|
|
625
|
-
if (!window.isCTBLoaded) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
636
|
+
|
|
637
|
+
if (!window.isCTBLoaded) {
|
|
638
|
+
const domain = window.location.hostname;
|
|
639
|
+
// Assuming PR-CLICKTOBUY plugin is enabled to make the script load
|
|
640
|
+
await loadScript(
|
|
641
|
+
`/wp-content/plugins/pr-clicktobuy/public/js/pr-clicktobuy-public.js`
|
|
642
|
+
);
|
|
643
|
+
window.isCTBLoaded = true;
|
|
644
|
+
|
|
645
|
+
// This is important!! Never remove this code
|
|
632
646
|
const clonedEvent = new event.constructor(event.type, event);
|
|
633
647
|
setTimeout(() => {
|
|
634
648
|
event.target.dispatchEvent(clonedEvent);
|
|
635
649
|
}, 500);
|
|
636
|
-
|
|
650
|
+
}
|
|
637
651
|
}
|
|
638
652
|
|
|
639
653
|
/**
|
|
640
|
-
*
|
|
654
|
+
*
|
|
641
655
|
* @param {HTMLElement} element The element which needs to set the Attributes
|
|
642
656
|
*/
|
|
643
657
|
function setAttributesToMenuItem(element) {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
658
|
+
const body = document.querySelector("body");
|
|
659
|
+
const localLang = body.dataset.sitelanguage;
|
|
660
|
+
const locale = localLang.replace(/_/g, "-");
|
|
661
|
+
element.setAttribute("data-ctbuy-lang", locale);
|
|
648
662
|
}
|
|
649
663
|
|
|
650
664
|
/**
|
|
651
|
-
*
|
|
665
|
+
*
|
|
652
666
|
* @param {HTMLElement} block The element CTA which triggers
|
|
653
667
|
*/
|
|
654
668
|
export function ctbCTAClickHandler(block = document) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
669
|
+
const elements = block.querySelectorAll("[data-ctbuy]");
|
|
670
|
+
elements.forEach((element) => {
|
|
671
|
+
setAttributesToMenuItem(element);
|
|
672
|
+
element.addEventListener("click", handleCTBClick);
|
|
673
|
+
});
|
|
660
674
|
}
|
|
661
675
|
|
|
662
676
|
const api = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pernod-ricard-global-cms/jsutils",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Handy collection of Javascript utility functions",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "jsutils.mjs",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"gsap": "^3.10.4",
|
|
22
22
|
"jquery": "^3.6.0",
|
|
23
|
-
"prettier": "^2.5.1"
|
|
23
|
+
"prettier": "^2.5.1",
|
|
24
|
+
"swiper": "^8.4.7"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
|
-
"
|
|
27
|
-
"jsdoc": "^3.6.7"
|
|
27
|
+
"jsdoc": "^4.0.4"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
});
|
package/cypress/plugins/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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) => { ... })
|
package/cypress/support/e2e.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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.config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const { defineConfig } = require('cypress')
|
|
2
|
-
|
|
3
|
-
module.exports = defineConfig({
|
|
4
|
-
e2e: {
|
|
5
|
-
// We've imported your old cypress plugins here.
|
|
6
|
-
// You may want to clean this up later by importing these.
|
|
7
|
-
setupNodeEvents(on, config) {
|
|
8
|
-
return require('./cypress/plugins/index.js')(on, config)
|
|
9
|
-
},
|
|
10
|
-
},
|
|
11
|
-
})
|