| 1 |
( function ( w, $ ) { |
| 2 |
'use strict'; |
| 3 |
/** Update the visible duration summary for a resource-specific Service selector. */ |
| 4 |
function updateSummary( $select ) { |
| 5 |
var $option = $select.find( 'option:selected' ), duration = Number( $option.data( 'duration' ) || 0 ), parts = []; |
| 6 |
if ( duration ) { parts.push( duration + ' min' ); } |
| 7 |
$select.closest( '.wpbc_appointment_service_selector' ).find( '.wpbc_appointment_service_summary' ).text( parts.join( ' ยท ' ) ); |
| 8 |
} |
| 9 |
$( document ).on( 'change', '.wpbc_appointment_service_select', function () { updateSummary( $( this ) ); } ); |
| 10 |
$( 'body' ).on( 'wpbc_before_booking_create', function ( event, resourceId, params ) { |
| 11 |
var $select = $( '#wpbc_appointment_service_' + Number( resourceId ) ); |
| 12 |
if ( $select.length ) { |
| 13 |
var $option = $select.find( 'option:selected' ); |
| 14 |
params.service_id = Number( $select.val() || 0 ); |
| 15 |
params.appointment_service_required = 1; |
| 16 |
params.appointment_context_token = String( $option.attr( 'data-appointment-context-token' ) || '' ); |
| 17 |
} |
| 18 |
} ); |
| 19 |
$( function () { $( '.wpbc_appointment_service_select' ).each( function () { updateSummary( $( this ) ); } ); } ); |
| 20 |
} )( window, jQuery ); |
| 21 |
|