| 1 |
( function ( $ ) { |
| 2 |
$( document ).on( 'ready', function () { |
| 3 |
let publishBtn = $( '.hsr-publish-btn' ); |
| 4 |
let completedClass = 'completed'; |
| 5 |
let gotItBtn = $( '.hsr-got-it-btn' ); |
| 6 |
publishBtn.on( 'click', function ( e ) { |
| 7 |
e.preventDefault(); |
| 8 |
$( '.hsr-modal' ).addClass( 'open' ); |
| 9 |
$( 'body' ).addClass( 'modal-open' ); |
| 10 |
$.ajax( { |
| 11 |
type: 'post', |
| 12 |
dataType: 'json', |
| 13 |
url: hostingerContainer.url, |
| 14 |
data: { |
| 15 |
action: 'hostinger_publish_website', |
| 16 |
maintenance: 0, |
| 17 |
nonce: hostingerContainer.nonce, |
| 18 |
}, |
| 19 |
success: function ( result ) { |
| 20 |
const previewBtn = $( '.hsr-preview-btn' ); |
| 21 |
$( '.hsr-circular' ).addClass( 'hsr-hide' ) |
| 22 |
$( '.hsr-success-circular' ).addClass( 'hsr-show' ) |
| 23 |
$( '.hsr-publish-modal--footer' ).addClass( 'show' ) |
| 24 |
$( '.hsr-publish-modal--body h3' ).text( result.data.title ); |
| 25 |
$( '.hsr-publish-modal--body__description' ).text( result.data.description ); |
| 26 |
$( '.hsr-publish-btn' ).addClass( 'hsr-preview' ) |
| 27 |
previewBtn.addClass( 'hsr-preview' ) |
| 28 |
previewBtn.text( result.data.content.btn.text ) |
| 29 |
$( '.hsr-onboarding__title' ).text( result.data.content.title ); |
| 30 |
$( '.hsr-onboarding__description' ).text( result.data.content.description ); |
| 31 |
}, |
| 32 |
error: function ( xhr, status, error ) { |
| 33 |
console.log( 'AJAX request failed: ' + error ); |
| 34 |
} |
| 35 |
} ) |
| 36 |
} ) |
| 37 |
|
| 38 |
gotItBtn.on( 'click', function ( e ) { |
| 39 |
e.preventDefault(); |
| 40 |
const element = $( this ); |
| 41 |
const step = $( this ).data( 'step' ); |
| 42 |
let remaining_tasks = $( '.hsr-onboarding-steps' ).data( 'remaining-tasks' ); |
| 43 |
|
| 44 |
$.ajax( { |
| 45 |
type: 'post', |
| 46 |
dataType: 'json', |
| 47 |
url: hostingerContainer.url, |
| 48 |
data: { |
| 49 |
action: 'hostinger_complete_onboarding_step', |
| 50 |
step: step, |
| 51 |
nonce: hostingerContainer.nonce, |
| 52 |
}, |
| 53 |
success: function () { |
| 54 |
element.closest( '.hsr-onboarding-step--content' ).slideUp() |
| 55 |
element.parents( '.hsr-onboarding-step' ) |
| 56 |
.find( '.hsr-onboarding-step--status' ) |
| 57 |
.addClass( completedClass ) |
| 58 |
|
| 59 |
if ( remaining_tasks > 0 ) { |
| 60 |
remaining_tasks = remaining_tasks - 1; |
| 61 |
$( '.hsr-onboarding-steps' ).data( 'remaining-tasks', remaining_tasks ) |
| 62 |
|
| 63 |
if ( remaining_tasks === 0 ) { |
| 64 |
$( '.hsr-publish-btn' ).addClass( completedClass ); |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
}, |
| 69 |
error: function ( xhr, status, error ) { |
| 70 |
console.log( 'AJAX request failed: ' + error ); |
| 71 |
} |
| 72 |
} ) |
| 73 |
} ) |
| 74 |
} ); |
| 75 |
} )( jQuery ); |
| 76 |
|