| 1 |
/** |
| 2 |
* Setup Wizard Script |
| 3 |
* |
| 4 |
* @since 4.2.8.6 |
| 5 |
*/ |
| 6 |
class SetupWizard { |
| 7 |
static selectors = { |
| 8 |
elSetupForm: '#learn-press-setup-form', |
| 9 |
elPreviewPrice: '#preview-price', |
| 10 |
}; |
| 11 |
|
| 12 |
init() { |
| 13 |
this.elSetupForm = document.querySelector( SetupWizard.selectors.elSetupForm ); |
| 14 |
if ( ! this.elSetupForm ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
this.events(); |
| 19 |
} |
| 20 |
|
| 21 |
events() { |
| 22 |
document.addEventListener( 'change', ( e ) => { |
| 23 |
if ( e.target.closest( 'input, select' ) ) { |
| 24 |
this.saveSettings(); |
| 25 |
} |
| 26 |
} ); |
| 27 |
} |
| 28 |
|
| 29 |
/* Post form data to current url, update preview price html with response */ |
| 30 |
saveSettings() { |
| 31 |
const formData = new FormData( this.elSetupForm ); |
| 32 |
|
| 33 |
fetch( window.location.href, { |
| 34 |
method: 'POST', |
| 35 |
body: formData, |
| 36 |
} ) |
| 37 |
.then( ( response ) => response.text() ) |
| 38 |
.then( ( html ) => { |
| 39 |
const elPreviewPrice = document.querySelector( SetupWizard.selectors.elPreviewPrice ); |
| 40 |
if ( elPreviewPrice ) { |
| 41 |
elPreviewPrice.innerHTML = html; |
| 42 |
} |
| 43 |
} ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
document.addEventListener( 'DOMContentLoaded', () => { |
| 48 |
new SetupWizard().init(); |
| 49 |
} ); |
| 50 |
|