Skip to content

Commit

Permalink
More elegant by cleaning up the URL param
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Oct 15, 2024
1 parent 004c371 commit 278436e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { domReady } = wp;
domReady( () => {
const modal = document.querySelector( '.jetpack-subscribe-modal' );
const modalDismissedCookie = 'jetpack_post_subscribe_modal_dismissed';
const skipUrlParam = 'jetpack_skip_subscription_popup';

function hasEnoughTimePassed() {
const lastDismissed = localStorage.getItem( modalDismissedCookie );
Expand All @@ -12,9 +13,10 @@ domReady( () => {
// Subscriber ended up here e.g. from emails:
// we won't show the modal to them in future since they most likely are already a subscriber.
function skipModal() {
const urlParams = new URLSearchParams( window.location.search );
const skip = urlParams.get( 'jetpack_skip_subscription_popup' );
if ( skip ) {
const url = new URL( window.location.href );
if ( url.searchParams.has( skipUrlParam ) ) {
url.searchParams.delete( skipUrlParam );
window.history.pushState( {}, '', url );
storeCloseTimestamp();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ const { domReady } = wp;
domReady( function () {
const overlay = document.querySelector( '.jetpack-subscribe-overlay' );
const overlayDismissedCookie = 'jetpack_post_subscribe_overlay_dismissed';
const skipUrlParam = 'jetpack_skip_subscription_popup';
const hasOverlayDismissedCookie =
document.cookie && document.cookie.indexOf( overlayDismissedCookie ) > -1;

// Subscriber ended up here e.g. from emails:
// we won't show the overlay to them in future since they most likely are already a subscriber.
function skipOverlay() {
const urlParams = new URLSearchParams( window.location.search );
const skip = urlParams.get( 'jetpack_skip_subscription_popup' );
if ( skip ) {
const url = new URL( window.location.href );
if ( url.searchParams.has( skipUrlParam ) ) {
url.searchParams.delete( skipUrlParam );
window.history.pushState( {}, '', url );
setOverlayDismissedCookie();
return true;
}
Expand Down

0 comments on commit 278436e

Please sign in to comment.