| 1 |
jQuery( document ).ready( function ($) { |
| 2 |
|
| 3 |
/** |
| 4 |
* Ajax save. |
| 5 |
*/ |
| 6 |
$( document ).on( 'click', '.elementor-save-skin', function () { |
| 7 |
|
| 8 |
|
| 9 |
const $button = $( this ); |
| 10 |
const $controlWrapper = $button.closest( '.elementor-control-content' ); |
| 11 |
const $select = $controlWrapper.find( '.elementor-control-input-wrapper select' ); |
| 12 |
const selectedSkin = $select.val(); |
| 13 |
|
| 14 |
const html_id = $button.attr( 'id' ); |
| 15 |
const nonce = WPBC_Ajax.nonce; |
| 16 |
|
| 17 |
// UI feedback: processing state. |
| 18 |
$button.attr( 'saved_title', $button.text() ); |
| 19 |
$button.text( $button.attr( 'processing_title' ) + '...' ); |
| 20 |
$button.prop( 'disabled', true ); |
| 21 |
|
| 22 |
$.ajax( |
| 23 |
{ |
| 24 |
url: WPBC_Ajax.ajax_url, |
| 25 |
type: 'POST', |
| 26 |
data: { |
| 27 |
action: 'wpbc_save_calendar_skin', |
| 28 |
skin: selectedSkin, |
| 29 |
_ajax_nonce: nonce, |
| 30 |
html_id: html_id, |
| 31 |
}, |
| 32 |
success: function (response) { |
| 33 |
|
| 34 |
// Restore button state. |
| 35 |
if ( html_id ) { |
| 36 |
const $btn = $( document.getElementById( html_id ) ); |
| 37 |
$btn.prop( 'disabled', false ).text( $btn.attr( 'saved_title' ) ).removeAttr( 'saved_title' ); |
| 38 |
} |
| 39 |
|
| 40 |
if ( ! response.success ) { |
| 41 |
console.warn( 'Skin save failed:', response.data || 'Unknown error' ); |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
const savedSkinUrl = response.data?.url_full; |
| 46 |
console.log( 'Skin saved successfully:', savedSkinUrl ); |
| 47 |
}, |
| 48 |
error : function () { |
| 49 |
|
| 50 |
console.error( 'AJAX error occurred during skin save.' ); |
| 51 |
// Optional: restore button UI. |
| 52 |
if ( html_id ) { |
| 53 |
const $btn = $( '#' + html_id ); |
| 54 |
$btn.prop( 'disabled', false ).text( $btn.attr( 'saved_title' ) ).removeAttr( 'saved_title' ); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
); |
| 59 |
} ); |
| 60 |
|
| 61 |
$( document ).on( 'click', '.wpbc-reset-dates-button', function () { |
| 62 |
// Clear input values directly |
| 63 |
$( 'input[data-setting="wpbc_booking_calendar_dates_start"]' ).val( '' ).trigger( 'input' ); |
| 64 |
$( 'input[data-setting="wpbc_booking_calendar_dates_end"]' ).val( '' ).trigger( 'input' ); |
| 65 |
$( 'input[data-setting="wpbc_booking_calendar_startmonth"]' ).val( '' ).trigger( 'input' ); |
| 66 |
} ); |
| 67 |
} ); |
| 68 |
|