From 74f0a6f02a1f2c607234e677e6dacda44a71f240 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 20 Aug 2024 14:12:01 +0530 Subject: [PATCH 1/3] fix: popup dismiss issue with recurring visitors option --- src/blocks/blocks/popup/save.js | 2 +- src/blocks/frontend/popup/popup.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/blocks/blocks/popup/save.js b/src/blocks/blocks/popup/save.js index f3c87605e..d3e86402c 100644 --- a/src/blocks/blocks/popup/save.js +++ b/src/blocks/blocks/popup/save.js @@ -15,7 +15,7 @@ const Save = ({ id: attributes.id, className: classnames( className, 'is-front', { 'with-outside-button': 'outside' === attributes.closeButtonType }), 'data-open': attributes.trigger, - 'data-dismiss': attributes.recurringClose ? attributes.recurringTime : '', + 'data-dismiss': attributes.recurringClose ? attributes.recurringTime || 0 : '', 'data-time': ( undefined === attributes.trigger || 'onLoad' === attributes.trigger ) ? ( attributes.wait || 0 ) : '', 'data-anchor': 'onClick' === attributes.trigger ? attributes.anchor : '', 'data-offset': 'onScroll' === attributes.trigger ? attributes.scroll : '', diff --git a/src/blocks/frontend/popup/popup.ts b/src/blocks/frontend/popup/popup.ts index 7fc0553e9..900dd6d75 100644 --- a/src/blocks/frontend/popup/popup.ts +++ b/src/blocks/frontend/popup/popup.ts @@ -81,6 +81,7 @@ class PopupBlock { isItemDismissed() { const { id } = this.element; + const { dismiss } = this.element.dataset; const cache = JSON.parse( localStorage.getItem( this.storageKey ) ?? '[]' ) || []; const inCache = cache.filter( ( entry: { modalID: string; }) => entry.modalID === id ); @@ -89,6 +90,10 @@ class PopupBlock { return false; } + if ( 0 === parseInt( dismiss ) && 0 < inCache.length ) { + return true; + } + const item = inCache[ 0 ]; const now = new Date(); From 18373317aee01001d4e174141451e73d4eb17eb9 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 27 Aug 2024 10:06:03 +0530 Subject: [PATCH 2/3] Set default zero in frontend rather than editing the save.js --- src/blocks/blocks/popup/save.js | 2 +- src/blocks/frontend/popup/popup.ts | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/blocks/blocks/popup/save.js b/src/blocks/blocks/popup/save.js index d3e86402c..f3c87605e 100644 --- a/src/blocks/blocks/popup/save.js +++ b/src/blocks/blocks/popup/save.js @@ -15,7 +15,7 @@ const Save = ({ id: attributes.id, className: classnames( className, 'is-front', { 'with-outside-button': 'outside' === attributes.closeButtonType }), 'data-open': attributes.trigger, - 'data-dismiss': attributes.recurringClose ? attributes.recurringTime || 0 : '', + 'data-dismiss': attributes.recurringClose ? attributes.recurringTime : '', 'data-time': ( undefined === attributes.trigger || 'onLoad' === attributes.trigger ) ? ( attributes.wait || 0 ) : '', 'data-anchor': 'onClick' === attributes.trigger ? attributes.anchor : '', 'data-offset': 'onScroll' === attributes.trigger ? attributes.scroll : '', diff --git a/src/blocks/frontend/popup/popup.ts b/src/blocks/frontend/popup/popup.ts index 900dd6d75..a84b08bae 100644 --- a/src/blocks/frontend/popup/popup.ts +++ b/src/blocks/frontend/popup/popup.ts @@ -10,9 +10,9 @@ class PopupBlock { this.happened = false; this.storageKey = 'otter-popup-dismiss'; - const { dismiss, anchor } = element.dataset; + const { dismiss = 0, anchor } = element.dataset; - if ( this.isItemDismissed() && dismiss && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) { + if ( this.isItemDismissed() && dismiss >= 0 && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) { return; } @@ -50,11 +50,11 @@ class PopupBlock { } dismissModal() { - const { dismiss, anchor } = this.element.dataset; + const { dismiss = 0, anchor } = this.element.dataset; const { id } = this.element; - if ( ! dismiss || ! id || anchor ) { + if ( 0 < dismiss || ! id || anchor ) { return false; } @@ -81,11 +81,10 @@ class PopupBlock { isItemDismissed() { const { id } = this.element; - const { dismiss } = this.element.dataset; + const { dismiss = 0 } = this.element.dataset; const cache = JSON.parse( localStorage.getItem( this.storageKey ) ?? '[]' ) || []; const inCache = cache.filter( ( entry: { modalID: string; }) => entry.modalID === id ); - if ( 0 === inCache.length ) { return false; } From 807613d5f673cdc12b82087b676fc1564bdfb543 Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Tue, 27 Aug 2024 10:14:05 +0530 Subject: [PATCH 3/3] Fix js lint error --- src/blocks/frontend/popup/popup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blocks/frontend/popup/popup.ts b/src/blocks/frontend/popup/popup.ts index a84b08bae..fc659185e 100644 --- a/src/blocks/frontend/popup/popup.ts +++ b/src/blocks/frontend/popup/popup.ts @@ -12,7 +12,7 @@ class PopupBlock { const { dismiss = 0, anchor } = element.dataset; - if ( this.isItemDismissed() && dismiss >= 0 && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) { + if ( this.isItemDismissed() && 0 <= dismiss && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) { return; }