PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.7
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.7
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / modules / subscriptions / subscribe-overlay / subscribe-overlay.js

subscribe-overlay.js in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.7, at modules/subscriptions/subscribe-overlay/subscribe-overlay.js

74 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 const { domReady } = wp;
2
3 domReady( function () {
4 const overlay = document.querySelector( '.jetpack-subscribe-overlay' );
5 const overlayDismissedCookie = 'jetpack_post_subscribe_overlay_dismissed';
6 const skipUrlParam = 'jetpack_skip_subscription_popup';
7 const hasOverlayDismissedCookie =
8 document.cookie && document.cookie.indexOf( overlayDismissedCookie ) > -1;
9
10 // Subscriber ended up here e.g. from emails:
11 // we won't show the overlay to them in future since they most likely are already a subscriber.
12 function skipOverlay() {
13 const url = new URL( window.location.href );
14 if ( url.searchParams.has( skipUrlParam ) ) {
15 url.searchParams.delete( skipUrlParam );
16 window.history.replaceState( {}, '', url );
17 setOverlayDismissedCookie();
18 return true;
19 }
20
21 return false;
22 }
23
24 if ( ! overlay || hasOverlayDismissedCookie || skipOverlay() ) {
25 return;
26 }
27
28 const close = overlay.querySelector( '.jetpack-subscribe-overlay__close' );
29 close.onclick = function ( event ) {
30 event.preventDefault();
31 closeOverlay();
32 };
33
34 const toContent = overlay.querySelector( '.jetpack-subscribe-overlay__to-content' );
35 // User can edit overlay, and could remove to content link.
36 if ( toContent ) {
37 toContent.onclick = function ( event ) {
38 event.preventDefault();
39 closeOverlay();
40 };
41 }
42
43 // When the form is submitted, and next modal loads, it'll fire "subscription-modal-loaded" signalling that this form can be hidden.
44 const form = overlay.querySelector( 'form' );
45 if ( form ) {
46 form.addEventListener( 'subscription-modal-loaded', closeOverlay );
47 }
48
49 function closeOverlayOnEscapeKeydown( event ) {
50 if ( event.key === 'Escape' ) {
51 closeOverlay();
52 }
53 }
54
55 function openOverlay() {
56 overlay.classList.add( 'open' );
57 document.body.classList.add( 'jetpack-subscribe-overlay-open' );
58 setOverlayDismissedCookie();
59 window.addEventListener( 'keydown', closeOverlayOnEscapeKeydown );
60 }
61
62 function closeOverlay() {
63 overlay.classList.remove( 'open' );
64 document.body.classList.remove( 'jetpack-subscribe-overlay-open' );
65 window.removeEventListener( 'keydown', closeOverlayOnEscapeKeydown );
66 }
67
68 function setOverlayDismissedCookie() {
69 document.cookie = `${ overlayDismissedCookie }=true; path=/;`;
70 }
71
72 openOverlay();
73 } );
74