| 1 |
/* global jpConnect */ |
| 2 |
|
| 3 |
const connectButtons = document.querySelectorAll( '.jp-connect-button, #jp-connect-button--alt' ); |
| 4 |
|
| 5 |
connectButtons.forEach( function ( connectButton ) { |
| 6 |
connectButton.addEventListener( 'click', function ( event ) { |
| 7 |
event.preventDefault(); |
| 8 |
startConnectionFlow( connectButton ); |
| 9 |
} ); |
| 10 |
} ); |
| 11 |
|
| 12 |
function startConnectionFlow( connectButton ) { |
| 13 |
connectButton.classList.add( 'button-disabled' ); |
| 14 |
|
| 15 |
const searchParams = new URLSearchParams( |
| 16 |
connectButton.getAttribute( 'href' ).split( '?' )[ 1 ] |
| 17 |
); |
| 18 |
window.location = |
| 19 |
searchParams && searchParams.get( 'from' ) |
| 20 |
? jpConnect.connectUrl |
| 21 |
.split( '?page=jetpack' ) |
| 22 |
.join( '?page=jetpack&from=' + searchParams.get( 'from' ) ) |
| 23 |
: jpConnect.connectUrl; |
| 24 |
} |
| 25 |
|