File manager - Edit - /home/premiey/www/wp-includes/images/media/__js.tar
Back
utils/wpbc_utils.js 0000666 00000002034 15165320372 0010424 0 ustar 00 /** * ===================================================================================================================== * JavaScript Util Functions ../includes/__js/utils/wpbc_utils.js * ===================================================================================================================== */ /** * Trim strings and array joined with (,) * * @param string_to_trim string / array * @returns string */ function wpbc_trim( string_to_trim ){ if ( Array.isArray( string_to_trim ) ){ string_to_trim = string_to_trim.join( ',' ); } if ( 'string' == typeof (string_to_trim) ){ string_to_trim = string_to_trim.trim(); } return string_to_trim; } /** * Check if element in array * * @param array_here array * @param p_val element to check * @returns {boolean} */ function wpbc_in_array( array_here, p_val ){ for ( var i = 0, l = array_here.length; i < l; i++ ){ if ( array_here[ i ] == p_val ){ return true; } } return false; } front_end_messages/wpbc_fe_messages.js 0000666 00000035752 15165320372 0014267 0 ustar 00 /** * ===================================================================================================================== * includes/__js/front_end_messages/wpbc_fe_messages.js * ===================================================================================================================== */ // --------------------------------------------------------------------------------------------------------------------- // Show Messages at Front-Edn side // --------------------------------------------------------------------------------------------------------------------- /** * Show message in content * * @param message Message HTML * @param params = { * 'type' : 'warning', // 'error' | 'warning' | 'info' | 'success' * 'show_here' : { * 'jq_node' : '', // any jQuery node definition * 'where' : 'inside' // 'inside' | 'before' | 'after' | 'right' | 'left' * }, * 'is_append': true, // Apply only if 'where' : 'inside' * 'style' : 'text-align:left;', // styles, if needed * 'css_class': '', // For example can be: 'wpbc_fe_message_alt' * 'delay' : 0, // how many microsecond to show, if 0 then show forever * 'if_visible_not_show': false // if true, then do not show message, if previos message was not hided (not apply if 'where' : 'inside' ) * }; * Examples: * var html_id = wpbc_front_end__show_message( 'You can test days selection in calendar', {} ); * * var notice_message_id = wpbc_front_end__show_message( _wpbc.get_message( 'message_check_required' ), { 'type': 'warning', 'delay': 10000, 'if_visible_not_show': true, * 'show_here': {'where': 'right', 'jq_node': el,} } ); * * wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), * { 'type' : ( 'undefined' !== typeof( response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] ) ) * ? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'info', * 'show_here': {'jq_node': jq_node, 'where': 'after'}, * 'css_class':'wpbc_fe_message_alt', * 'delay' : 10000 * } ); * * * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message( message, params = {} ){ var params_default = { 'type' : 'warning', // 'error' | 'warning' | 'info' | 'success' 'show_here' : { 'jq_node' : '', // any jQuery node definition 'where' : 'inside' // 'inside' | 'before' | 'after' | 'right' | 'left' }, 'is_append': true, // Apply only if 'where' : 'inside' 'style' : 'text-align:left;', // styles, if needed 'css_class': '', // For example can be: 'wpbc_fe_message_alt' 'delay' : 0, // how many microsecond to show, if 0 then show forever 'if_visible_not_show': false, // if true, then do not show message, if previos message was not hided (not apply if 'where' : 'inside' ) 'is_scroll': true // is scroll to this element }; for ( var p_key in params ){ params_default[ p_key ] = params[ p_key ]; } params = params_default; var unique_div_id = new Date(); unique_div_id = 'wpbc_notice_' + unique_div_id.getTime(); params['css_class'] += ' wpbc_fe_message'; if ( params['type'] == 'error' ){ params['css_class'] += ' wpbc_fe_message_error'; message = '<i class="menu_icon icon-1x wpbc_icn_report_gmailerrorred"></i>' + message; } if ( params['type'] == 'warning' ){ params['css_class'] += ' wpbc_fe_message_warning'; message = '<i class="menu_icon icon-1x wpbc_icn_warning"></i>' + message; } if ( params['type'] == 'info' ){ params['css_class'] += ' wpbc_fe_message_info'; } if ( params['type'] == 'success' ){ params['css_class'] += ' wpbc_fe_message_success'; message = '<i class="menu_icon icon-1x wpbc_icn_done_outline"></i>' + message; } var scroll_to_element = '<div id="' + unique_div_id + '_scroll" style="display:none;"></div>'; message = '<div id="' + unique_div_id + '" class="wpbc_front_end__message ' + params['css_class'] + '" style="' + params[ 'style' ] + '">' + message + '</div>'; var jq_el_message = false; var is_show_message = true; if ( 'inside' === params[ 'show_here' ][ 'where' ] ){ if ( params[ 'is_append' ] ){ jQuery( params[ 'show_here' ][ 'jq_node' ] ).append( scroll_to_element ); jQuery( params[ 'show_here' ][ 'jq_node' ] ).append( message ); } else { jQuery( params[ 'show_here' ][ 'jq_node' ] ).html( scroll_to_element + message ); } } else if ( 'before' === params[ 'show_here' ][ 'where' ] ){ jq_el_message = jQuery( params[ 'show_here' ][ 'jq_node' ] ).siblings( '[id^="wpbc_notice_"]' ); if ( (params[ 'if_visible_not_show' ]) && (jq_el_message.is( ':visible' )) ){ is_show_message = false; unique_div_id = jQuery( jq_el_message.get( 0 ) ).attr( 'id' ); } if ( is_show_message ){ jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( scroll_to_element ); jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( message ); } } else if ( 'after' === params[ 'show_here' ][ 'where' ] ){ jq_el_message = jQuery( params[ 'show_here' ][ 'jq_node' ] ).nextAll( '[id^="wpbc_notice_"]' ); if ( (params[ 'if_visible_not_show' ]) && (jq_el_message.is( ':visible' )) ){ is_show_message = false; unique_div_id = jQuery( jq_el_message.get( 0 ) ).attr( 'id' ); } if ( is_show_message ){ jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( scroll_to_element ); // We need to set here before(for handy scroll) jQuery( params[ 'show_here' ][ 'jq_node' ] ).after( message ); } } else if ( 'right' === params[ 'show_here' ][ 'where' ] ){ jq_el_message = jQuery( params[ 'show_here' ][ 'jq_node' ] ).nextAll( '.wpbc_front_end__message_container_right' ).find( '[id^="wpbc_notice_"]' ); if ( (params[ 'if_visible_not_show' ]) && (jq_el_message.is( ':visible' )) ){ is_show_message = false; unique_div_id = jQuery( jq_el_message.get( 0 ) ).attr( 'id' ); } if ( is_show_message ){ jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( scroll_to_element ); // We need to set here before(for handy scroll) jQuery( params[ 'show_here' ][ 'jq_node' ] ).after( '<div class="wpbc_front_end__message_container_right">' + message + '</div>' ); } } else if ( 'left' === params[ 'show_here' ][ 'where' ] ){ jq_el_message = jQuery( params[ 'show_here' ][ 'jq_node' ] ).siblings( '.wpbc_front_end__message_container_left' ).find( '[id^="wpbc_notice_"]' ); if ( (params[ 'if_visible_not_show' ]) && (jq_el_message.is( ':visible' )) ){ is_show_message = false; unique_div_id = jQuery( jq_el_message.get( 0 ) ).attr( 'id' ); } if ( is_show_message ){ jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( scroll_to_element ); // We need to set here before(for handy scroll) jQuery( params[ 'show_here' ][ 'jq_node' ] ).before( '<div class="wpbc_front_end__message_container_left">' + message + '</div>' ); } } if ( ( is_show_message ) && ( parseInt( params[ 'delay' ] ) > 0 ) ){ var closed_timer = setTimeout( function (){ jQuery( '#' + unique_div_id ).fadeOut( 1500 ); } , parseInt( params[ 'delay' ] ) ); var closed_timer2 = setTimeout( function (){ jQuery( '#' + unique_div_id ).trigger( 'hide' ); }, ( parseInt( params[ 'delay' ] ) + 1501 ) ); } // Check if showed message in some hidden parent section and show it. But it must be lower than '.wpbc_container' var parent_els = jQuery( '#' + unique_div_id ).parents().map( function (){ if ( (!jQuery( this ).is( 'visible' )) && (jQuery( '.wpbc_container' ).has( this )) ){ jQuery( this ).show(); } } ); if ( params[ 'is_scroll' ] ){ wpbc_do_scroll( '#' + unique_div_id + '_scroll' ); } return unique_div_id; } /** * Error message. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__error( jq_node, message ){ var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'error', 'delay' : 10000, 'if_visible_not_show': true, 'show_here' : { 'where' : 'right', 'jq_node': jq_node } } ); return notice_message_id; } /** * Error message UNDER element. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__error_under_element( jq_node, message, message_delay ){ if ( 'undefined' === typeof (message_delay) ){ message_delay = 0 } var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'error', 'delay' : message_delay, 'if_visible_not_show': true, 'show_here' : { 'where' : 'after', 'jq_node': jq_node } } ); return notice_message_id; } /** * Error message UNDER element. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__error_above_element( jq_node, message, message_delay ){ if ( 'undefined' === typeof (message_delay) ){ message_delay = 10000 } var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'error', 'delay' : message_delay, 'if_visible_not_show': true, 'show_here' : { 'where' : 'before', 'jq_node': jq_node } } ); return notice_message_id; } /** * Warning message. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__warning( jq_node, message ){ var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'warning', 'delay' : 10000, 'if_visible_not_show': true, 'show_here' : { 'where' : 'right', 'jq_node': jq_node } } ); wpbc_highlight_error_on_form_field( jq_node ); return notice_message_id; } /** * Warning message UNDER element. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__warning_under_element( jq_node, message ){ var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'warning', 'delay' : 10000, 'if_visible_not_show': true, 'show_here' : { 'where' : 'after', 'jq_node': jq_node } } ); return notice_message_id; } /** * Warning message ABOVE element. Preset of parameters for real message function. * * @param el - any jQuery node definition * @param message - Message HTML * @returns string - HTML ID or 0 if not showing during this time. */ function wpbc_front_end__show_message__warning_above_element( jq_node, message ){ var notice_message_id = wpbc_front_end__show_message( message, { 'type' : 'warning', 'delay' : 10000, 'if_visible_not_show': true, 'show_here' : { 'where' : 'before', 'jq_node': jq_node } } ); return notice_message_id; } /** * Highlight Error in specific field * * @param jq_node string or jQuery element, where scroll to */ function wpbc_highlight_error_on_form_field( jq_node ){ if ( !jQuery( jq_node ).length ){ return; } if ( ! jQuery( jq_node ).is( ':input' ) ){ // Situation with checkboxes or radio buttons var jq_node_arr = jQuery( jq_node ).find( ':input' ); if ( !jq_node_arr.length ){ return } jq_node = jq_node_arr.get( 0 ); } var params = {}; params[ 'delay' ] = 10000; if ( !jQuery( jq_node ).hasClass( 'wpbc_form_field_error' ) ){ jQuery( jq_node ).addClass( 'wpbc_form_field_error' ) if ( parseInt( params[ 'delay' ] ) > 0 ){ var closed_timer = setTimeout( function (){ jQuery( jq_node ).removeClass( 'wpbc_form_field_error' ); } , parseInt( params[ 'delay' ] ) ); } } } /** * Scroll to specific element * * @param jq_node string or jQuery element, where scroll to * @param extra_shift_offset int shift offset from jq_node */ function wpbc_do_scroll( jq_node , extra_shift_offset = 0 ){ if ( !jQuery( jq_node ).length ){ return; } var targetOffset = jQuery( jq_node ).offset().top; if ( targetOffset <= 0 ){ if ( 0 != jQuery( jq_node ).nextAll( ':visible' ).length ){ targetOffset = jQuery( jq_node ).nextAll( ':visible' ).first().offset().top; } else if ( 0 != jQuery( jq_node ).parent().nextAll( ':visible' ).length ){ targetOffset = jQuery( jq_node ).parent().nextAll( ':visible' ).first().offset().top; } } if ( jQuery( '#wpadminbar' ).length > 0 ){ targetOffset = targetOffset - 50 - 50; } else { targetOffset = targetOffset - 20 - 50; } targetOffset += extra_shift_offset; // Scroll only if we did not scroll before if ( ! jQuery( 'html,body' ).is( ':animated' ) ){ jQuery( 'html,body' ).animate( {scrollTop: targetOffset}, 500 ); } } cal/days_select_custom.js 0000666 00000017435 15165320372 0011554 0 ustar 00 /** * ==================================================================================================================== * includes/__js/cal/days_select_custom.js * ==================================================================================================================== */ //FixIn: 9.8.9.2 /** * Re-Init Calendar and Re-Render it. * * @param resource_id */ function wpbc_cal__re_init( resource_id ){ // Remove CLASS for ability to re-render and reinit calendar. jQuery( '#calendar_booking' + resource_id ).removeClass( 'hasDatepick' ); wpbc_calendar_show( resource_id ); } /** * Re-Init previously saved days selection variables. * * @param resource_id */ function wpbc_cal_days_select__re_init( resource_id ){ _wpbc.calendar__set_param_value( resource_id, 'saved_variable___days_select_initial' , { 'dynamic__days_min' : _wpbc.calendar__get_param_value( resource_id, 'dynamic__days_min' ), 'dynamic__days_max' : _wpbc.calendar__get_param_value( resource_id, 'dynamic__days_max' ), 'dynamic__days_specific' : _wpbc.calendar__get_param_value( resource_id, 'dynamic__days_specific' ), 'dynamic__week_days__start': _wpbc.calendar__get_param_value( resource_id, 'dynamic__week_days__start' ), 'fixed__days_num' : _wpbc.calendar__get_param_value( resource_id, 'fixed__days_num' ), 'fixed__week_days__start' : _wpbc.calendar__get_param_value( resource_id, 'fixed__week_days__start' ) } ); } // --------------------------------------------------------------------------------------------------------------------- /** * Set Single Day selection - after page load * * @param resource_id ID of booking resource */ function wpbc_cal_ready_days_select__single( resource_id ){ // Re-define selection, only after page loaded with all init vars jQuery(document).ready(function(){ // Wait 1 second, just to be sure, that all init vars defined setTimeout(function(){ wpbc_cal_days_select__single( resource_id ); }, 1000); }); } /** * Set Single Day selection * Can be run at any time, when calendar defined - useful for console run. * * @param resource_id ID of booking resource */ function wpbc_cal_days_select__single( resource_id ){ _wpbc.calendar__set_parameters( resource_id, {'days_select_mode': 'single'} ); wpbc_cal_days_select__re_init( resource_id ); wpbc_cal__re_init( resource_id ); } // --------------------------------------------------------------------------------------------------------------------- /** * Set Multiple Days selection - after page load * * @param resource_id ID of booking resource */ function wpbc_cal_ready_days_select__multiple( resource_id ){ // Re-define selection, only after page loaded with all init vars jQuery(document).ready(function(){ // Wait 1 second, just to be sure, that all init vars defined setTimeout(function(){ wpbc_cal_days_select__multiple( resource_id ); }, 1000); }); } /** * Set Multiple Days selection * Can be run at any time, when calendar defined - useful for console run. * * @param resource_id ID of booking resource */ function wpbc_cal_days_select__multiple( resource_id ){ _wpbc.calendar__set_parameters( resource_id, {'days_select_mode': 'multiple'} ); wpbc_cal_days_select__re_init( resource_id ); wpbc_cal__re_init( resource_id ); } // --------------------------------------------------------------------------------------------------------------------- /** * Set Fixed Days selection with 1 mouse click - after page load * * @integer resource_id - 1 -- ID of booking resource (calendar) - * @integer days_number - 3 -- number of days to select - * @array week_days__start - [-1] | [ 1, 5] -- { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ function wpbc_cal_ready_days_select__fixed( resource_id, days_number, week_days__start = [-1] ){ // Re-define selection, only after page loaded with all init vars jQuery(document).ready(function(){ // Wait 1 second, just to be sure, that all init vars defined setTimeout(function(){ wpbc_cal_days_select__fixed( resource_id, days_number, week_days__start ); }, 1000); }); } /** * Set Fixed Days selection with 1 mouse click * Can be run at any time, when calendar defined - useful for console run. * * @integer resource_id - 1 -- ID of booking resource (calendar) - * @integer days_number - 3 -- number of days to select - * @array week_days__start - [-1] | [ 1, 5] -- { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ function wpbc_cal_days_select__fixed( resource_id, days_number, week_days__start = [-1] ){ _wpbc.calendar__set_parameters( resource_id, {'days_select_mode': 'fixed'} ); _wpbc.calendar__set_parameters( resource_id, {'fixed__days_num': parseInt( days_number )} ); // Number of days selection with 1 mouse click _wpbc.calendar__set_parameters( resource_id, {'fixed__week_days__start': week_days__start} ); // { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } wpbc_cal_days_select__re_init( resource_id ); wpbc_cal__re_init( resource_id ); } // --------------------------------------------------------------------------------------------------------------------- /** * Set Range Days selection with 2 mouse clicks - after page load * * @integer resource_id - 1 -- ID of booking resource (calendar) * @integer days_min - 7 -- Min number of days to select * @integer days_max - 30 -- Max number of days to select * @array days_specific - [] | [7,14,21,28] -- Restriction for Specific number of days selection * @array week_days__start - [-1] | [ 1, 5] -- { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ function wpbc_cal_ready_days_select__range( resource_id, days_min, days_max, days_specific = [], week_days__start = [-1] ){ // Re-define selection, only after page loaded with all init vars jQuery(document).ready(function(){ // Wait 1 second, just to be sure, that all init vars defined setTimeout(function(){ wpbc_cal_days_select__range( resource_id, days_min, days_max, days_specific, week_days__start ); }, 1000); }); } /** * Set Range Days selection with 2 mouse clicks * Can be run at any time, when calendar defined - useful for console run. * * @integer resource_id - 1 -- ID of booking resource (calendar) * @integer days_min - 7 -- Min number of days to select * @integer days_max - 30 -- Max number of days to select * @array days_specific - [] | [7,14,21,28] -- Restriction for Specific number of days selection * @array week_days__start - [-1] | [ 1, 5] -- { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } */ function wpbc_cal_days_select__range( resource_id, days_min, days_max, days_specific = [], week_days__start = [-1] ){ _wpbc.calendar__set_parameters( resource_id, {'days_select_mode': 'dynamic'} ); _wpbc.calendar__set_param_value( resource_id, 'dynamic__days_min' , parseInt( days_min ) ); // Min. Number of days selection with 2 mouse clicks _wpbc.calendar__set_param_value( resource_id, 'dynamic__days_max' , parseInt( days_max ) ); // Max. Number of days selection with 2 mouse clicks _wpbc.calendar__set_param_value( resource_id, 'dynamic__days_specific' , days_specific ); // Example [5,7] _wpbc.calendar__set_param_value( resource_id, 'dynamic__week_days__start' , week_days__start ); // { -1 - Any | 0 - Su, 1 - Mo, 2 - Tu, 3 - We, 4 - Th, 5 - Fr, 6 - Sat } wpbc_cal_days_select__re_init( resource_id ); wpbc_cal__re_init( resource_id ); } cal/wpbc_cal.js 0000666 00000227203 15165320372 0007431 0 ustar 00 /** * ===================================================================================================================== * includes/__js/cal/wpbc_cal.js * ===================================================================================================================== */ /** * Order or child booking resources saved here: _wpbc.booking__get_param_value( resource_id, 'resources_id_arr__in_dates' ) [2,10,12,11] */ /** * How to check booked times on specific date: ? * _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21'); console.log( _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_seconds, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[10].booked_time_slots.merged_seconds, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[11].booked_time_slots.merged_seconds, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_seconds ); * OR console.log( _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_readable, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[10].booked_time_slots.merged_readable, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[11].booked_time_slots.merged_readable, _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_readable ); * */ /** * Days selection: * wpbc_calendar__unselect_all_dates( resource_id ); * * var resource_id = 1; * Example 1: var num_selected_days = wpbc_auto_select_dates_in_calendar( resource_id, '2024-05-15', '2024-05-25' ); * Example 2: var num_selected_days = wpbc_auto_select_dates_in_calendar( resource_id, ['2024-05-09','2024-05-19','2024-05-25'] ); * */ /** * C A L E N D A R --------------------------------------------------------------------------------------------------- */ /** * Show WPBC Calendar * * @param resource_id - resource ID * @returns {boolean} */ function wpbc_calendar_show( resource_id ){ // If no calendar HTML tag, then exit if ( 0 === jQuery( '#calendar_booking' + resource_id ).length ){ return false; } // If the calendar with the same Booking resource is activated already, then exit. if ( true === jQuery( '#calendar_booking' + resource_id ).hasClass( 'hasDatepick' ) ){ return false; } // ----------------------------------------------------------------------------------------------------------------- // Days selection // ----------------------------------------------------------------------------------------------------------------- var local__is_range_select = false; var local__multi_days_select_num = 365; // multiple | fixed if ( 'dynamic' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ){ local__is_range_select = true; local__multi_days_select_num = 0; } if ( 'single' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ){ local__multi_days_select_num = 0; } // ----------------------------------------------------------------------------------------------------------------- // Min - Max days to scroll/show // ----------------------------------------------------------------------------------------------------------------- var local__min_date = 0; local__min_date = new Date( _wpbc.get_other_param( 'today_arr' )[ 0 ], (parseInt( _wpbc.get_other_param( 'today_arr' )[ 1 ] ) - 1), _wpbc.get_other_param( 'today_arr' )[ 2 ], 0, 0, 0 ); //FixIn: 9.9.0.17 //console.log( local__min_date ); var local__max_date = _wpbc.calendar__get_param_value( resource_id, 'booking_max_monthes_in_calendar' ); //local__max_date = new Date(2024, 5, 28); It is here issue of not selectable dates, but some dates showing in calendar as available, but we can not select it. //// Define last day in calendar (as a last day of month (and not date, which is related to actual 'Today' date). //// E.g. if today is 2023-09-25, and we set 'Number of months to scroll' as 5 months, then last day will be 2024-02-29 and not the 2024-02-25. // var cal_last_day_in_month = jQuery.datepick._determineDate( null, local__max_date, new Date() ); // cal_last_day_in_month = new Date( cal_last_day_in_month.getFullYear(), cal_last_day_in_month.getMonth() + 1, 0 ); // local__max_date = cal_last_day_in_month; //FixIn: 10.0.0.26 if ( ( location.href.indexOf('page=wpbc-new') != -1 ) && ( location.href.indexOf('booking_hash') != -1 ) // Comment this line for ability to add booking in past days at Booking > Add booking page. ){ local__min_date = null; local__max_date = null; } var local__start_weekday = _wpbc.calendar__get_param_value( resource_id, 'booking_start_day_weeek' ); var local__number_of_months = parseInt( _wpbc.calendar__get_param_value( resource_id, 'calendar_number_of_months' ) ); jQuery( '#calendar_booking' + resource_id ).text( '' ); // Remove all HTML in calendar tag // ----------------------------------------------------------------------------------------------------------------- // Show calendar // ----------------------------------------------------------------------------------------------------------------- jQuery('#calendar_booking'+ resource_id).datepick( { beforeShowDay: function ( js_date ){ return wpbc__calendar__apply_css_to_days( js_date, {'resource_id': resource_id}, this ); }, onSelect: function ( string_dates, js_dates_arr ){ /** * string_dates = '23.08.2023 - 26.08.2023' | '23.08.2023 - 23.08.2023' | '19.09.2023, 24.08.2023, 30.09.2023' * js_dates_arr = range: [ Date (Aug 23 2023), Date (Aug 25 2023)] | multiple: [ Date(Oct 24 2023), Date(Oct 20 2023), Date(Oct 16 2023) ] */ return wpbc__calendar__on_select_days( string_dates, {'resource_id': resource_id}, this ); }, onHover: function ( string_date, js_date ){ return wpbc__calendar__on_hover_days( string_date, js_date, {'resource_id': resource_id}, this ); }, onChangeMonthYear: function ( year, real_month, js_date__1st_day_in_month ){ }, showOn : 'both', numberOfMonths: local__number_of_months, stepMonths : 1, prevText : '«', nextText : '»', dateFormat : 'dd.mm.yy', changeMonth : false, changeYear : false, minDate : local__min_date, maxDate : local__max_date, // '1Y', // minDate: new Date(2020, 2, 1), maxDate: new Date(2020, 9, 31), // Ability to set any start and end date in calendar showStatus : false, multiSeparator : ', ', closeAtTop : false, firstDay : local__start_weekday, gotoCurrent : false, hideIfNoPrevNext: true, multiSelect : local__multi_days_select_num, rangeSelect : local__is_range_select, // showWeeks: true, useThemeRoller: false } ); // ----------------------------------------------------------------------------------------------------------------- // Clear today date highlighting // ----------------------------------------------------------------------------------------------------------------- setTimeout( function (){ wpbc_calendars__clear_days_highlighting( resource_id ); }, 500 ); //FixIn: 7.1.2.8 // ----------------------------------------------------------------------------------------------------------------- // Scroll calendar to specific month // ----------------------------------------------------------------------------------------------------------------- var start_bk_month = _wpbc.calendar__get_param_value( resource_id, 'calendar_scroll_to' ); if ( false !== start_bk_month ){ wpbc_calendar__scroll_to( resource_id, start_bk_month[ 0 ], start_bk_month[ 1 ] ); } } /** * Apply CSS to calendar date cells * * @param date - JavaScript Date Obj: Mon Dec 11 2023 00:00:00 GMT+0200 (Eastern European Standard Time) * @param calendar_params_arr - Calendar Settings Object: { * "resource_id": 4 * } * @param datepick_this - this of datepick Obj * @returns {(*|string)[]|(boolean|string)[]} - [ {true -available | false - unavailable}, 'CSS classes for calendar day cell' ] */ function wpbc__calendar__apply_css_to_days( date, calendar_params_arr, datepick_this ){ var today_date = new Date( _wpbc.get_other_param( 'today_arr' )[ 0 ], (parseInt( _wpbc.get_other_param( 'today_arr' )[ 1 ] ) - 1), _wpbc.get_other_param( 'today_arr' )[ 2 ], 0, 0, 0 ); // Today JS_Date_Obj. var class_day = wpbc__get__td_class_date( date ); // '1-9-2023' var sql_class_day = wpbc__get__sql_class_date( date ); // '2023-01-09' var resource_id = ( 'undefined' !== typeof(calendar_params_arr[ 'resource_id' ]) ) ? calendar_params_arr[ 'resource_id' ] : '1'; // '1' // Get Data -------------------------------------------------------------------------------------------------------- var date_bookings_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_class_day ); // Array with CSS classes for date --------------------------------------------------------------------------------- var css_classes__for_date = []; css_classes__for_date.push( 'sql_date_' + sql_class_day ); // 'sql_date_2023-07-21' css_classes__for_date.push( 'cal4date-' + class_day ); // 'cal4date-7-21-2023' css_classes__for_date.push( 'wpbc_weekday_' + date.getDay() ); // 'wpbc_weekday_4' var is_day_selectable = false; // If something not defined, then this date closed --------------------------------------------------------------- if ( false === date_bookings_obj ){ css_classes__for_date.push( 'date_user_unavailable' ); return [ is_day_selectable, css_classes__for_date.join(' ') ]; } // ----------------------------------------------------------------------------------------------------------------- // date_bookings_obj - Defined. Dates can be selectable. // ----------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------- // Add season names to the day CSS classes -- it is required for correct work of conditional fields -------------- var season_names_arr = _wpbc.seasons__get_for_date( resource_id, sql_class_day ); for ( var season_key in season_names_arr ){ css_classes__for_date.push( season_names_arr[ season_key ] ); // 'wpdevbk_season_september_2023' } // ----------------------------------------------------------------------------------------------------------------- // Cost Rate ------------------------------------------------------------------------------------------------------- css_classes__for_date.push( 'rate_' + date_bookings_obj[ resource_id ][ 'date_cost_rate' ].toString().replace( /[\.\s]/g, '_' ) ); // 'rate_99_00' -> 99.00 if ( parseInt( date_bookings_obj[ 'day_availability' ] ) > 0 ){ is_day_selectable = true; css_classes__for_date.push( 'date_available' ); css_classes__for_date.push( 'reserved_days_count' + parseInt( date_bookings_obj[ 'max_capacity' ] - date_bookings_obj[ 'day_availability' ] ) ); } else { is_day_selectable = false; css_classes__for_date.push( 'date_user_unavailable' ); } switch ( date_bookings_obj[ 'summary']['status_for_day' ] ){ case 'available': break; case 'time_slots_booking': css_classes__for_date.push( 'timespartly', 'times_clock' ); break; case 'full_day_booking': css_classes__for_date.push( 'full_day_booking' ); break; case 'season_filter': css_classes__for_date.push( 'date_user_unavailable', 'season_unavailable' ); date_bookings_obj[ 'summary']['status_for_bookings' ] = ''; // Reset booking status color for possible old bookings on this date break; case 'resource_availability': css_classes__for_date.push( 'date_user_unavailable', 'resource_unavailable' ); date_bookings_obj[ 'summary']['status_for_bookings' ] = ''; // Reset booking status color for possible old bookings on this date break; case 'weekday_unavailable': css_classes__for_date.push( 'date_user_unavailable', 'weekday_unavailable' ); date_bookings_obj[ 'summary']['status_for_bookings' ] = ''; // Reset booking status color for possible old bookings on this date break; case 'from_today_unavailable': css_classes__for_date.push( 'date_user_unavailable', 'from_today_unavailable' ); date_bookings_obj[ 'summary']['status_for_bookings' ] = ''; // Reset booking status color for possible old bookings on this date break; case 'limit_available_from_today': css_classes__for_date.push( 'date_user_unavailable', 'limit_available_from_today' ); date_bookings_obj[ 'summary']['status_for_bookings' ] = ''; // Reset booking status color for possible old bookings on this date break; case 'change_over': /* * // check_out_time_date2approve check_in_time_date2approve // check_out_time_date2approve check_in_time_date_approved // check_in_time_date2approve check_out_time_date_approved // check_out_time_date_approved check_in_time_date_approved */ css_classes__for_date.push( 'timespartly', 'check_in_time', 'check_out_time' ); //FixIn: 10.0.0.2 if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'approved_pending' ) > -1 ){ css_classes__for_date.push( 'check_out_time_date_approved', 'check_in_time_date2approve' ); } if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'pending_approved' ) > -1 ){ css_classes__for_date.push( 'check_out_time_date2approve', 'check_in_time_date_approved' ); } break; case 'check_in': css_classes__for_date.push( 'timespartly', 'check_in_time' ); //FixIn: 9.9.0.33 if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'pending' ) > -1 ){ css_classes__for_date.push( 'check_in_time_date2approve' ); } else if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'approved' ) > -1 ){ css_classes__for_date.push( 'check_in_time_date_approved' ); } break; case 'check_out': css_classes__for_date.push( 'timespartly', 'check_out_time' ); //FixIn: 9.9.0.33 if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'pending' ) > -1 ){ css_classes__for_date.push( 'check_out_time_date2approve' ); } else if ( date_bookings_obj[ 'summary' ][ 'status_for_bookings' ].indexOf( 'approved' ) > -1 ){ css_classes__for_date.push( 'check_out_time_date_approved' ); } break; default: // mixed statuses: 'change_over check_out' .... variations.... check more in function wpbc_get_availability_per_days_arr() date_bookings_obj[ 'summary']['status_for_day' ] = 'available'; } if ( 'available' != date_bookings_obj[ 'summary']['status_for_day' ] ){ var is_set_pending_days_selectable = _wpbc.calendar__get_param_value( resource_id, 'pending_days_selectable' ); // set pending days selectable //FixIn: 8.6.1.18 switch ( date_bookings_obj[ 'summary']['status_for_bookings' ] ){ case '': // Usually it's means that day is available or unavailable without the bookings break; case 'pending': css_classes__for_date.push( 'date2approve' ); is_day_selectable = (is_day_selectable) ? true : is_set_pending_days_selectable; break; case 'approved': css_classes__for_date.push( 'date_approved' ); break; // Situations for "change-over" days: ---------------------------------------------------------------------- case 'pending_pending': css_classes__for_date.push( 'check_out_time_date2approve', 'check_in_time_date2approve' ); is_day_selectable = (is_day_selectable) ? true : is_set_pending_days_selectable; break; case 'pending_approved': css_classes__for_date.push( 'check_out_time_date2approve', 'check_in_time_date_approved' ); is_day_selectable = (is_day_selectable) ? true : is_set_pending_days_selectable; break; case 'approved_pending': css_classes__for_date.push( 'check_out_time_date_approved', 'check_in_time_date2approve' ); is_day_selectable = (is_day_selectable) ? true : is_set_pending_days_selectable; break; case 'approved_approved': css_classes__for_date.push( 'check_out_time_date_approved', 'check_in_time_date_approved' ); break; default: } } return [ is_day_selectable, css_classes__for_date.join( ' ' ) ]; } /** * Mouseover calendar date cells * * @param string_date * @param date - JavaScript Date Obj: Mon Dec 11 2023 00:00:00 GMT+0200 (Eastern European Standard Time) * @param calendar_params_arr - Calendar Settings Object: { * "resource_id": 4 * } * @param datepick_this - this of datepick Obj * @returns {boolean} */ function wpbc__calendar__on_hover_days( string_date, date, calendar_params_arr, datepick_this ) { if ( null === date ){ return false; } var class_day = wpbc__get__td_class_date( date ); // '1-9-2023' var sql_class_day = wpbc__get__sql_class_date( date ); // '2023-01-09' var resource_id = ( 'undefined' !== typeof(calendar_params_arr[ 'resource_id' ]) ) ? calendar_params_arr[ 'resource_id' ] : '1'; // '1' // Get Data -------------------------------------------------------------------------------------------------------- var date_booking_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_class_day ); // {...} if ( ! date_booking_obj ){ return false; } // T o o l t i p s ------------------------------------------------------------------------------------------------- var tooltip_text = ''; if ( date_booking_obj[ 'summary']['tooltip_availability' ].length > 0 ){ tooltip_text += date_booking_obj[ 'summary']['tooltip_availability' ]; } if ( date_booking_obj[ 'summary']['tooltip_day_cost' ].length > 0 ){ tooltip_text += date_booking_obj[ 'summary']['tooltip_day_cost' ]; } if ( date_booking_obj[ 'summary']['tooltip_times' ].length > 0 ){ tooltip_text += date_booking_obj[ 'summary']['tooltip_times' ]; } if ( date_booking_obj[ 'summary']['tooltip_booking_details' ].length > 0 ){ tooltip_text += date_booking_obj[ 'summary']['tooltip_booking_details' ]; } wpbc_set_tooltip___for__calendar_date( tooltip_text, resource_id, class_day ); // U n h o v e r i n g in UNSELECTABLE_CALENDAR ------------------------------------------------------------ var is_unselectable_calendar = ( jQuery( '#calendar_booking_unselectable' + resource_id ).length > 0); //FixIn: 8.0.1.2 var is_booking_form_exist = ( jQuery( '#booking_form_div' + resource_id ).length > 0 ); if ( ( is_unselectable_calendar ) && ( ! is_booking_form_exist ) ){ /** * Un Hover all dates in calendar (without the booking form), if only Availability Calendar here and we do not insert Booking form by mistake. */ wpbc_calendars__clear_days_highlighting( resource_id ); // Clear days highlighting var css_of_calendar = '.wpbc_only_calendar #calendar_booking' + resource_id; jQuery( css_of_calendar + ' .datepick-days-cell, ' + css_of_calendar + ' .datepick-days-cell a' ).css( 'cursor', 'default' ); // Set cursor to Default return false; } // D a y s H o v e r i n g ------------------------------------------------------------------------------------ if ( ( location.href.indexOf( 'page=wpbc' ) == -1 ) || ( location.href.indexOf( 'page=wpbc-new' ) > 0 ) || ( location.href.indexOf( 'page=wpbc-availability' ) > 0 ) || ( ( location.href.indexOf( 'page=wpbc-settings' ) > 0 ) && ( location.href.indexOf( '&tab=form' ) > 0 ) ) ){ // The same as dates selection, but for days hovering if ( 'function' == typeof( wpbc__calendar__do_days_highlight__bs ) ){ wpbc__calendar__do_days_highlight__bs( sql_class_day, date, resource_id ); } } } /** * Select calendar date cells * * @param date - JavaScript Date Obj: Mon Dec 11 2023 00:00:00 GMT+0200 (Eastern European Standard Time) * @param calendar_params_arr - Calendar Settings Object: { * "resource_id": 4 * } * @param datepick_this - this of datepick Obj * */ function wpbc__calendar__on_select_days( date, calendar_params_arr, datepick_this ){ var resource_id = ( 'undefined' !== typeof(calendar_params_arr[ 'resource_id' ]) ) ? calendar_params_arr[ 'resource_id' ] : '1'; // '1' // Set unselectable, if only Availability Calendar here (and we do not insert Booking form by mistake). var is_unselectable_calendar = ( jQuery( '#calendar_booking_unselectable' + resource_id ).length > 0); //FixIn: 8.0.1.2 var is_booking_form_exist = ( jQuery( '#booking_form_div' + resource_id ).length > 0 ); if ( ( is_unselectable_calendar ) && ( ! is_booking_form_exist ) ){ wpbc_calendar__unselect_all_dates( resource_id ); // Unselect Dates jQuery('.wpbc_only_calendar .popover_calendar_hover').remove(); // Hide all opened popovers return false; } jQuery( '#date_booking' + resource_id ).val( date ); // Add selected dates to hidden textarea if ( 'function' === typeof (wpbc__calendar__do_days_select__bs) ){ wpbc__calendar__do_days_select__bs( date, resource_id ); } wpbc_disable_time_fields_in_booking_form( resource_id ); // Hook -- trigger day selection ----------------------------------------------------------------------------------- var mouse_clicked_dates = date; // Can be: "05.10.2023 - 07.10.2023" | "10.10.2023 - 10.10.2023" | var all_selected_dates_arr = wpbc_get__selected_dates_sql__as_arr( resource_id ); // Can be: [ "2023-10-05", "2023-10-06", "2023-10-07", … ] jQuery( ".booking_form_div" ).trigger( "date_selected", [ resource_id, mouse_clicked_dates, all_selected_dates_arr ] ); } /** * -- T i m e F i e l d s start -------------------------------------------------------------------------- */ /** * Disable time slots in booking form depend on selected dates and booked dates/times * * @param resource_id */ function wpbc_disable_time_fields_in_booking_form( resource_id ){ /** * 1. Get all time fields in the booking form as array of objects * [ * { jquery_option: jQuery_Object {} * name: 'rangetime2[]' * times_as_seconds: [ 21600, 23400 ] * value_option_24h: '06:00 - 06:30' * } * ... * { jquery_option: jQuery_Object {} * name: 'starttime2[]' * times_as_seconds: [ 21600 ] * value_option_24h: '06:00' * } * ] */ var time_fields_obj_arr = wpbc_get__time_fields__in_booking_form__as_arr( resource_id ); // 2. Get all selected dates in SQL format like this [ "2023-08-23", "2023-08-24", "2023-08-25", ... ] var selected_dates_arr = wpbc_get__selected_dates_sql__as_arr( resource_id ); // 3. Get child booking resources or single booking resource that exist in dates var child_resources_arr = wpbc_clone_obj( _wpbc.booking__get_param_value( resource_id, 'resources_id_arr__in_dates' ) ); var sql_date; var child_resource_id; var merged_seconds; var time_fields_obj; var is_intersect; var is_check_in; // 4. Loop all time Fields options //FixIn: 10.3.0.2 for ( let field_key = 0; field_key < time_fields_obj_arr.length; field_key++ ){ time_fields_obj_arr[ field_key ].disabled = 0; // By default, this time field is not disabled time_fields_obj = time_fields_obj_arr[ field_key ]; // { times_as_seconds: [ 21600, 23400 ], value_option_24h: '06:00 - 06:30', name: 'rangetime2[]', jquery_option: jQuery_Object {}} // Loop all selected dates for ( var i = 0; i < selected_dates_arr.length; i++ ){ //FixIn: 9.9.0.31 if ( ( 'Off' === _wpbc.calendar__get_param_value( resource_id, 'booking_recurrent_time' ) ) && ( selected_dates_arr.length>1 ) ){ //TODO: skip some fields checking if it's start / end time for mulple dates selection mode. //TODO: we need to fix situation for entimes, when user select several dates, and in start time booked 00:00 - 15:00 , but systsme block untill 15:00 the end time as well, which is wrong, because it 2 or 3 dates selection and end date can be fullu available if ( (0 == i) && (time_fields_obj[ 'name' ].indexOf( 'endtime' ) >= 0) ){ break; } if ( ( (selected_dates_arr.length-1) == i ) && (time_fields_obj[ 'name' ].indexOf( 'starttime' ) >= 0) ){ break; } } // Get Date: '2023-08-18' sql_date = selected_dates_arr[ i ]; var how_many_resources_intersected = 0; // Loop all resources ID // for ( var res_key in child_resources_arr ){ //FixIn: 10.3.0.2 for ( let res_key = 0; res_key < child_resources_arr.length; res_key++ ){ child_resource_id = child_resources_arr[ res_key ]; // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[12].booked_time_slots.merged_seconds = [ "07:00:11 - 07:30:02", "10:00:11 - 00:00:00" ] // _wpbc.bookings_in_calendar__get_for_date(2,'2023-08-21')[2].booked_time_slots.merged_seconds = [ [ 25211, 27002 ], [ 36011, 86400 ] ] if ( false !== _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date ) ){ merged_seconds = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_date )[ child_resource_id ].booked_time_slots.merged_seconds; // [ [ 25211, 27002 ], [ 36011, 86400 ] ] } else { merged_seconds = []; } if ( time_fields_obj.times_as_seconds.length > 1 ){ is_intersect = wpbc_is_intersect__range_time_interval( [ [ ( parseInt( time_fields_obj.times_as_seconds[0] ) + 20 ), ( parseInt( time_fields_obj.times_as_seconds[1] ) - 20 ) ] ] , merged_seconds ); } else { is_check_in = (-1 !== time_fields_obj.name.indexOf( 'start' )); is_intersect = wpbc_is_intersect__one_time_interval( ( ( is_check_in ) ? parseInt( time_fields_obj.times_as_seconds ) + 20 : parseInt( time_fields_obj.times_as_seconds ) - 20 ) , merged_seconds ); } if (is_intersect){ how_many_resources_intersected++; // Increase } } if ( child_resources_arr.length == how_many_resources_intersected ) { // All resources intersected, then it's means that this time-slot or time must be Disabled, and we can exist from selected_dates_arr LOOP time_fields_obj_arr[ field_key ].disabled = 1; break; // exist from Dates LOOP } } } // 5. Now we can disable time slot in HTML by using ( field.disabled == 1 ) property wpbc__html__time_field_options__set_disabled( time_fields_obj_arr ); jQuery( ".booking_form_div" ).trigger( 'wpbc_hook_timeslots_disabled', [resource_id, selected_dates_arr] ); // Trigger hook on disabling timeslots. Usage: jQuery( ".booking_form_div" ).on( 'wpbc_hook_timeslots_disabled', function ( event, bk_type, all_dates ){ ... } ); //FixIn: 8.7.11.9 } /** * Is number inside /intersect of array of intervals ? * * @param time_A - 25800 * @param time_interval_B - [ [ 25211, 27002 ], [ 36011, 86400 ] ] * @returns {boolean} */ function wpbc_is_intersect__one_time_interval( time_A, time_interval_B ){ for ( var j = 0; j < time_interval_B.length; j++ ){ if ( (parseInt( time_A ) > parseInt( time_interval_B[ j ][ 0 ] )) && (parseInt( time_A ) < parseInt( time_interval_B[ j ][ 1 ] )) ){ return true } // if ( ( parseInt( time_A ) == parseInt( time_interval_B[ j ][ 0 ] ) ) || ( parseInt( time_A ) == parseInt( time_interval_B[ j ][ 1 ] ) ) ) { // // Time A just at the border of interval // } } return false; } /** * Is these array of intervals intersected ? * * @param time_interval_A - [ [ 21600, 23400 ] ] * @param time_interval_B - [ [ 25211, 27002 ], [ 36011, 86400 ] ] * @returns {boolean} */ function wpbc_is_intersect__range_time_interval( time_interval_A, time_interval_B ){ var is_intersect; for ( var i = 0; i < time_interval_A.length; i++ ){ for ( var j = 0; j < time_interval_B.length; j++ ){ is_intersect = wpbc_intervals__is_intersected( time_interval_A[ i ], time_interval_B[ j ] ); if ( is_intersect ){ return true; } } } return false; } /** * Get all time fields in the booking form as array of objects * * @param resource_id * @returns [] * * Example: * [ * { * value_option_24h: '06:00 - 06:30' * times_as_seconds: [ 21600, 23400 ] * jquery_option: jQuery_Object {} * name: 'rangetime2[]' * } * ... * { * value_option_24h: '06:00' * times_as_seconds: [ 21600 ] * jquery_option: jQuery_Object {} * name: 'starttime2[]' * } * ] */ function wpbc_get__time_fields__in_booking_form__as_arr( resource_id ){ /** * Fields with [] like this select[name="rangetime1[]"] * it's when we have 'multiple' in shortcode: [select* rangetime multiple "06:00 - 06:30" ... ] */ var time_fields_arr=[ 'select[name="rangetime' + resource_id + '"]', 'select[name="rangetime' + resource_id + '[]"]', 'select[name="starttime' + resource_id + '"]', 'select[name="starttime' + resource_id + '[]"]', 'select[name="endtime' + resource_id + '"]', 'select[name="endtime' + resource_id + '[]"]' ]; var time_fields_obj_arr = []; // Loop all Time Fields for ( var ctf= 0; ctf < time_fields_arr.length; ctf++ ){ var time_field = time_fields_arr[ ctf ]; var time_option = jQuery( time_field + ' option' ); // Loop all options in time field for ( var j = 0; j < time_option.length; j++ ){ var jquery_option = jQuery( time_field + ' option:eq(' + j + ')' ); var value_option_seconds_arr = jquery_option.val().split( '-' ); var times_as_seconds = []; // Get time as seconds if ( value_option_seconds_arr.length ){ //FixIn: 9.8.10.1 for ( let i = 0; i < value_option_seconds_arr.length; i++ ){ //FixIn: 10.0.0.56 // value_option_seconds_arr[i] = '14:00 ' | ' 16:00' (if from 'rangetime') and '16:00' if (start/end time) var start_end_times_arr = value_option_seconds_arr[ i ].trim().split( ':' ); var time_in_seconds = parseInt( start_end_times_arr[ 0 ] ) * 60 * 60 + parseInt( start_end_times_arr[ 1 ] ) * 60; times_as_seconds.push( time_in_seconds ); } } time_fields_obj_arr.push( { 'name' : jQuery( time_field ).attr( 'name' ), 'value_option_24h': jquery_option.val(), 'jquery_option' : jquery_option, 'times_as_seconds': times_as_seconds } ); } } return time_fields_obj_arr; } /** * Disable HTML options and add booked CSS class * * @param time_fields_obj_arr - this value is from the func: wpbc_get__time_fields__in_booking_form__as_arr( resource_id ) * [ * { jquery_option: jQuery_Object {} * name: 'rangetime2[]' * times_as_seconds: [ 21600, 23400 ] * value_option_24h: '06:00 - 06:30' * disabled = 1 * } * ... * { jquery_option: jQuery_Object {} * name: 'starttime2[]' * times_as_seconds: [ 21600 ] * value_option_24h: '06:00' * disabled = 0 * } * ] * */ function wpbc__html__time_field_options__set_disabled( time_fields_obj_arr ){ var jquery_option; for ( var i = 0; i < time_fields_obj_arr.length; i++ ){ var jquery_option = time_fields_obj_arr[ i ].jquery_option; if ( 1 == time_fields_obj_arr[ i ].disabled ){ jquery_option.prop( 'disabled', true ); // Make disable some options jquery_option.addClass( 'booked' ); // Add "booked" CSS class // if this booked element selected --> then deselect it if ( jquery_option.prop( 'selected' ) ){ jquery_option.prop( 'selected', false ); jquery_option.parent().find( 'option:not([disabled]):first' ).prop( 'selected', true ).trigger( "change" ); } } else { jquery_option.prop( 'disabled', false ); // Make active all times jquery_option.removeClass( 'booked' ); // Remove class "booked" } } } /** * Check if this time_range | Time_Slot is Full Day booked * * @param timeslot_arr_in_seconds - [ 36011, 86400 ] * @returns {boolean} */ function wpbc_is_this_timeslot__full_day_booked( timeslot_arr_in_seconds ){ if ( ( timeslot_arr_in_seconds.length > 1 ) && ( parseInt( timeslot_arr_in_seconds[ 0 ] ) < 30 ) && ( parseInt( timeslot_arr_in_seconds[ 1 ] ) > ( (24 * 60 * 60) - 30) ) ){ return true; } return false; } // ----------------------------------------------------------------------------------------------------------------- /* == S e l e c t e d D a t e s / T i m e - F i e l d s == // ----------------------------------------------------------------------------------------------------------------- */ /** * Get all selected dates in SQL format like this [ "2023-08-23", "2023-08-24" , ... ] * * @param resource_id * @returns {[]} [ "2023-08-23", "2023-08-24", "2023-08-25", "2023-08-26", "2023-08-27", "2023-08-28", "2023-08-29" ] */ function wpbc_get__selected_dates_sql__as_arr( resource_id ){ var selected_dates_arr = []; selected_dates_arr = jQuery( '#date_booking' + resource_id ).val().split(','); if ( selected_dates_arr.length ){ //FixIn: 9.8.10.1 for ( let i = 0; i < selected_dates_arr.length; i++ ){ //FixIn: 10.0.0.56 selected_dates_arr[ i ] = selected_dates_arr[ i ].trim(); selected_dates_arr[ i ] = selected_dates_arr[ i ].split( '.' ); if ( selected_dates_arr[ i ].length > 1 ){ selected_dates_arr[ i ] = selected_dates_arr[ i ][ 2 ] + '-' + selected_dates_arr[ i ][ 1 ] + '-' + selected_dates_arr[ i ][ 0 ]; } } } // Remove empty elements from an array selected_dates_arr = selected_dates_arr.filter( function ( n ){ return parseInt(n); } ); selected_dates_arr.sort(); return selected_dates_arr; } /** * Get all time fields in the booking form as array of objects * * @param resource_id * @param is_only_selected_time * @returns [] * * Example: * [ * { * value_option_24h: '06:00 - 06:30' * times_as_seconds: [ 21600, 23400 ] * jquery_option: jQuery_Object {} * name: 'rangetime2[]' * } * ... * { * value_option_24h: '06:00' * times_as_seconds: [ 21600 ] * jquery_option: jQuery_Object {} * name: 'starttime2[]' * } * ] */ function wpbc_get__selected_time_fields__in_booking_form__as_arr( resource_id, is_only_selected_time = true ){ /** * Fields with [] like this select[name="rangetime1[]"] * it's when we have 'multiple' in shortcode: [select* rangetime multiple "06:00 - 06:30" ... ] */ var time_fields_arr=[ 'select[name="rangetime' + resource_id + '"]', 'select[name="rangetime' + resource_id + '[]"]', 'select[name="starttime' + resource_id + '"]', 'select[name="starttime' + resource_id + '[]"]', 'select[name="endtime' + resource_id + '"]', 'select[name="endtime' + resource_id + '[]"]', 'select[name="durationtime' + resource_id + '"]', 'select[name="durationtime' + resource_id + '[]"]' ]; var time_fields_obj_arr = []; // Loop all Time Fields for ( var ctf= 0; ctf < time_fields_arr.length; ctf++ ){ var time_field = time_fields_arr[ ctf ]; var time_option; if ( is_only_selected_time ){ time_option = jQuery( '#booking_form' + resource_id + ' ' + time_field + ' option:selected' ); // Exclude conditional fields, because of using '#booking_form3 ...' } else { time_option = jQuery( '#booking_form' + resource_id + ' ' + time_field + ' option' ); // All time fields } // Loop all options in time field for ( var j = 0; j < time_option.length; j++ ){ var jquery_option = jQuery( time_option[ j ] ); // Get only selected options //jQuery( time_field + ' option:eq(' + j + ')' ); var value_option_seconds_arr = jquery_option.val().split( '-' ); var times_as_seconds = []; // Get time as seconds if ( value_option_seconds_arr.length ){ //FixIn: 9.8.10.1 for ( let i = 0; i < value_option_seconds_arr.length; i++ ){ //FixIn: 10.0.0.56 // value_option_seconds_arr[i] = '14:00 ' | ' 16:00' (if from 'rangetime') and '16:00' if (start/end time) var start_end_times_arr = value_option_seconds_arr[ i ].trim().split( ':' ); var time_in_seconds = parseInt( start_end_times_arr[ 0 ] ) * 60 * 60 + parseInt( start_end_times_arr[ 1 ] ) * 60; times_as_seconds.push( time_in_seconds ); } } time_fields_obj_arr.push( { 'name' : jQuery( '#booking_form' + resource_id + ' ' + time_field ).attr( 'name' ), 'value_option_24h': jquery_option.val(), 'jquery_option' : jquery_option, 'times_as_seconds': times_as_seconds } ); } } // Text: [starttime] - [endtime] ----------------------------------------------------------------------------- var text_time_fields_arr=[ 'input[name="starttime' + resource_id + '"]', 'input[name="endtime' + resource_id + '"]', ]; for ( var tf= 0; tf < text_time_fields_arr.length; tf++ ){ var text_jquery = jQuery( '#booking_form' + resource_id + ' ' + text_time_fields_arr[ tf ] ); // Exclude conditional fields, because of using '#booking_form3 ...' if ( text_jquery.length > 0 ){ var time__h_m__arr = text_jquery.val().trim().split( ':' ); // '14:00' if ( 0 == time__h_m__arr.length ){ continue; // Not entered time value in a field } if ( 1 == time__h_m__arr.length ){ if ( '' === time__h_m__arr[ 0 ] ){ continue; // Not entered time value in a field } time__h_m__arr[ 1 ] = 0; } var text_time_in_seconds = parseInt( time__h_m__arr[ 0 ] ) * 60 * 60 + parseInt( time__h_m__arr[ 1 ] ) * 60; var text_times_as_seconds = []; text_times_as_seconds.push( text_time_in_seconds ); time_fields_obj_arr.push( { 'name' : text_jquery.attr( 'name' ), 'value_option_24h': text_jquery.val(), 'jquery_option' : text_jquery, 'times_as_seconds': text_times_as_seconds } ); } } return time_fields_obj_arr; } // --------------------------------------------------------------------------------------------------------------------- /* == S U P P O R T for C A L E N D A R == // --------------------------------------------------------------------------------------------------------------------- */ /** * Get Calendar datepick Instance * @param resource_id of booking resource * @returns {*|null} */ function wpbc_calendar__get_inst( resource_id ){ if ( 'undefined' === typeof (resource_id) ){ resource_id = '1'; } if ( jQuery( '#calendar_booking' + resource_id ).length > 0 ){ return jQuery.datepick._getInst( jQuery( '#calendar_booking' + resource_id ).get( 0 ) ); } return null; } /** * Unselect all dates in calendar and visually update this calendar * * @param resource_id ID of booking resource * @returns {boolean} true on success | false, if no such calendar */ function wpbc_calendar__unselect_all_dates( resource_id ){ if ( 'undefined' === typeof (resource_id) ){ resource_id = '1'; } var inst = wpbc_calendar__get_inst( resource_id ) if ( null !== inst ){ // Unselect all dates and set properties of Datepick jQuery( '#date_booking' + resource_id ).val( '' ); //FixIn: 5.4.3 inst.stayOpen = false; inst.dates = []; jQuery.datepick._updateDatepick( inst ); return true } return false; } /** * Clear days highlighting in All or specific Calendars * * @param resource_id - can be skiped to clear highlighting in all calendars */ function wpbc_calendars__clear_days_highlighting( resource_id ){ if ( 'undefined' !== typeof ( resource_id ) ){ jQuery( '#calendar_booking' + resource_id + ' .datepick-days-cell-over' ).removeClass( 'datepick-days-cell-over' ); // Clear in specific calendar } else { jQuery( '.datepick-days-cell-over' ).removeClass( 'datepick-days-cell-over' ); // Clear in all calendars } } /** * Scroll to specific month in calendar * * @param resource_id ID of resource * @param year - real year - 2023 * @param month - real month - 12 * @returns {boolean} */ function wpbc_calendar__scroll_to( resource_id, year, month ){ if ( 'undefined' === typeof (resource_id) ){ resource_id = '1'; } var inst = wpbc_calendar__get_inst( resource_id ) if ( null !== inst ){ year = parseInt( year ); month = parseInt( month ) - 1; // In JS date, month -1 inst.cursorDate = new Date(); // In some cases, the setFullYear can set only Year, and not the Month and day //FixIn:6.2.3.5 inst.cursorDate.setFullYear( year, month, 1 ); inst.cursorDate.setMonth( month ); inst.cursorDate.setDate( 1 ); inst.drawMonth = inst.cursorDate.getMonth(); inst.drawYear = inst.cursorDate.getFullYear(); jQuery.datepick._notifyChange( inst ); jQuery.datepick._adjustInstDate( inst ); jQuery.datepick._showDate( inst ); jQuery.datepick._updateDatepick( inst ); return true; } return false; } /** * Is this date selectable in calendar (mainly it's means AVAILABLE date) * * @param {int|string} resource_id 1 * @param {string} sql_class_day '2023-08-11' * @returns {boolean} true | false */ function wpbc_is_this_day_selectable( resource_id, sql_class_day ){ // Get Data -------------------------------------------------------------------------------------------------------- var date_bookings_obj = _wpbc.bookings_in_calendar__get_for_date( resource_id, sql_class_day ); var is_day_selectable = ( parseInt( date_bookings_obj[ 'day_availability' ] ) > 0 ); if ( typeof (date_bookings_obj[ 'summary' ]) === 'undefined' ){ return is_day_selectable; } if ( 'available' != date_bookings_obj[ 'summary']['status_for_day' ] ){ var is_set_pending_days_selectable = _wpbc.calendar__get_param_value( resource_id, 'pending_days_selectable' ); // set pending days selectable //FixIn: 8.6.1.18 switch ( date_bookings_obj[ 'summary']['status_for_bookings' ] ){ case 'pending': // Situations for "change-over" days: case 'pending_pending': case 'pending_approved': case 'approved_pending': is_day_selectable = (is_day_selectable) ? true : is_set_pending_days_selectable; break; default: } } return is_day_selectable; } /** * Is date to check IN array of selected dates * * @param {date}js_date_to_check - JS Date - simple JavaScript Date object * @param {[]} js_dates_arr - [ JSDate, ... ] - array of JS dates * @returns {boolean} */ function wpbc_is_this_day_among_selected_days( js_date_to_check, js_dates_arr ){ for ( var date_index = 0; date_index < js_dates_arr.length ; date_index++ ){ //FixIn: 8.4.5.16 if ( ( js_dates_arr[ date_index ].getFullYear() === js_date_to_check.getFullYear() ) && ( js_dates_arr[ date_index ].getMonth() === js_date_to_check.getMonth() ) && ( js_dates_arr[ date_index ].getDate() === js_date_to_check.getDate() ) ) { return true; } } return false; } /** * Get SQL Class Date '2023-08-01' from JS Date * * @param date JS Date * @returns {string} '2023-08-12' */ function wpbc__get__sql_class_date( date ){ var sql_class_day = date.getFullYear() + '-'; sql_class_day += ( ( date.getMonth() + 1 ) < 10 ) ? '0' : ''; sql_class_day += ( date.getMonth() + 1 ) + '-' sql_class_day += ( date.getDate() < 10 ) ? '0' : ''; sql_class_day += date.getDate(); return sql_class_day; } /** * Get JS Date from the SQL date format '2024-05-14' * @param sql_class_date * @returns {Date} */ function wpbc__get__js_date( sql_class_date ){ var sql_class_date_arr = sql_class_date.split( '-' ); var date_js = new Date(); date_js.setFullYear( parseInt( sql_class_date_arr[ 0 ] ), (parseInt( sql_class_date_arr[ 1 ] ) - 1), parseInt( sql_class_date_arr[ 2 ] ) ); // year, month, date // Without this time adjust Dates selection in Datepicker can not work!!! date_js.setHours(0); date_js.setMinutes(0); date_js.setSeconds(0); date_js.setMilliseconds(0); return date_js; } /** * Get TD Class Date '1-31-2023' from JS Date * * @param date JS Date * @returns {string} '1-31-2023' */ function wpbc__get__td_class_date( date ){ var td_class_day = (date.getMonth() + 1) + '-' + date.getDate() + '-' + date.getFullYear(); // '1-9-2023' return td_class_day; } /** * Get date params from string date * * @param date string date like '31.5.2023' * @param separator default '.' can be skipped. * @returns { {date: number, month: number, year: number} } */ function wpbc__get__date_params__from_string_date( date , separator){ separator = ( 'undefined' !== typeof (separator) ) ? separator : '.'; var date_arr = date.split( separator ); var date_obj = { 'year' : parseInt( date_arr[ 2 ] ), 'month': (parseInt( date_arr[ 1 ] ) - 1), 'date' : parseInt( date_arr[ 0 ] ) }; return date_obj; // for = new Date( date_obj.year , date_obj.month , date_obj.date ); } /** * Add Spin Loader to calendar * @param resource_id */ function wpbc_calendar__loading__start( resource_id ){ if ( ! jQuery( '#calendar_booking' + resource_id ).next().hasClass( 'wpbc_spins_loader_wrapper' ) ){ jQuery( '#calendar_booking' + resource_id ).after( '<div class="wpbc_spins_loader_wrapper"><div class="wpbc_spins_loader"></div></div>' ); } if ( ! jQuery( '#calendar_booking' + resource_id ).hasClass( 'wpbc_calendar_blur_small' ) ){ jQuery( '#calendar_booking' + resource_id ).addClass( 'wpbc_calendar_blur_small' ); } wpbc_calendar__blur__start( resource_id ); } /** * Remove Spin Loader to calendar * @param resource_id */ function wpbc_calendar__loading__stop( resource_id ){ jQuery( '#calendar_booking' + resource_id + ' + .wpbc_spins_loader_wrapper' ).remove(); jQuery( '#calendar_booking' + resource_id ).removeClass( 'wpbc_calendar_blur_small' ); wpbc_calendar__blur__stop( resource_id ); } /** * Add Blur to calendar * @param resource_id */ function wpbc_calendar__blur__start( resource_id ){ if ( ! jQuery( '#calendar_booking' + resource_id ).hasClass( 'wpbc_calendar_blur' ) ){ jQuery( '#calendar_booking' + resource_id ).addClass( 'wpbc_calendar_blur' ); } } /** * Remove Blur in calendar * @param resource_id */ function wpbc_calendar__blur__stop( resource_id ){ jQuery( '#calendar_booking' + resource_id ).removeClass( 'wpbc_calendar_blur' ); } // ................................................................................................................. /* == Calendar Update - View == // ................................................................................................................. */ /** * Update Look of calendar * * @param resource_id */ function wpbc_calendar__update_look( resource_id ){ var inst = wpbc_calendar__get_inst( resource_id ); jQuery.datepick._updateDatepick( inst ); } /** * Update dynamically Number of Months in calendar * * @param resource_id int * @param months_number int */ function wpbc_calendar__update_months_number( resource_id, months_number ){ var inst = wpbc_calendar__get_inst( resource_id ); if ( null !== inst ){ inst.settings[ 'numberOfMonths' ] = months_number; //_wpbc.calendar__set_param_value( resource_id, 'calendar_number_of_months', months_number ); wpbc_calendar__update_look( resource_id ); } } /** * Show calendar in different Skin * * @param selected_skin_url */ function wpbc__calendar__change_skin( selected_skin_url ){ //console.log( 'SKIN SELECTION ::', selected_skin_url ); // Remove CSS skin var stylesheet = document.getElementById( 'wpbc-calendar-skin-css' ); stylesheet.parentNode.removeChild( stylesheet ); // Add new CSS skin var headID = document.getElementsByTagName( "head" )[ 0 ]; var cssNode = document.createElement( 'link' ); cssNode.type = 'text/css'; cssNode.setAttribute( "id", "wpbc-calendar-skin-css" ); cssNode.rel = 'stylesheet'; cssNode.media = 'screen'; cssNode.href = selected_skin_url; //"http://beta/wp-content/plugins/booking/css/skins/green-01.css"; headID.appendChild( cssNode ); } function wpbc__css__change_skin( selected_skin_url, stylesheet_id = 'wpbc-time_picker-skin-css' ){ // Remove CSS skin var stylesheet = document.getElementById( stylesheet_id ); stylesheet.parentNode.removeChild( stylesheet ); // Add new CSS skin var headID = document.getElementsByTagName( "head" )[ 0 ]; var cssNode = document.createElement( 'link' ); cssNode.type = 'text/css'; cssNode.setAttribute( "id", stylesheet_id ); cssNode.rel = 'stylesheet'; cssNode.media = 'screen'; cssNode.href = selected_skin_url; //"http://beta/wp-content/plugins/booking/css/skins/green-01.css"; headID.appendChild( cssNode ); } // --------------------------------------------------------------------------------------------------------------------- /* == S U P P O R T M A T H == // --------------------------------------------------------------------------------------------------------------------- */ /** * Merge several intersected intervals or return not intersected: [[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]] * * @param [] intervals [ [1,3],[2,4],[6,8],[9,10],[3,7] ] * @returns [] [ [1,8],[9,10] ] * * Exmample: wpbc_intervals__merge_inersected( [ [1,3],[2,4],[6,8],[9,10],[3,7] ] ); */ function wpbc_intervals__merge_inersected( intervals ){ if ( ! intervals || intervals.length === 0 ){ return []; } var merged = []; intervals.sort( function ( a, b ){ return a[ 0 ] - b[ 0 ]; } ); var mergedInterval = intervals[ 0 ]; for ( var i = 1; i < intervals.length; i++ ){ var interval = intervals[ i ]; if ( interval[ 0 ] <= mergedInterval[ 1 ] ){ mergedInterval[ 1 ] = Math.max( mergedInterval[ 1 ], interval[ 1 ] ); } else { merged.push( mergedInterval ); mergedInterval = interval; } } merged.push( mergedInterval ); return merged; } /** * Is 2 intervals intersected: [36011, 86392] <=> [1, 43192] => true ( intersected ) * * Good explanation here https://stackoverflow.com/questions/3269434/whats-the-most-efficient-way-to-test-if-two-ranges-overlap * * @param interval_A - [ 36011, 86392 ] * @param interval_B - [ 1, 43192 ] * * @return bool */ function wpbc_intervals__is_intersected( interval_A, interval_B ) { if ( ( 0 == interval_A.length ) || ( 0 == interval_B.length ) ){ return false; } interval_A[ 0 ] = parseInt( interval_A[ 0 ] ); interval_A[ 1 ] = parseInt( interval_A[ 1 ] ); interval_B[ 0 ] = parseInt( interval_B[ 0 ] ); interval_B[ 1 ] = parseInt( interval_B[ 1 ] ); var is_intersected = Math.max( interval_A[ 0 ], interval_B[ 0 ] ) - Math.min( interval_A[ 1 ], interval_B[ 1 ] ); // if ( 0 == is_intersected ) { // // Such ranges going one after other, e.g.: [ 12, 15 ] and [ 15, 21 ] // } if ( is_intersected < 0 ) { return true; // INTERSECTED } return false; // Not intersected } /** * Get the closets ABS value of element in array to the current myValue * * @param myValue - int element to search closet 4 * @param myArray - array of elements where to search [5,8,1,7] * @returns int 5 */ function wpbc_get_abs_closest_value_in_arr( myValue, myArray ){ if ( myArray.length == 0 ){ // If the array is empty -> return the myValue return myValue; } var obj = myArray[ 0 ]; var diff = Math.abs( myValue - obj ); // Get distance between 1st element var closetValue = myArray[ 0 ]; // Save 1st element for ( var i = 1; i < myArray.length; i++ ){ obj = myArray[ i ]; if ( Math.abs( myValue - obj ) < diff ){ // we found closer value -> save it diff = Math.abs( myValue - obj ); closetValue = obj; } } return closetValue; } // --------------------------------------------------------------------------------------------------------------------- /* == T O O L T I P S == // --------------------------------------------------------------------------------------------------------------------- */ /** * Define tooltip to show, when mouse over Date in Calendar * * @param tooltip_text - Text to show 'Booked time: 12:00 - 13:00<br>Cost: $20.00' * @param resource_id - ID of booking resource '1' * @param td_class - SQL class '1-9-2023' * @returns {boolean} - defined to show or not */ function wpbc_set_tooltip___for__calendar_date( tooltip_text, resource_id, td_class ){ //TODO: make escaping of text for quot symbols, and JS/HTML... jQuery( '#calendar_booking' + resource_id + ' td.cal4date-' + td_class ).attr( 'data-content', tooltip_text ); var td_el = jQuery( '#calendar_booking' + resource_id + ' td.cal4date-' + td_class ).get( 0 ); //FixIn: 9.0.1.1 if ( ( 'undefined' !== typeof(td_el) ) && ( undefined == td_el._tippy ) && ( '' !== tooltip_text ) ){ wpbc_tippy( td_el , { content( reference ){ var popover_content = reference.getAttribute( 'data-content' ); return '<div class="popover popover_tippy">' + '<div class="popover-content">' + popover_content + '</div>' + '</div>'; }, allowHTML : true, trigger : 'mouseenter focus', interactive : false, hideOnClick : true, interactiveBorder: 10, maxWidth : 550, theme : 'wpbc-tippy-times', placement : 'top', delay : [400, 0], //FixIn: 9.4.2.2 //delay : [0, 9999999999], // Debuge tooltip ignoreAttributes : true, touch : true, //['hold', 500], // 500ms delay //FixIn: 9.2.1.5 appendTo: () => document.body, }); return true; } return false; } // --------------------------------------------------------------------------------------------------------------------- /* == Dates Functions == // --------------------------------------------------------------------------------------------------------------------- */ /** * Get number of dates between 2 JS Dates * * @param date1 JS Date * @param date2 JS Date * @returns {number} */ function wpbc_dates__days_between(date1, date2) { // The number of milliseconds in one day var ONE_DAY = 1000 * 60 * 60 * 24; // Convert both dates to milliseconds var date1_ms = date1.getTime(); var date2_ms = date2.getTime(); // Calculate the difference in milliseconds var difference_ms = date1_ms - date2_ms; // Convert back to days and return return Math.round(difference_ms/ONE_DAY); } /** * Check if this array of dates is consecutive array of dates or not. * e.g. ['2024-05-09','2024-05-19','2024-05-30'] -> false * e.g. ['2024-05-09','2024-05-10','2024-05-11'] -> true * @param sql_dates_arr array e.g.: ['2024-05-09','2024-05-19','2024-05-30'] * @returns {boolean} */ function wpbc_dates__is_consecutive_dates_arr_range( sql_dates_arr ){ //FixIn: 10.0.0.50 if ( sql_dates_arr.length > 1 ){ var previos_date = wpbc__get__js_date( sql_dates_arr[ 0 ] ); var current_date; for ( var i = 1; i < sql_dates_arr.length; i++ ){ current_date = wpbc__get__js_date( sql_dates_arr[i] ); if ( wpbc_dates__days_between( current_date, previos_date ) != 1 ){ return false; } previos_date = current_date; } } return true; } // --------------------------------------------------------------------------------------------------------------------- /* == Auto Dates Selection == // --------------------------------------------------------------------------------------------------------------------- */ /** * == How to use ? == * * For Dates selection, we need to use this logic! We need select the dates only after booking data loaded! * * Check example bellow. * * // Fire on all booking dates loaded * jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loaded_resource_id ){ * * if ( loaded_resource_id == select_dates_in_calendar_id ){ * wpbc_auto_select_dates_in_calendar( select_dates_in_calendar_id, '2024-05-15', '2024-05-25' ); * } * } ); * */ /** * Try to Auto select dates in specific calendar by simulated clicks in datepicker * * @param resource_id 1 * @param check_in_ymd '2024-05-09' OR ['2024-05-09','2024-05-19','2024-05-20'] * @param check_out_ymd '2024-05-15' Optional * * @returns {number} number of selected dates * * Example 1: var num_selected_days = wpbc_auto_select_dates_in_calendar( 1, '2024-05-15', '2024-05-25' ); * Example 2: var num_selected_days = wpbc_auto_select_dates_in_calendar( 1, ['2024-05-09','2024-05-19','2024-05-20'] ); */ function wpbc_auto_select_dates_in_calendar( resource_id, check_in_ymd, check_out_ymd = '' ){ //FixIn: 10.0.0.47 console.log( 'WPBC_AUTO_SELECT_DATES_IN_CALENDAR( RESOURCE_ID, CHECK_IN_YMD, CHECK_OUT_YMD )', resource_id, check_in_ymd, check_out_ymd ); if ( ( '2100-01-01' == check_in_ymd ) || ( '2100-01-01' == check_out_ymd ) || ( ( '' == check_in_ymd ) && ( '' == check_out_ymd ) ) ){ return 0; } // ----------------------------------------------------------------------------------------------------------------- // If check_in_ymd = [ '2024-05-09','2024-05-19','2024-05-30' ] ARRAY of DATES //FixIn: 10.0.0.50 // ----------------------------------------------------------------------------------------------------------------- var dates_to_select_arr = []; if ( Array.isArray( check_in_ymd ) ){ dates_to_select_arr = wpbc_clone_obj( check_in_ymd ); // ------------------------------------------------------------------------------------------------------------- // Exceptions to set MULTIPLE DAYS mode // ------------------------------------------------------------------------------------------------------------- // if dates as NOT CONSECUTIVE: ['2024-05-09','2024-05-19','2024-05-30'], -> set MULTIPLE DAYS mode if ( ( dates_to_select_arr.length > 0 ) && ( '' == check_out_ymd ) && ( ! wpbc_dates__is_consecutive_dates_arr_range( dates_to_select_arr ) ) ){ wpbc_cal_days_select__multiple( resource_id ); } // if multiple days to select, but enabled SINGLE day mode, -> set MULTIPLE DAYS mode if ( ( dates_to_select_arr.length > 1 ) && ( '' == check_out_ymd ) && ( 'single' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ) ){ wpbc_cal_days_select__multiple( resource_id ); } // ------------------------------------------------------------------------------------------------------------- check_in_ymd = dates_to_select_arr[ 0 ]; if ( '' == check_out_ymd ){ check_out_ymd = dates_to_select_arr[ (dates_to_select_arr.length-1) ]; } } // ----------------------------------------------------------------------------------------------------------------- if ( '' == check_in_ymd ){ check_in_ymd = check_out_ymd; } if ( '' == check_out_ymd ){ check_out_ymd = check_in_ymd; } if ( 'undefined' === typeof (resource_id) ){ resource_id = '1'; } var inst = wpbc_calendar__get_inst( resource_id ); if ( null !== inst ){ // Unselect all dates and set properties of Datepick jQuery( '#date_booking' + resource_id ).val( '' ); //FixIn: 5.4.3 inst.stayOpen = false; inst.dates = []; var check_in_js = wpbc__get__js_date( check_in_ymd ); var td_cell = wpbc_get_clicked_td( inst.id, check_in_js ); // --------------------------------------------------------------------------------------------------------- // == DYNAMIC == if ( 'dynamic' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ){ // 1-st click inst.stayOpen = false; jQuery.datepick._selectDay( td_cell, '#' + inst.id, check_in_js.getTime() ); if ( 0 === inst.dates.length ){ return 0; // First click was unsuccessful, so we must not make other click } // 2-nd click var check_out_js = wpbc__get__js_date( check_out_ymd ); var td_cell_out = wpbc_get_clicked_td( inst.id, check_out_js ); inst.stayOpen = true; jQuery.datepick._selectDay( td_cell_out, '#' + inst.id, check_out_js.getTime() ); } // --------------------------------------------------------------------------------------------------------- // == FIXED == if ( 'fixed' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' )) { jQuery.datepick._selectDay( td_cell, '#' + inst.id, check_in_js.getTime() ); } // --------------------------------------------------------------------------------------------------------- // == SINGLE == if ( 'single' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ){ //jQuery.datepick._restrictMinMax( inst, jQuery.datepick._determineDate( inst, check_in_js, null ) ); // Do we need to run this ? Please note, check_in_js must have time, min, sec defined to 0! jQuery.datepick._selectDay( td_cell, '#' + inst.id, check_in_js.getTime() ); } // --------------------------------------------------------------------------------------------------------- // == MULTIPLE == if ( 'multiple' === _wpbc.calendar__get_param_value( resource_id, 'days_select_mode' ) ){ var dates_arr; if ( dates_to_select_arr.length > 0 ){ // Situation, when we have dates array: ['2024-05-09','2024-05-19','2024-05-30']. and not the Check In / Check out dates as parameter in this function dates_arr = wpbc_get_selection_dates_js_str_arr__from_arr( dates_to_select_arr ); } else { dates_arr = wpbc_get_selection_dates_js_str_arr__from_check_in_out( check_in_ymd, check_out_ymd, inst ); } if ( 0 === dates_arr.dates_js.length ){ return 0; } // For Calendar Days selection for ( var j = 0; j < dates_arr.dates_js.length; j++ ){ // Loop array of dates var str_date = wpbc__get__sql_class_date( dates_arr.dates_js[ j ] ); // Date unavailable ! if ( 0 == _wpbc.bookings_in_calendar__get_for_date( resource_id, str_date ).day_availability ){ return 0; } if ( dates_arr.dates_js[ j ] != -1 ) { inst.dates.push( dates_arr.dates_js[ j ] ); } } var check_out_date = dates_arr.dates_js[ (dates_arr.dates_js.length - 1) ]; inst.dates.push( check_out_date ); // Need add one additional SAME date for correct works of dates selection !!!!! var checkout_timestamp = check_out_date.getTime(); var td_cell = wpbc_get_clicked_td( inst.id, check_out_date ); jQuery.datepick._selectDay( td_cell, '#' + inst.id, checkout_timestamp ); } if ( 0 !== inst.dates.length ){ // Scroll to specific month, if we set dates in some future months wpbc_calendar__scroll_to( resource_id, inst.dates[ 0 ].getFullYear(), inst.dates[ 0 ].getMonth()+1 ); } return inst.dates.length; } return 0; } /** * Get HTML td element (where was click in calendar day cell) * * @param calendar_html_id 'calendar_booking1' * @param date_js JS Date * @returns {*|jQuery} Dom HTML td element */ function wpbc_get_clicked_td( calendar_html_id, date_js ){ var td_cell = jQuery( '#' + calendar_html_id + ' .sql_date_' + wpbc__get__sql_class_date( date_js ) ).get( 0 ); return td_cell; } /** * Get arrays of JS and SQL dates as dates array * * @param check_in_ymd '2024-05-15' * @param check_out_ymd '2024-05-25' * @param inst Datepick Inst. Use wpbc_calendar__get_inst( resource_id ); * @returns {{dates_js: *[], dates_str: *[]}} */ function wpbc_get_selection_dates_js_str_arr__from_check_in_out( check_in_ymd, check_out_ymd , inst ){ var original_array = []; var date; var bk_distinct_dates = []; var check_in_date = check_in_ymd.split( '-' ); var check_out_date = check_out_ymd.split( '-' ); date = new Date(); date.setFullYear( check_in_date[ 0 ], (check_in_date[ 1 ] - 1), check_in_date[ 2 ] ); // year, month, date var original_check_in_date = date; original_array.push( jQuery.datepick._restrictMinMax( inst, jQuery.datepick._determineDate( inst, date, null ) ) ); //add date if ( ! wpbc_in_array( bk_distinct_dates, (check_in_date[ 2 ] + '.' + check_in_date[ 1 ] + '.' + check_in_date[ 0 ]) ) ){ bk_distinct_dates.push( parseInt(check_in_date[ 2 ]) + '.' + parseInt(check_in_date[ 1 ]) + '.' + check_in_date[ 0 ] ); } var date_out = new Date(); date_out.setFullYear( check_out_date[ 0 ], (check_out_date[ 1 ] - 1), check_out_date[ 2 ] ); // year, month, date var original_check_out_date = date_out; var mewDate = new Date( original_check_in_date.getFullYear(), original_check_in_date.getMonth(), original_check_in_date.getDate() ); mewDate.setDate( original_check_in_date.getDate() + 1 ); while ( (original_check_out_date > date) && (original_check_in_date != original_check_out_date) ){ date = new Date( mewDate.getFullYear(), mewDate.getMonth(), mewDate.getDate() ); original_array.push( jQuery.datepick._restrictMinMax( inst, jQuery.datepick._determineDate( inst, date, null ) ) ); //add date if ( !wpbc_in_array( bk_distinct_dates, (date.getDate() + '.' + parseInt( date.getMonth() + 1 ) + '.' + date.getFullYear()) ) ){ bk_distinct_dates.push( (parseInt(date.getDate()) + '.' + parseInt( date.getMonth() + 1 ) + '.' + date.getFullYear()) ); } mewDate = new Date( date.getFullYear(), date.getMonth(), date.getDate() ); mewDate.setDate( mewDate.getDate() + 1 ); } original_array.pop(); bk_distinct_dates.pop(); return {'dates_js': original_array, 'dates_str': bk_distinct_dates}; } /** * Get arrays of JS and SQL dates as dates array * * @param dates_to_select_arr = ['2024-05-09','2024-05-19','2024-05-30'] * * @returns {{dates_js: *[], dates_str: *[]}} */ function wpbc_get_selection_dates_js_str_arr__from_arr( dates_to_select_arr ){ //FixIn: 10.0.0.50 var original_array = []; var bk_distinct_dates = []; var one_date_str; for ( var d = 0; d < dates_to_select_arr.length; d++ ){ original_array.push( wpbc__get__js_date( dates_to_select_arr[ d ] ) ); one_date_str = dates_to_select_arr[ d ].split('-') if ( ! wpbc_in_array( bk_distinct_dates, (one_date_str[ 2 ] + '.' + one_date_str[ 1 ] + '.' + one_date_str[ 0 ]) ) ){ bk_distinct_dates.push( parseInt(one_date_str[ 2 ]) + '.' + parseInt(one_date_str[ 1 ]) + '.' + one_date_str[ 0 ] ); } } return {'dates_js': original_array, 'dates_str': original_array}; } // ===================================================================================================================== /* == Auto Fill Fields / Auto Select Dates == // ===================================================================================================================== */ jQuery( document ).ready( function (){ var url_params = new URLSearchParams( window.location.search ); // Disable days selection in calendar, after redirection from the "Search results page, after search availability" //FixIn: 8.8.2.3 if ( 'On' != _wpbc.get_other_param( 'is_enabled_booking_search_results_days_select' ) ) { if ( ( url_params.has( 'wpbc_select_check_in' ) ) && ( url_params.has( 'wpbc_select_check_out' ) ) && ( url_params.has( 'wpbc_select_calendar_id' ) ) ){ var select_dates_in_calendar_id = parseInt( url_params.get( 'wpbc_select_calendar_id' ) ); // Fire on all booking dates loaded jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loaded_resource_id ){ if ( loaded_resource_id == select_dates_in_calendar_id ){ wpbc_auto_select_dates_in_calendar( select_dates_in_calendar_id, url_params.get( 'wpbc_select_check_in' ), url_params.get( 'wpbc_select_check_out' ) ); } } ); } } if ( url_params.has( 'wpbc_auto_fill' ) ){ var wpbc_auto_fill_value = url_params.get( 'wpbc_auto_fill' ); // Convert back. Some systems do not like symbol '~' in URL, so we need to replace to some other symbols wpbc_auto_fill_value = wpbc_auto_fill_value.replaceAll( '_^_', '~' ); wpbc_auto_fill_booking_fields( wpbc_auto_fill_value ); } } ); /** * Autofill / select booking form fields by values from the GET request parameter: ?wpbc_auto_fill= * * @param auto_fill_str */ function wpbc_auto_fill_booking_fields( auto_fill_str ){ //FixIn: 10.0.0.48 if ( '' == auto_fill_str ){ return; } // console.log( 'WPBC_AUTO_FILL_BOOKING_FIELDS( AUTO_FILL_STR )', auto_fill_str); var fields_arr = wpbc_auto_fill_booking_fields__parse( auto_fill_str ); for ( let i = 0; i < fields_arr.length; i++ ){ jQuery( '[name="' + fields_arr[ i ][ 'name' ] + '"]' ).val( fields_arr[ i ][ 'value' ] ); } } /** * Parse data from get parameter: ?wpbc_auto_fill=visitors231^2~max_capacity231^2 * * @param data_str = 'visitors231^2~max_capacity231^2'; * @returns {*} */ function wpbc_auto_fill_booking_fields__parse( data_str ){ var filter_options_arr = []; var data_arr = data_str.split( '~' ); for ( var j = 0; j < data_arr.length; j++ ){ var my_form_field = data_arr[ j ].split( '^' ); var filter_name = ('undefined' !== typeof (my_form_field[ 0 ])) ? my_form_field[ 0 ] : ''; var filter_value = ('undefined' !== typeof (my_form_field[ 1 ])) ? my_form_field[ 1 ] : ''; filter_options_arr.push( { 'name' : filter_name, 'value' : filter_value } ); } return filter_options_arr; } /** * Parse data from get parameter: ?search_get__custom_params=... * * @param data_str = 'text^search_field__display_check_in^23.05.2024~text^search_field__display_check_out^26.05.2024~selectbox-one^search_quantity^2~selectbox-one^location^Spain~selectbox-one^max_capacity^2~selectbox-one^amenity^parking~checkbox^search_field__extend_search_days^5~submit^^Search~hidden^search_get__check_in_ymd^2024-05-23~hidden^search_get__check_out_ymd^2024-05-26~hidden^search_get__time^~hidden^search_get__quantity^2~hidden^search_get__extend^5~hidden^search_get__users_id^~hidden^search_get__custom_params^~'; * @returns {*} */ function wpbc_auto_fill_search_fields__parse( data_str ){ var filter_options_arr = []; var data_arr = data_str.split( '~' ); for ( var j = 0; j < data_arr.length; j++ ){ var my_form_field = data_arr[ j ].split( '^' ); var filter_type = ('undefined' !== typeof (my_form_field[ 0 ])) ? my_form_field[ 0 ] : ''; var filter_name = ('undefined' !== typeof (my_form_field[ 1 ])) ? my_form_field[ 1 ] : ''; var filter_value = ('undefined' !== typeof (my_form_field[ 2 ])) ? my_form_field[ 2 ] : ''; filter_options_arr.push( { 'type' : filter_type, 'name' : filter_name, 'value' : filter_value } ); } return filter_options_arr; } // --------------------------------------------------------------------------------------------------------------------- /* == Auto Update number of months in calendars ON screen size changed == // --------------------------------------------------------------------------------------------------------------------- */ /** * Auto Update Number of Months in Calendar, e.g.: if ( WINDOW_WIDTH <= 782px ) >>> MONTHS_NUMBER = 1 * ELSE: number of months defined in shortcode. * @param resource_id int * */ function wpbc_calendar__auto_update_months_number__on_resize( resource_id ){ var local__number_of_months = parseInt( _wpbc.calendar__get_param_value( resource_id, 'calendar_number_of_months' ) ); if ( local__number_of_months > 1 ){ if ( jQuery( window ).width() <= 782 ){ wpbc_calendar__update_months_number( resource_id, 1 ); } else { wpbc_calendar__update_months_number( resource_id, local__number_of_months ); } } } /** * Auto Update Number of Months in ALL Calendars * */ function wpbc_calendars__auto_update_months_number(){ var all_calendars_arr = _wpbc.calendars_all__get(); // This LOOP "for in" is GOOD, because we check here keys 'calendar_' === calendar_id.slice( 0, 9 ) for ( var calendar_id in all_calendars_arr ){ if ( 'calendar_' === calendar_id.slice( 0, 9 ) ){ var resource_id = parseInt( calendar_id.slice( 9 ) ); // 'calendar_3' -> 3 if ( resource_id > 0 ){ wpbc_calendar__auto_update_months_number__on_resize( resource_id ); } } } } /** * If browser window changed, then update number of months. */ jQuery( window ).on( 'resize', function (){ wpbc_calendars__auto_update_months_number(); } ); /** * Auto update calendar number of months on initial page load */ jQuery( document ).ready( function (){ var closed_timer = setTimeout( function (){ wpbc_calendars__auto_update_months_number(); }, 100 ); }); cal_ajx_load/wpbc_cal_ajx.js 0000666 00000026054 15165320372 0012135 0 ustar 00 /** * ==================================================================================================================== * includes/__js/cal_ajx_load/wpbc_cal_ajx.js * ==================================================================================================================== */ // --------------------------------------------------------------------------------------------------------------------- // A j a x L o a d C a l e n d a r D a t a // --------------------------------------------------------------------------------------------------------------------- function wpbc_calendar__load_data__ajx( params ){ //FixIn: 9.8.6.2 wpbc_calendar__loading__start( params['resource_id'] ); if ( wpbc_balancer__is_wait( params , 'wpbc_calendar__load_data__ajx' ) ){ return false; } //FixIn: 9.8.6.2 wpbc_calendar__blur__stop( params['resource_id'] ); // console.groupEnd(); console.time('resource_id_' + params['resource_id']); console.groupCollapsed( 'WPBC_AJX_CALENDAR_LOAD' ); console.log( ' == Before Ajax Send - calendars_all__get() == ' , _wpbc.calendars_all__get() ); // Start Ajax jQuery.post( wpbc_url_ajax, { action : 'WPBC_AJX_CALENDAR_LOAD', wpbc_ajx_user_id: _wpbc.get_secure_param( 'user_id' ), nonce : _wpbc.get_secure_param( 'nonce' ), wpbc_ajx_locale : _wpbc.get_secure_param( 'locale' ), calendar_request_params : params // Usually like: { 'resource_id': 1, 'max_days_count': 365 } }, /** * S u c c e s s * * @param response_data - its object returned from Ajax - class-live-search.php * @param textStatus - 'success' * @param jqXHR - Object */ function ( response_data, textStatus, jqXHR ) { // console.timeEnd('resource_id_' + response_data['resource_id']); console.log( ' == Response WPBC_AJX_CALENDAR_LOAD == ', response_data ); console.groupEnd(); //FixIn: 9.8.6.2 var ajx_post_data__resource_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); wpbc_balancer__completed( ajx_post_data__resource_id , 'wpbc_calendar__load_data__ajx' ); // Probably Error if ( (typeof response_data !== 'object') || (response_data === null) ){ var jq_node = wpbc_get_calendar__jq_node__for_messages( this.data ); var message_type = 'info'; if ( '' === response_data ){ response_data = 'The server responds with an empty string. The server probably stopped working unexpectedly. <br>Please check your <strong>error.log</strong> in your server configuration for relative errors.'; message_type = 'warning'; } // Show Message wpbc_front_end__show_message( response_data , { 'type' : message_type, 'show_here': {'jq_node': jq_node, 'where': 'after'}, 'is_append': true, 'style' : 'text-align:left;', 'delay' : 0 } ); return; } // Show Calendar wpbc_calendar__loading__stop( response_data[ 'resource_id' ] ); // ------------------------------------------------------------------------------------------------- // Bookings - Dates _wpbc.bookings_in_calendar__set_dates( response_data[ 'resource_id' ], response_data[ 'ajx_data' ]['dates'] ); // Bookings - Child or only single booking resource in dates _wpbc.booking__set_param_value( response_data[ 'resource_id' ], 'resources_id_arr__in_dates', response_data[ 'ajx_data' ][ 'resources_id_arr__in_dates' ] ); // Aggregate booking resources, if any ? _wpbc.booking__set_param_value( response_data[ 'resource_id' ], 'aggregate_resource_id_arr', response_data[ 'ajx_data' ][ 'aggregate_resource_id_arr' ] ); // ------------------------------------------------------------------------------------------------- // Update calendar wpbc_calendar__update_look( response_data[ 'resource_id' ] ); if ( ( 'undefined' !== typeof (response_data[ 'ajx_data' ][ 'ajx_after_action_message' ]) ) && ( '' != response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ) ) ){ var jq_node = wpbc_get_calendar__jq_node__for_messages( this.data ); // Show Message wpbc_front_end__show_message( response_data[ 'ajx_data' ][ 'ajx_after_action_message' ].replace( /\n/g, "<br />" ), { 'type' : ( 'undefined' !== typeof( response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] ) ) ? response_data[ 'ajx_data' ][ 'ajx_after_action_message_status' ] : 'info', 'show_here': {'jq_node': jq_node, 'where': 'after'}, 'is_append': true, 'style' : 'text-align:left;', 'delay' : 10000 } ); } // Trigger event that calendar has been //FixIn: 10.0.0.44 if ( jQuery( '#calendar_booking' + response_data[ 'resource_id' ] ).length > 0 ){ var target_elm = jQuery( 'body' ).trigger( "wpbc_calendar_ajx__loaded_data", [response_data[ 'resource_id' ]] ); //jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function( event, resource_id ) { ... } ); } //jQuery( '#ajax_respond' ).html( response_data ); // For ability to show response, add such DIV element to page } ).fail( function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } var ajx_post_data__resource_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); wpbc_balancer__completed( ajx_post_data__resource_id , 'wpbc_calendar__load_data__ajx' ); // Get Content of Error Message var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; if ( jqXHR.status ){ error_message += ' (<b>' + jqXHR.status + '</b>)'; if (403 == jqXHR.status ){ error_message += '<br> Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.'; error_message += '<br> Otherwise, please check this <a style="font-weight: 600;" href="https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?after_update=10.1.1">troubleshooting instruction</a>.<br>' } } var message_show_delay = 3000; if ( jqXHR.responseText ){ error_message += ' ' + jqXHR.responseText; message_show_delay = 10; } error_message = error_message.replace( /\n/g, "<br />" ); var jq_node = wpbc_get_calendar__jq_node__for_messages( this.data ); /** * If we make fast clicking on different pages, * then under calendar will show error message with empty text, because ajax was not received. * To not show such warnings we are set delay in 3 seconds. var message_show_delay = 3000; */ var closed_timer = setTimeout( function (){ // Show Message wpbc_front_end__show_message( error_message , { 'type' : 'error', 'show_here': {'jq_node': jq_node, 'where': 'after'}, 'is_append': true, 'style' : 'text-align:left;', 'css_class':'wpbc_fe_message_alt', 'delay' : 0 } ); } , parseInt( message_show_delay ) ); }) // .done( function ( data, textStatus, jqXHR ) { if ( window.console && window.console.log ){ console.log( 'second success', data, textStatus, jqXHR ); } }) // .always( function ( data_jqXHR, textStatus, jqXHR_errorThrown ) { if ( window.console && window.console.log ){ console.log( 'always finished', data_jqXHR, textStatus, jqXHR_errorThrown ); } }) ; // End Ajax } // --------------------------------------------------------------------------------------------------------------------- // Support // --------------------------------------------------------------------------------------------------------------------- /** * Get Calendar jQuery node for showing messages during Ajax * This parameter: calendar_request_params[resource_id] parsed from this.data Ajax post data * * @param ajx_post_data_url_params 'action=WPBC_AJX_CALENDAR_LOAD...&calendar_request_params%5Bresource_id%5D=2&calendar_request_params%5Bbooking_hash%5D=&calendar_request_params' * @returns {string} ''#calendar_booking1' | '.booking_form_div' ... * * Example var jq_node = wpbc_get_calendar__jq_node__for_messages( this.data ); */ function wpbc_get_calendar__jq_node__for_messages( ajx_post_data_url_params ){ var jq_node = '.booking_form_div'; var calendar_resource_id = wpbc_get_resource_id__from_ajx_post_data_url( ajx_post_data_url_params ); if ( calendar_resource_id > 0 ){ jq_node = '#calendar_booking' + calendar_resource_id; } return jq_node; } /** * Get resource ID from ajx post data url usually from this.data = 'action=WPBC_AJX_CALENDAR_LOAD...&calendar_request_params%5Bresource_id%5D=2&calendar_request_params%5Bbooking_hash%5D=&calendar_request_params' * * @param ajx_post_data_url_params 'action=WPBC_AJX_CALENDAR_LOAD...&calendar_request_params%5Bresource_id%5D=2&calendar_request_params%5Bbooking_hash%5D=&calendar_request_params' * @returns {int} 1 | 0 (if errror then 0) * * Example var jq_node = wpbc_get_calendar__jq_node__for_messages( this.data ); */ function wpbc_get_resource_id__from_ajx_post_data_url( ajx_post_data_url_params ){ // Get booking resource ID from Ajax Post Request -> this.data = 'action=WPBC_AJX_CALENDAR_LOAD...&calendar_request_params%5Bresource_id%5D=2&calendar_request_params%5Bbooking_hash%5D=&calendar_request_params' var calendar_resource_id = wpbc_get_uri_param_by_name( 'calendar_request_params[resource_id]', ajx_post_data_url_params ); if ( (null !== calendar_resource_id) && ('' !== calendar_resource_id) ){ calendar_resource_id = parseInt( calendar_resource_id ); if ( calendar_resource_id > 0 ){ return calendar_resource_id; } } return 0; } /** * Get parameter from URL - parse URL parameters, like this: action=WPBC_AJX_CALENDAR_LOAD...&calendar_request_params%5Bresource_id%5D=2&calendar_request_params%5Bbooking_hash%5D=&calendar_request_params * @param name parameter name, like 'calendar_request_params[resource_id]' * @param url 'parameter string URL' * @returns {string|null} parameter value * * Example: wpbc_get_uri_param_by_name( 'calendar_request_params[resource_id]', this.data ); -> '2' */ function wpbc_get_uri_param_by_name( name, url ){ url = decodeURIComponent( url ); name = name.replace( /[\[\]]/g, '\\$&' ); var regex = new RegExp( '[?&]' + name + '(=([^&#]*)|&|#|$)' ), results = regex.exec( url ); if ( !results ) return null; if ( !results[ 2 ] ) return ''; return decodeURIComponent( results[ 2 ].replace( /\+/g, ' ' ) ); } popover/timeline_popover.js 0000666 00000003024 15165320372 0012163 0 ustar 00 //FixIn: 10.2.0.4 /** * Define Popovers for Timelines in WP Booking Calendar * * @returns {string|boolean} */ function wpbc_define_tippy_popover(){ if ( 'function' !== typeof (wpbc_tippy) ){ console.log( 'WPBC Error. wpbc_tippy was not defined.' ); return false; } wpbc_tippy( '.popover_bottom.popover_click', { content( reference ){ var popover_title = reference.getAttribute( 'data-original-title' ); var popover_content = reference.getAttribute( 'data-content' ); return '<div class="popover popover_tippy">' + '<div class="popover-close"><a href="javascript:void(0)" onclick="javascript:this.parentElement.parentElement.parentElement.parentElement.parentElement._tippy.hide();" >×</a></div>' + popover_content + '</div>'; }, allowHTML : true, trigger : 'manual', interactive : true, hideOnClick : false, interactiveBorder: 10, maxWidth : 550, theme : 'wpbc-tippy-popover', placement : 'bottom-start', touch : ['hold', 500], } ); jQuery( '.popover_bottom.popover_click' ).on( 'click', function (){ if ( this._tippy.state.isVisible ){ this._tippy.hide(); } else { this._tippy.show(); } } ); wpbc_define_hide_tippy_on_scroll(); } function wpbc_define_hide_tippy_on_scroll(){ jQuery( '.flex_tl__scrolling_section2,.flex_tl__scrolling_sections' ).on( 'scroll', function ( event ){ if ( 'function' === typeof (wpbc_tippy) ){ wpbc_tippy.hideAll(); } } ); } load_balancer/ajx_load_balancer.js 0000666 00000014753 15165320372 0013302 0 ustar 00 /** * Extend _wpbc with new methods //FixIn: 9.8.6.2 * * @type {*|{}} * @private */ _wpbc = (function ( obj, $) { // Load Balancer ----------------------------------------------------------------------------------------------- var p_balancer = obj.balancer_obj = obj.balancer_obj || { 'max_threads': 2, 'in_process' : [], 'wait' : [] }; /** * Set max parallel request to load * * @param max_threads */ obj.balancer__set_max_threads = function ( max_threads ){ p_balancer[ 'max_threads' ] = max_threads; }; /** * Check if balancer for specific booking resource defined :: true | false * * @param {string|int} resource_id * @returns {boolean} */ obj.balancer__is_defined = function ( resource_id ) { return ('undefined' !== typeof( p_balancer[ 'balancer_' + resource_id ] ) ); }; /** * Create balancer initializing * * @param {string|int} resource_id */ obj.balancer__init = function ( resource_id, function_name , params ={}) { var balance_obj = {}; balance_obj[ 'resource_id' ] = resource_id; balance_obj[ 'priority' ] = 1; balance_obj[ 'function_name' ] = function_name; balance_obj[ 'params' ] = wpbc_clone_obj( params ); if ( obj.balancer__is_already_run( resource_id, function_name ) ){ return 'run'; } if ( obj.balancer__is_already_wait( resource_id, function_name ) ){ return 'wait'; } if ( obj.balancer__can_i_run() ){ obj.balancer__add_to__run( balance_obj ); return 'run'; } else { obj.balancer__add_to__wait( balance_obj ); return 'wait'; } }; /** * Can I Run ? * @returns {boolean} */ obj.balancer__can_i_run = function (){ return ( p_balancer[ 'in_process' ].length < p_balancer[ 'max_threads' ] ); } /** * Add to WAIT * @param balance_obj */ obj.balancer__add_to__wait = function ( balance_obj ) { p_balancer['wait'].push( balance_obj ); } /** * Remove from Wait * * @param resource_id * @param function_name * @returns {*|boolean} */ obj.balancer__remove_from__wait_list = function ( resource_id, function_name ){ var removed_el = false; if ( p_balancer[ 'wait' ].length ){ //FixIn: 9.8.10.1 for ( var i in p_balancer[ 'wait' ] ){ if ( (resource_id === p_balancer[ 'wait' ][ i ][ 'resource_id' ]) && (function_name === p_balancer[ 'wait' ][ i ][ 'function_name' ]) ){ removed_el = p_balancer[ 'wait' ].splice( i, 1 ); removed_el = removed_el.pop(); p_balancer[ 'wait' ] = p_balancer[ 'wait' ].filter( function ( v ){ return v; } ); // Reindex array return removed_el; } } } return removed_el; } /** * Is already WAIT * * @param resource_id * @param function_name * @returns {boolean} */ obj.balancer__is_already_wait = function ( resource_id, function_name ){ if ( p_balancer[ 'wait' ].length ){ //FixIn: 9.8.10.1 for ( var i in p_balancer[ 'wait' ] ){ if ( (resource_id === p_balancer[ 'wait' ][ i ][ 'resource_id' ]) && (function_name === p_balancer[ 'wait' ][ i ][ 'function_name' ]) ){ return true; } } } return false; } /** * Add to RUN * @param balance_obj */ obj.balancer__add_to__run = function ( balance_obj ) { p_balancer['in_process'].push( balance_obj ); } /** * Remove from RUN list * * @param resource_id * @param function_name * @returns {*|boolean} */ obj.balancer__remove_from__run_list = function ( resource_id, function_name ){ var removed_el = false; if ( p_balancer[ 'in_process' ].length ){ //FixIn: 9.8.10.1 for ( var i in p_balancer[ 'in_process' ] ){ if ( (resource_id === p_balancer[ 'in_process' ][ i ][ 'resource_id' ]) && (function_name === p_balancer[ 'in_process' ][ i ][ 'function_name' ]) ){ removed_el = p_balancer[ 'in_process' ].splice( i, 1 ); removed_el = removed_el.pop(); p_balancer[ 'in_process' ] = p_balancer[ 'in_process' ].filter( function ( v ){ return v; } ); // Reindex array return removed_el; } } } return removed_el; } /** * Is already RUN * * @param resource_id * @param function_name * @returns {boolean} */ obj.balancer__is_already_run = function ( resource_id, function_name ){ if ( p_balancer[ 'in_process' ].length ){ //FixIn: 9.8.10.1 for ( var i in p_balancer[ 'in_process' ] ){ if ( (resource_id === p_balancer[ 'in_process' ][ i ][ 'resource_id' ]) && (function_name === p_balancer[ 'in_process' ][ i ][ 'function_name' ]) ){ return true; } } } return false; } obj.balancer__run_next = function (){ // Get 1st from Wait list var removed_el = false; if ( p_balancer[ 'wait' ].length ){ //FixIn: 9.8.10.1 for ( var i in p_balancer[ 'wait' ] ){ removed_el = obj.balancer__remove_from__wait_list( p_balancer[ 'wait' ][ i ][ 'resource_id' ], p_balancer[ 'wait' ][ i ][ 'function_name' ] ); break; } } if ( false !== removed_el ){ // Run obj.balancer__run( removed_el ); } } /** * Run * @param balance_obj */ obj.balancer__run = function ( balance_obj ){ switch ( balance_obj[ 'function_name' ] ){ case 'wpbc_calendar__load_data__ajx': // Add to run list obj.balancer__add_to__run( balance_obj ); wpbc_calendar__load_data__ajx( balance_obj[ 'params' ] ) break; default: } } return obj; }( _wpbc || {}, jQuery )); /** * -- Help functions ---------------------------------------------------------------------------------------------- */ function wpbc_balancer__is_wait( params, function_name ){ //console.log('::wpbc_balancer__is_wait',params , function_name ); if ( 'undefined' !== typeof (params[ 'resource_id' ]) ){ var balancer_status = _wpbc.balancer__init( params[ 'resource_id' ], function_name, params ); return ( 'wait' === balancer_status ); } return false; } function wpbc_balancer__completed( resource_id , function_name ){ //console.log('::wpbc_balancer__completed',resource_id , function_name ); _wpbc.balancer__remove_from__run_list( resource_id, function_name ); _wpbc.balancer__run_next(); } wpbc/wpbc.js 0000666 00000045003 15165320372 0007002 0 ustar 00 "use strict"; /** * ===================================================================================================================== * includes/__js/wpbc/wpbc.js * ===================================================================================================================== */ /** * Deep Clone of object or array * * @param obj * @returns {any} */ function wpbc_clone_obj( obj ){ return JSON.parse( JSON.stringify( obj ) ); } /** * Main _wpbc JS object */ var _wpbc = (function ( obj, $) { // Secure parameters for Ajax ------------------------------------------------------------------------------------ var p_secure = obj.security_obj = obj.security_obj || { user_id: 0, nonce : '', locale : '' }; obj.set_secure_param = function ( param_key, param_val ) { p_secure[ param_key ] = param_val; }; obj.get_secure_param = function ( param_key ) { return p_secure[ param_key ]; }; // Calendars ---------------------------------------------------------------------------------------------------- var p_calendars = obj.calendars_obj = obj.calendars_obj || { // sort : "booking_id", // sort_type : "DESC", // page_num : 1, // page_items_count: 10, // create_date : "", // keyword : "", // source : "" }; /** * Check if calendar for specific booking resource defined :: true | false * * @param {string|int} resource_id * @returns {boolean} */ obj.calendar__is_defined = function ( resource_id ) { return ('undefined' !== typeof( p_calendars[ 'calendar_' + resource_id ] ) ); }; /** * Create Calendar initializing * * @param {string|int} resource_id */ obj.calendar__init = function ( resource_id ) { p_calendars[ 'calendar_' + resource_id ] = {}; p_calendars[ 'calendar_' + resource_id ][ 'id' ] = resource_id; p_calendars[ 'calendar_' + resource_id ][ 'pending_days_selectable' ] = false; }; /** * Check if the type of this property is INT * @param property_name * @returns {boolean} */ obj.calendar__is_prop_int = function ( property_name ) { //FixIn: 9.9.0.29 var p_calendar_int_properties = ['dynamic__days_min', 'dynamic__days_max', 'fixed__days_num']; var is_include = p_calendar_int_properties.includes( property_name ); return is_include; }; /** * Set params for all calendars * * @param {object} calendars_obj Object { calendar_1: {} } * calendar_3: {}, ... } */ obj.calendars_all__set = function ( calendars_obj ) { p_calendars = calendars_obj; }; /** * Get bookings in all calendars * * @returns {object|{}} */ obj.calendars_all__get = function () { return p_calendars; }; /** * Get calendar object :: { id: 1, … } * * @param {string|int} resource_id '2' * @returns {object|boolean} { id: 2 ,… } */ obj.calendar__get_parameters = function ( resource_id ) { if ( obj.calendar__is_defined( resource_id ) ){ return p_calendars[ 'calendar_' + resource_id ]; } else { return false; } }; /** * Set calendar object :: { dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * * if calendar object not defined, then it's will be defined and ID set * if calendar exist, then system set as new or overwrite only properties from calendar_property_obj parameter, but other properties will be existed and not overwrite, like 'id' * * @param {string|int} resource_id '2' * @param {object} calendar_property_obj { dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } } * @param {boolean} is_complete_overwrite if 'true' (default: 'false'), then only overwrite or add new properties in calendar_property_obj * @returns {*} * * Examples: * * Common usage in PHP: * echo " _wpbc.calendar__set( " .intval( $resource_id ) . ", { 'dates': " . wp_json_encode( $availability_per_days_arr ) . " } );"; */ obj.calendar__set_parameters = function ( resource_id, calendar_property_obj, is_complete_overwrite = false ) { if ( (!obj.calendar__is_defined( resource_id )) || (true === is_complete_overwrite) ){ obj.calendar__init( resource_id ); } for ( var prop_name in calendar_property_obj ){ p_calendars[ 'calendar_' + resource_id ][ prop_name ] = calendar_property_obj[ prop_name ]; } return p_calendars[ 'calendar_' + resource_id ]; }; /** * Set property to calendar * @param resource_id "1" * @param prop_name name of property * @param prop_value value of property * @returns {*} calendar object */ obj.calendar__set_param_value = function ( resource_id, prop_name, prop_value ) { if ( (!obj.calendar__is_defined( resource_id )) ){ obj.calendar__init( resource_id ); } p_calendars[ 'calendar_' + resource_id ][ prop_name ] = prop_value; return p_calendars[ 'calendar_' + resource_id ]; }; /** * Get calendar property value :: mixed | null * * @param {string|int} resource_id '1' * @param {string} prop_name 'selection_mode' * @returns {*|null} mixed | null */ obj.calendar__get_param_value = function( resource_id, prop_name ){ if ( ( obj.calendar__is_defined( resource_id ) ) && ( 'undefined' !== typeof ( p_calendars[ 'calendar_' + resource_id ][ prop_name ] ) ) ){ //FixIn: 9.9.0.29 if ( obj.calendar__is_prop_int( prop_name ) ){ p_calendars[ 'calendar_' + resource_id ][ prop_name ] = parseInt( p_calendars[ 'calendar_' + resource_id ][ prop_name ] ); } return p_calendars[ 'calendar_' + resource_id ][ prop_name ]; } return null; // If some property not defined, then null; }; // ----------------------------------------------------------------------------------------------------------------- // Bookings ---------------------------------------------------------------------------------------------------- var p_bookings = obj.bookings_obj = obj.bookings_obj || { // calendar_1: Object { // id: 1 // , dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … // } }; /** * Check if bookings for specific booking resource defined :: true | false * * @param {string|int} resource_id * @returns {boolean} */ obj.bookings_in_calendar__is_defined = function ( resource_id ) { return ('undefined' !== typeof( p_bookings[ 'calendar_' + resource_id ] ) ); }; /** * Get bookings calendar object :: { id: 1 , dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * * @param {string|int} resource_id '2' * @returns {object|boolean} { id: 2 , dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } */ obj.bookings_in_calendar__get = function( resource_id ){ if ( obj.bookings_in_calendar__is_defined( resource_id ) ){ return p_bookings[ 'calendar_' + resource_id ]; } else { return false; } }; /** * Set bookings calendar object :: { dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * * if calendar object not defined, then it's will be defined and ID set * if calendar exist, then system set as new or overwrite only properties from calendar_obj parameter, but other properties will be existed and not overwrite, like 'id' * * @param {string|int} resource_id '2' * @param {object} calendar_obj { dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } } * @returns {*} * * Examples: * * Common usage in PHP: * echo " _wpbc.bookings_in_calendar__set( " .intval( $resource_id ) . ", { 'dates': " . wp_json_encode( $availability_per_days_arr ) . " } );"; */ obj.bookings_in_calendar__set = function( resource_id, calendar_obj ){ if ( ! obj.bookings_in_calendar__is_defined( resource_id ) ){ p_bookings[ 'calendar_' + resource_id ] = {}; p_bookings[ 'calendar_' + resource_id ][ 'id' ] = resource_id; } for ( var prop_name in calendar_obj ){ p_bookings[ 'calendar_' + resource_id ][ prop_name ] = calendar_obj[ prop_name ]; } return p_bookings[ 'calendar_' + resource_id ]; }; // Dates /** * Get bookings data for ALL Dates in calendar :: false | { "2023-07-22": {…}, "2023-07-23": {…}, … } * * @param {string|int} resource_id '1' * @returns {object|boolean} false | Object { "2023-07-24": Object { ['summary']['status_for_day']: "available", day_availability: 1, max_capacity: 1, … } "2023-07-26": Object { ['summary']['status_for_day']: "full_day_booking", ['summary']['status_for_bookings']: "pending", day_availability: 0, … } "2023-07-29": Object { ['summary']['status_for_day']: "resource_availability", day_availability: 0, max_capacity: 1, … } "2023-07-30": {…}, "2023-07-31": {…}, … } */ obj.bookings_in_calendar__get_dates = function( resource_id){ if ( ( obj.bookings_in_calendar__is_defined( resource_id ) ) && ( 'undefined' !== typeof ( p_bookings[ 'calendar_' + resource_id ][ 'dates' ] ) ) ){ return p_bookings[ 'calendar_' + resource_id ][ 'dates' ]; } return false; // If some property not defined, then false; }; /** * Set bookings dates in calendar object :: { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * * if calendar object not defined, then it's will be defined and 'id', 'dates' set * if calendar exist, then system add a new or overwrite only dates from dates_obj parameter, * but other dates not from parameter dates_obj will be existed and not overwrite. * * @param {string|int} resource_id '2' * @param {object} dates_obj { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * @param {boolean} is_complete_overwrite if false, then only overwrite or add dates from dates_obj * @returns {*} * * Examples: * _wpbc.bookings_in_calendar__set_dates( resource_id, { "2023-07-21": {…}, "2023-07-22": {…}, … } ); <- overwrite ALL dates * _wpbc.bookings_in_calendar__set_dates( resource_id, { "2023-07-22": {…} }, false ); <- add or overwrite only "2023-07-22": {} * * Common usage in PHP: * echo " _wpbc.bookings_in_calendar__set_dates( " . intval( $resource_id ) . ", " . wp_json_encode( $availability_per_days_arr ) . " ); "; */ obj.bookings_in_calendar__set_dates = function( resource_id, dates_obj , is_complete_overwrite = true ){ if ( !obj.bookings_in_calendar__is_defined( resource_id ) ){ obj.bookings_in_calendar__set( resource_id, { 'dates': {} } ); } if ( 'undefined' === typeof (p_bookings[ 'calendar_' + resource_id ][ 'dates' ]) ){ p_bookings[ 'calendar_' + resource_id ][ 'dates' ] = {} } if (is_complete_overwrite){ // Complete overwrite all booking dates p_bookings[ 'calendar_' + resource_id ][ 'dates' ] = dates_obj; } else { // Add only new or overwrite exist booking dates from parameter. Booking dates not from parameter will be without chnanges for ( var prop_name in dates_obj ){ p_bookings[ 'calendar_' + resource_id ]['dates'][ prop_name ] = dates_obj[ prop_name ]; } } return p_bookings[ 'calendar_' + resource_id ]; }; /** * Get bookings data for specific date in calendar :: false | { day_availability: 1, ... } * * @param {string|int} resource_id '1' * @param {string} sql_class_day '2023-07-21' * @returns {object|boolean} false | { day_availability: 4 max_capacity: 4 // >= Business Large 2: Object { is_day_unavailable: false, _day_status: "available" } 10: Object { is_day_unavailable: false, _day_status: "available" } // >= Business Large ... 11: Object { is_day_unavailable: false, _day_status: "available" } 12: Object { is_day_unavailable: false, _day_status: "available" } } */ obj.bookings_in_calendar__get_for_date = function( resource_id, sql_class_day ){ if ( ( obj.bookings_in_calendar__is_defined( resource_id ) ) && ( 'undefined' !== typeof ( p_bookings[ 'calendar_' + resource_id ][ 'dates' ] ) ) && ( 'undefined' !== typeof ( p_bookings[ 'calendar_' + resource_id ][ 'dates' ][ sql_class_day ] ) ) ){ return p_bookings[ 'calendar_' + resource_id ][ 'dates' ][ sql_class_day ]; } return false; // If some property not defined, then false; }; // Any PARAMS in bookings /** * Set property to booking * @param resource_id "1" * @param prop_name name of property * @param prop_value value of property * @returns {*} booking object */ obj.booking__set_param_value = function ( resource_id, prop_name, prop_value ) { if ( ! obj.bookings_in_calendar__is_defined( resource_id ) ){ p_bookings[ 'calendar_' + resource_id ] = {}; p_bookings[ 'calendar_' + resource_id ][ 'id' ] = resource_id; } p_bookings[ 'calendar_' + resource_id ][ prop_name ] = prop_value; return p_bookings[ 'calendar_' + resource_id ]; }; /** * Get booking property value :: mixed | null * * @param {string|int} resource_id '1' * @param {string} prop_name 'selection_mode' * @returns {*|null} mixed | null */ obj.booking__get_param_value = function( resource_id, prop_name ){ if ( ( obj.bookings_in_calendar__is_defined( resource_id ) ) && ( 'undefined' !== typeof ( p_bookings[ 'calendar_' + resource_id ][ prop_name ] ) ) ){ return p_bookings[ 'calendar_' + resource_id ][ prop_name ]; } return null; // If some property not defined, then null; }; /** * Set bookings for all calendars * * @param {object} calendars_obj Object { calendar_1: { id: 1, dates: Object { "2023-07-22": {…}, "2023-07-23": {…}, "2023-07-24": {…}, … } } * calendar_3: {}, ... } */ obj.bookings_in_calendars__set_all = function ( calendars_obj ) { p_bookings = calendars_obj; }; /** * Get bookings in all calendars * * @returns {object|{}} */ obj.bookings_in_calendars__get_all = function () { return p_bookings; }; // ----------------------------------------------------------------------------------------------------------------- // Seasons ---------------------------------------------------------------------------------------------------- var p_seasons = obj.seasons_obj = obj.seasons_obj || { // calendar_1: Object { // id: 1 // , dates: Object { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … // } }; /** * Add season names for dates in calendar object :: { "2023-07-21": [ 'wpbc_season_september_2023', 'wpbc_season_september_2024' ], "2023-07-22": [...], ... } * * * @param {string|int} resource_id '2' * @param {object} dates_obj { "2023-07-21": {…}, "2023-07-22": {…}, "2023-07-23": {…}, … } * @param {boolean} is_complete_overwrite if false, then only add dates from dates_obj * @returns {*} * * Examples: * _wpbc.seasons__set( resource_id, { "2023-07-21": [ 'wpbc_season_september_2023', 'wpbc_season_september_2024' ], "2023-07-22": [...], ... } ); */ obj.seasons__set = function( resource_id, dates_obj , is_complete_overwrite = false ){ if ( 'undefined' === typeof (p_seasons[ 'calendar_' + resource_id ]) ){ p_seasons[ 'calendar_' + resource_id ] = {}; } if ( is_complete_overwrite ){ // Complete overwrite all season dates p_seasons[ 'calendar_' + resource_id ] = dates_obj; } else { // Add only new or overwrite exist booking dates from parameter. Booking dates not from parameter will be without chnanges for ( var prop_name in dates_obj ){ if ( 'undefined' === typeof (p_seasons[ 'calendar_' + resource_id ][ prop_name ]) ){ p_seasons[ 'calendar_' + resource_id ][ prop_name ] = []; } for ( var season_name_key in dates_obj[ prop_name ] ){ p_seasons[ 'calendar_' + resource_id ][ prop_name ].push( dates_obj[ prop_name ][ season_name_key ] ); } } } return p_seasons[ 'calendar_' + resource_id ]; }; /** * Get bookings data for specific date in calendar :: [] | [ 'wpbc_season_september_2023', 'wpbc_season_september_2024' ] * * @param {string|int} resource_id '1' * @param {string} sql_class_day '2023-07-21' * @returns {object|boolean} [] | [ 'wpbc_season_september_2023', 'wpbc_season_september_2024' ] */ obj.seasons__get_for_date = function( resource_id, sql_class_day ){ if ( ( 'undefined' !== typeof ( p_seasons[ 'calendar_' + resource_id ] ) ) && ( 'undefined' !== typeof ( p_seasons[ 'calendar_' + resource_id ][ sql_class_day ] ) ) ){ return p_seasons[ 'calendar_' + resource_id ][ sql_class_day ]; } return []; // If not defined, then []; }; // Other parameters ------------------------------------------------------------------------------------ var p_other = obj.other_obj = obj.other_obj || { }; obj.set_other_param = function ( param_key, param_val ) { p_other[ param_key ] = param_val; }; obj.get_other_param = function ( param_key ) { return p_other[ param_key ]; }; /** * Get all other params * * @returns {object|{}} */ obj.get_other_param__all = function () { return p_other; }; // Messages ------------------------------------------------------------------------------------ var p_messages = obj.messages_obj = obj.messages_obj || { }; obj.set_message = function ( param_key, param_val ) { p_messages[ param_key ] = param_val; }; obj.get_message = function ( param_key ) { return p_messages[ param_key ]; }; /** * Get all other params * * @returns {object|{}} */ obj.get_messages__all = function () { return p_messages; }; // ----------------------------------------------------------------------------------------------------------------- return obj; }( _wpbc || {}, jQuery ));
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings