Skip to content

Commit

Permalink
Merge pull request #2347 from Codeinwp/bugfix/otter-internals/228
Browse files Browse the repository at this point in the history
Fixed popup dismiss issue with recurring visitors option
  • Loading branch information
HardeepAsrani authored Aug 28, 2024
2 parents e387d09 + 807613d commit ed9a053
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/blocks/frontend/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() && 0 <= dismiss && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) {
return;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -81,14 +81,18 @@ class PopupBlock {

isItemDismissed() {
const { id } = this.element;
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;
}

if ( 0 === parseInt( dismiss ) && 0 < inCache.length ) {
return true;
}

const item = inCache[ 0 ];
const now = new Date();

Expand Down

0 comments on commit ed9a053

Please sign in to comment.