← All changes
|
modules/comments/subscription-modal-on-comment/subscription-modal.js
+15
-11
13.6.2
→
16.3-beta
View file →
| @@ -1,4 +1,5 @@ | ||
| 1 | +/* global subscriptionData */ | |
| 1 | 2 | document.addEventListener( 'DOMContentLoaded', function () { |
| 2 | 3 | const modal = document.getElementsByClassName( 'jetpack-subscription-modal' )[ 0 ]; |
| 3 | 4 | |
| 4 | 5 | if ( ! modal ) { |
| @@ -22,12 +23,15 @@ | ||
| 22 | 23 | localStorage.setItem( |
| 23 | 24 | 'jetpack-subscription-modal-on-comment-scroll-to', |
| 24 | 25 | destinationUrl.hash |
| 25 | 26 | ); |
| 26 | - // eslint-disable-next-line no-empty | |
| 27 | - } catch ( e ) {} | |
| 28 | - // For avoiding Firefox reload, we need to force reload bypassing the cache. | |
| 29 | - window.location.reload( true ); | |
| 27 | + } catch { | |
| 28 | + // Ok if we can't set it. | |
| 29 | + } | |
| 30 | + | |
| 31 | + // Add cache-busting parameter | |
| 32 | + destinationUrl.searchParams.set( '_ctn', Date.now() ); | |
| 33 | + window.location.href = destinationUrl.toString(); | |
| 30 | 34 | } |
| 31 | 35 | |
| 32 | 36 | function JetpackSubscriptionModalOnCommentMessageListener( event ) { |
| 33 | 37 | let message = event && event.data; |
| @@ -33,9 +37,9 @@ | ||
| 33 | 37 | let message = event && event.data; |
| 34 | 38 | if ( typeof message === 'string' ) { |
| 35 | 39 | try { |
| 36 | 40 | message = JSON.parse( message ); |
| 37 | - } catch ( err ) { | |
| 41 | + } catch { | |
| 38 | 42 | return; |
| 39 | 43 | } |
| 40 | 44 | } |
| 41 | 45 | |
| @@ -45,15 +49,15 @@ | ||
| 45 | 49 | if ( type !== 'subscriptionModalShow' || typeof data.url === 'undefined' ) { |
| 46 | 50 | return; |
| 47 | 51 | } |
| 48 | 52 | |
| 49 | - if ( ! event.origin.includes( window.location.host ) ) { | |
| 53 | + if ( subscriptionData.homeUrl !== event.origin ) { | |
| 50 | 54 | return; |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | 57 | if ( data.email ) { |
| 54 | 58 | const emailInput = document.querySelector( |
| 55 | - '.jetpack-subscription-modal__modal-content input[type=email]' | |
| 59 | + '.jetpack-subscription-modal__modal-content input[type="email"]' | |
| 56 | 60 | ); |
| 57 | 61 | if ( ! emailInput ) { |
| 58 | 62 | reloadOnCloseSubscriptionModal( data.url ); |
| 59 | 63 | return; |
| @@ -59,9 +63,9 @@ | ||
| 59 | 63 | return; |
| 60 | 64 | } |
| 61 | 65 | |
| 62 | 66 | const appSource = document.querySelector( |
| 63 | - '.jetpack-subscription-modal__modal-content input[name=app_source]' | |
| 67 | + '.jetpack-subscription-modal__modal-content input[name="app_source"]' | |
| 64 | 68 | ); |
| 65 | 69 | if ( ! appSource ) { |
| 66 | 70 | reloadOnCloseSubscriptionModal( data.url ); |
| 67 | 71 | return; |
| @@ -90,10 +94,11 @@ | ||
| 90 | 94 | |
| 91 | 95 | reloadOnCloseSubscriptionModal( data.url ); |
| 92 | 96 | return; |
| 93 | 97 | } |
| 94 | - // eslint-disable-next-line no-empty | |
| 95 | - } catch ( e ) {} | |
| 98 | + } catch { | |
| 99 | + // Ignore any errors. | |
| 100 | + } | |
| 96 | 101 | |
| 97 | 102 | new Image().src = |
| 98 | 103 | document.location.protocol + |
| 99 | 104 | '//pixel.wp.com/g.gif?v=wpcom-no-pv&x_jetpack-subscribe-modal-comm=showed&r=' + |
| @@ -101,9 +106,8 @@ | ||
| 101 | 106 | |
| 102 | 107 | modal.classList.toggle( 'open' ); |
| 103 | 108 | hasLoaded = true; |
| 104 | 109 | redirectUrl = data.url; |
| 105 | - return; | |
| 106 | 110 | } |
| 107 | 111 | } |
| 108 | 112 | |
| 109 | 113 | window.addEventListener( 'message', JetpackSubscriptionModalOnCommentMessageListener ); |