Skip to content

Commit

Permalink
[MWPW-154970] allow authoring hash value delay=0 for promo modals (#2706
Browse files Browse the repository at this point in the history
)

allow authoring delay=0 for modals
  • Loading branch information
Ruchika4 authored Aug 14, 2024
1 parent 302e9be commit 01da50f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions libs/blocks/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function getHashParams(hashStr) {
params.hash = part;
} else {
const [key, val] = part.split('=');
if (key === 'delay' && parseInt(val, 10) > 0) {
if (key === 'delay') {
params.delay = parseInt(val, 10) * 1000;
}
}
Expand All @@ -232,7 +232,7 @@ export function getHashParams(hashStr) {

export function delayedModal(el) {
const { hash, delay } = getHashParams(el?.dataset.modalHash);
if (!delay || !hash) return false;
if (delay === undefined || !hash) return false;
isDelayedModal = true;
const modalOpenEvent = new Event(`${hash}:modalOpen`);
const pagesModalWasShownOn = window.sessionStorage.getItem(`shown:${hash}`);
Expand Down
5 changes: 4 additions & 1 deletion test/blocks/modals/modals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ describe('Modals', () => {

it('validates and returns proper hash parameters', () => {
expect(getHashParams()).to.deep.equal({});
expect(getHashParams('#delayed-modal:delay=0')).to.deep.equal({ hash: '#delayed-modal' });
expect(getHashParams('#delayed-modal:delay=0')).to.deep.equal({
delay: 0,
hash: '#delayed-modal',
});
expect(getHashParams('#delayed-modal:delay=1')).to.deep.equal({
delay: 1000,
hash: '#delayed-modal',
Expand Down

0 comments on commit 01da50f

Please sign in to comment.