@pernod-ricard-global-cms/jsutils 3.2.2 → 4.0.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/jsutils.mjs +37 -37
- package/package.json +2 -3
- 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
|
/**
|
|
@@ -612,64 +612,65 @@ export function appendPreconnect(domain) {
|
|
|
612
612
|
}
|
|
613
613
|
|
|
614
614
|
/**
|
|
615
|
-
*
|
|
615
|
+
*
|
|
616
616
|
* @param {string} src The URL src to load
|
|
617
617
|
*/
|
|
618
618
|
async function loadScript(src) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
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
|
+
});
|
|
628
628
|
}
|
|
629
629
|
|
|
630
630
|
/**
|
|
631
|
-
*
|
|
631
|
+
*
|
|
632
632
|
* @param {object} event The click event object
|
|
633
633
|
*/
|
|
634
634
|
async function handleCTBClick(event) {
|
|
635
|
-
|
|
636
635
|
event.preventDefault();
|
|
637
|
-
|
|
638
|
-
if (!window.isCTBLoaded) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
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
|
|
645
646
|
const clonedEvent = new event.constructor(event.type, event);
|
|
646
647
|
setTimeout(() => {
|
|
647
648
|
event.target.dispatchEvent(clonedEvent);
|
|
648
649
|
}, 500);
|
|
649
|
-
|
|
650
|
+
}
|
|
650
651
|
}
|
|
651
652
|
|
|
652
653
|
/**
|
|
653
|
-
*
|
|
654
|
+
*
|
|
654
655
|
* @param {HTMLElement} element The element which needs to set the Attributes
|
|
655
656
|
*/
|
|
656
657
|
function setAttributesToMenuItem(element) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
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);
|
|
661
662
|
}
|
|
662
663
|
|
|
663
664
|
/**
|
|
664
|
-
*
|
|
665
|
+
*
|
|
665
666
|
* @param {HTMLElement} block The element CTA which triggers
|
|
666
667
|
*/
|
|
667
668
|
export function ctbCTAClickHandler(block = document) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
669
|
+
const elements = block.querySelectorAll("[data-ctbuy]");
|
|
670
|
+
elements.forEach((element) => {
|
|
671
|
+
setAttributesToMenuItem(element);
|
|
672
|
+
element.addEventListener("click", handleCTBClick);
|
|
673
|
+
});
|
|
673
674
|
}
|
|
674
675
|
|
|
675
676
|
const api = {
|
|
@@ -681,7 +682,6 @@ const api = {
|
|
|
681
682
|
getPosition,
|
|
682
683
|
getGsap,
|
|
683
684
|
getJquery,
|
|
684
|
-
getSwiperAssetsV2,
|
|
685
685
|
inCriticalCssConfig,
|
|
686
686
|
injectYouTubeIframeScript,
|
|
687
687
|
isEmailValid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pernod-ricard-global-cms/jsutils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Handy collection of Javascript utility functions",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "jsutils.mjs",
|
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
"gsap": "^3.10.4",
|
|
22
22
|
"jquery": "^3.6.0",
|
|
23
23
|
"prettier": "^2.5.1",
|
|
24
|
-
"swiper": "^8.
|
|
24
|
+
"swiper": "^8.4.7"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"cypress": "^10.5.0",
|
|
28
27
|
"jsdoc": "^3.6.7"
|
|
29
28
|
}
|
|
30
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
|
-
})
|