@pernod-ricard-global-cms/jsutils 3.2.0 → 3.2.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.
Files changed (2) hide show
  1. package/jsutils.mjs +8 -4
  2. package/package.json +1 -1
package/jsutils.mjs CHANGED
@@ -632,16 +632,20 @@ async function loadScript(src) {
632
632
  * @param {object} event The click event object
633
633
  */
634
634
  async function handleCTBClick(event) {
635
- if (!window.isCTBLoaded) {
635
+
636
+ event.preventDefault();
637
+
638
+ if (!window.isCTBLoaded) {
636
639
  const domain = window.location.hostname;
637
640
  // Assuming PR-CLICKTOBUY plugin is enabled to make the script load
638
641
  await loadScript(`/wp-content/plugins/pr-clicktobuy/public/js/pr-clicktobuy-public.js`);
639
642
  window.isCTBLoaded = true;
640
643
 
641
644
  // This is important!! Never remove this code
642
- setTimeout(() => {
643
- event.target.click();
644
- }, 100);
645
+ const clonedEvent = new event.constructor(event.type, event);
646
+ setTimeout(() => {
647
+ event.target.dispatchEvent(clonedEvent);
648
+ }, 500);
645
649
  }
646
650
  }
647
651
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pernod-ricard-global-cms/jsutils",
3
- "version": "3.2.0",
3
+ "version": "3.2.2",
4
4
  "description": "Handy collection of Javascript utility functions",
5
5
  "type": "commonjs",
6
6
  "main": "jsutils.mjs",