"use strict";/** * ===================================================================================================================== * 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 or # to stay in the same tab. */(function(){'use strict';function is_playground_origin(){return location.origin==='https://playground.wordpress.net';}function is_pseudo_link(a){if(!a||!a.getAttribute)return true;var href=(a.getAttribute('href')||'').trim().toLowerCase();return!href||href==='#'||href.indexOf('#')===0||href.indexOf('javascript:')===0||href.indexOf('mailto:')===0||href.indexOf('tel:')===0;}function fix_target(a){if(!a)return;if(is_pseudo_link(a)||a.hasAttribute('data-wp-no-blank')){a.target='_self';}}function init_fix(){// Optional: clean up current DOM (harmless—affects only pseudo/datamarked links). var nodes=document.querySelectorAll('a[href]');for(var i=0;i= 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);window.__WPBC_DEV=true;/** * Extend _wpbc with new methods * * @type {*|{}} * @private */_wpbc=function(obj,$){/** * Dev logger (no-op unless window.__WPBC_DEV = true) * * @type {*|{warn: (function(*, *, *): void), error: (function(*, *, *): void), once: obj.dev.once, try: ((function(*, *, *): (*|undefined))|*)}} */obj.dev=obj.dev||(()=>{const seen=new Set();const enabled=()=>!!window.__WPBC_DEV;function out(level,code,msg,extra){if(!enabled())return;try{(console[level]||console.warn)(`[WPBC][${code}] ${msg}`,extra??'');}catch{}}return{log:(code,msg,extra)=>out('log',code,msg,extra),debug:(code,msg,extra)=>out('debug',code,msg,extra),warn:(code,msg,extra)=>out('warn',code,msg,extra),error:(code,errOrMsg,extra)=>out('error',code,errOrMsg instanceof Error?errOrMsg.message:String(errOrMsg),errOrMsg instanceof Error?errOrMsg:extra),once:(code,msg,extra)=>{if(!enabled())return;const key=`${code}|${msg}`;if(seen.has(key))return;seen.add(key);out('error',code,msg,extra);},try:(code,fn,extra)=>{try{return fn();}catch(e){out('error',code,e,extra);}}};})();// Optional: global traps in dev. if(window.__WPBC_DEV){window.addEventListener('error',e=>{try{_wpbc?.dev?.error('GLOBAL-ERROR',e?.error||e?.message,e);}catch(_){}});window.addEventListener('unhandledrejection',e=>{try{_wpbc?.dev?.error('GLOBAL-REJECTION',e?.reason);}catch(_){}});}return obj;}(_wpbc||{},jQuery);/** * 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 Add booking page. ||location.href.indexOf('allow_past')!=-1// FixIn: 10.7.1.2. )){// local__min_date = null; // FixIn: 10.14.1.4. var wpbc_min_date_arr=wpbc_is_allow_past_context&&wpbc_allow_past_date_arr&&5<=wpbc_allow_past_date_arr.length?wpbc_allow_past_date_arr:_wpbc.get_other_param('time_local_arr');local__min_date=new Date(wpbc_min_date_arr[0],parseInt(wpbc_min_date_arr[1])-1,wpbc_min_date_arr[2],wpbc_min_date_arr[3],wpbc_min_date_arr[4],0);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 : '»', 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]);}}/** * Get booking statuses as array from the structured summary field, with fallback to the legacy string field. * * @param date_bookings_obj * @returns {[]} */function wpbc_get_booking_statuses__as_arr(date_bookings_obj){if(!date_bookings_obj||'undefined'===typeof date_bookings_obj['summary']){return[];}if(Array.isArray(date_bookings_obj['summary']['status_for_bookings_arr'])){return date_bookings_obj['summary']['status_for_bookings_arr'].filter(function(booking_status){return''!==booking_status;});}if(!date_bookings_obj['summary']['status_for_bookings']){return[];}return date_bookings_obj['summary']['status_for_bookings'].toString().trim().split(/\s+/).filter(function(booking_status){return''!==booking_status;});}/** * Check exact booking status in statuses array. * * @param {[]} booking_statuses_arr * @param {string} booking_status * @returns {boolean} */function wpbc_booking_statuses__has(booking_statuses_arr,booking_status){return booking_statuses_arr.indexOf(booking_status)>-1;}/** * Check booking status part, e.g. "pending" in "approved_pending". * * @param {[]} booking_statuses_arr * @param {string} booking_status_part * @returns {boolean} */function wpbc_booking_statuses__has_part(booking_statuses_arr,booking_status_part){for(var i=0;i-1){return true;}}return false;}/** * 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 Selected dates in calendar var selected_dates_sql=wpbc_get__selected_dates_sql__as_arr(resource_id);// 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' // Define Selected Check In/Out dates in TD ----------------------------------------------------------------------- if(selected_dates_sql.length//&& ( selected_dates_sql[ 0 ] !== selected_dates_sql[ (selected_dates_sql.length - 1) ] ) ){if(sql_class_day===selected_dates_sql[0]){css_classes__for_date.push('selected_check_in');css_classes__for_date.push('selected_check_in_out');}if(selected_dates_sql.length>1&&sql_class_day===selected_dates_sql[selected_dates_sql.length-1]){css_classes__for_date.push('selected_check_out');css_classes__for_date.push('selected_check_in_out');}}var is_day_selectable=false;// If something not defined, then this date closed --------------------------------------------------------------- // FixIn: 10.12.4.6. if(false===date_bookings_obj||'undefined'===typeof date_bookings_obj[resource_id]){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. // ----------------------------------------------------------------------------------------------------------------- var booking_statuses_arr=wpbc_get_booking_statuses__as_arr(date_bookings_obj);// ----------------------------------------------------------------------------------------------------------------- // 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 date_bookings_obj['summary']['status_for_bookings_arr']=[];booking_statuses_arr=[];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 date_bookings_obj['summary']['status_for_bookings_arr']=[];booking_statuses_arr=[];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 date_bookings_obj['summary']['status_for_bookings_arr']=[];booking_statuses_arr=[];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 date_bookings_obj['summary']['status_for_bookings_arr']=[];booking_statuses_arr=[];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 date_bookings_obj['summary']['status_for_bookings_arr']=[];booking_statuses_arr=[];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(wpbc_booking_statuses__has(booking_statuses_arr,'approved_pending')){css_classes__for_date.push('check_out_time_date_approved','check_in_time_date2approve');}if(wpbc_booking_statuses__has(booking_statuses_arr,'pending_approved')){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(wpbc_booking_statuses__has_part(booking_statuses_arr,'pending')){css_classes__for_date.push('check_in_time_date2approve');}else if(wpbc_booking_statuses__has_part(booking_statuses_arr,'approved')){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(wpbc_booking_statuses__has_part(booking_statuses_arr,'pending')){css_classes__for_date.push('check_out_time_date2approve');}else if(wpbc_booking_statuses__has_part(booking_statuses_arr,'approved')){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. if(wpbc_booking_statuses__has(booking_statuses_arr,'pending')){css_classes__for_date.push('date2approve');is_day_selectable=is_day_selectable?true:is_set_pending_days_selectable;}if(wpbc_booking_statuses__has(booking_statuses_arr,'approved')){css_classes__for_date.push('date_approved');}if(wpbc_booking_statuses__has(booking_statuses_arr,'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;}if(wpbc_booking_statuses__has(booking_statuses_arr,'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;}if(wpbc_booking_statuses__has(booking_statuses_arr,'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;}if(wpbc_booking_statuses__has(booking_statuses_arr,'approved_approved')){css_classes__for_date.push('check_out_time_date_approved','check_in_time_date_approved');}}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){wpbc_calendars__clear_days_highlighting('undefined'!==typeof calendar_params_arr['resource_id']?calendar_params_arr['resource_id']:'1');// FixIn: 10.5.2.4. 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;var is_add_booking_modal_calendar=jQuery('#calendar_booking'+resource_id).closest('#wpbc_modal__add_booking__section').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')>0&&location.href.indexOf('tab=add-booking')>0||is_add_booking_modal_calendar||location.href.indexOf('page=wpbc-setup')>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]);}// Mark middle selected dates with 0.5 opacity // FixIn: 10.3.0.9. jQuery(document).ready(function(){jQuery(".booking_form_div").on('date_selected',function(event,resource_id,date){if('fixed'===_wpbc.calendar__get_param_value(resource_id,'days_select_mode')||'dynamic'===_wpbc.calendar__get_param_value(resource_id,'days_select_mode')){var closed_timer=setTimeout(function(){var middle_days_opacity=_wpbc.get_other_param('calendars__days_selection__middle_days_opacity');jQuery('#calendar_booking'+resource_id+' .datepick-current-day').not(".selected_check_in_out").css('opacity',middle_days_opacity);},10);}});});/** * -- 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;var today_time__real=new Date(_wpbc.get_other_param('time_local_arr')[0],parseInt(_wpbc.get_other_param('time_local_arr')[1])-1,_wpbc.get_other_param('time_local_arr')[2],_wpbc.get_other_param('time_local_arr')[3],_wpbc.get_other_param('time_local_arr')[4],0);var today_time__shift=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],_wpbc.get_other_param('today_arr')[3],_wpbc.get_other_param('today_arr')[4],0);var allow_past_context=_wpbc.get_other_param('this_page_allow_past');var edit_booking_hash_context=_wpbc.get_other_param('this_page_booking_hash');var is_allow_past_context='1'===String(allow_past_context)||1===allow_past_context||true===allow_past_context||''!==String(edit_booking_hash_context||'')||location.href.indexOf('booking_hash')>-1||location.href.indexOf('allow_past')>-1;// 4. Loop all time Fields options // FixIn: 10.3.0.2. for(let field_key=0;field_key1){is_time_in_past=wpbc_check_is_time_in_past(today_time__shift,selected_dates_arr[selected_dates_arr.length-1],time_fields_obj);}if(is_time_in_past){// This time for selected date already in the past. time_fields_obj_arr[field_key].disabled=1;break;// exist from Dates LOOP. }// 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;}}var how_many_resources_intersected=0;// Loop all resources ID // for ( var res_key in child_resources_arr ){ // FixIn: 10.3.0.2. if(null===child_resources_arr){child_resources_arr=[];}for(let res_key=0;res_key1){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. }/** * Check if specific time(-slot) already in the past for selected date * * @param js_current_time_to_check - JS Date * @param sql_date - '2025-01-26' * @param time_fields_obj - Object * @returns {boolean} */function wpbc_check_is_time_in_past(js_current_time_to_check,sql_date,time_fields_obj){// FixIn: 10.9.6.4 var sql_date_arr=sql_date.split('-');var sql_date__midnight=new Date(parseInt(sql_date_arr[0]),parseInt(sql_date_arr[1])-1,parseInt(sql_date_arr[2]),0,0,0);var sql_date__midnight_miliseconds=sql_date__midnight.getTime();var is_intersect=false;if(time_fields_obj.times_as_seconds.length>1){if(js_current_time_to_check.getTime()>sql_date__midnight_miliseconds+(parseInt(time_fields_obj.times_as_seconds[0])+20)*1000){is_intersect=true;}if(js_current_time_to_check.getTime()>sql_date__midnight_miliseconds+(parseInt(time_fields_obj.times_as_seconds[1])-20)*1000){is_intersect=true;}}else{var is_check_in=-1!==time_fields_obj.name.indexOf('start');var times_as_seconds_check=is_check_in?parseInt(time_fields_obj.times_as_seconds)+20:parseInt(time_fields_obj.times_as_seconds)-20;times_as_seconds_check=sql_date__midnight_miliseconds+times_as_seconds_check*1000;if(js_current_time_to_check.getTime()>times_as_seconds_check){is_intersect=true;}}return is_intersect;}/** * 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;jparseInt(time_interval_B[j][0])&&parseInt(time_A) 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;i1){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;ctf0){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 {int|string} resource_id * @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){try{var inst=jQuery.datepick._getInst(jQuery('#calendar_booking'+resource_id).get(0));return inst?inst:null;}catch(e){return null;}}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. var booking_statuses_arr=wpbc_get_booking_statuses__as_arr(date_bookings_obj);if(wpbc_booking_statuses__has(booking_statuses_arr,'pending')||wpbc_booking_statuses__has(booking_statuses_arr,'pending_pending')||wpbc_booking_statuses__has(booking_statuses_arr,'pending_approved')||wpbc_booking_statuses__has(booking_statuses_arr,'approved_pending')){is_day_selectable=is_day_selectable?true:is_set_pending_days_selectable;}}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
');}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 (safe). * * In Elementor preview the DOM can be re-rendered, so the calendar element may exist * while the Datepick instance is missing. In that case try to (re)initialize. * * @param {int|string} resource_id * @return {boolean} true if updated, false if not possible */function wpbc_calendar__update_look(resource_id){var inst=wpbc_calendar__get_inst(resource_id);// If instance missing, try to re-init calendar once. if(null===inst){var jq_cal=jQuery('#calendar_booking'+resource_id);if(jq_cal.length&&'function'===typeof wpbc_calendar_show){// Elementor sometimes leaves stale class without real instance. if(jq_cal.hasClass('hasDatepick')){jq_cal.removeClass('hasDatepick');}// Try to init datepick markup now. wpbc_calendar_show(resource_id);// Try again. inst=wpbc_calendar__get_inst(resource_id);}}// Still no instance -> do not crash the whole ajax flow. if(null===inst){return false;}jQuery.datepick._updateDatepick(inst);return true;}/** * 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 [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 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
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'
'+'
'+popover_content+'
'+'
';},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 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);// Is ome type of error, then select multiple days selection mode. if(''===_wpbc.calendar__get_param_value(resource_id,'days_select_mode')){_wpbc.calendar__set_param_value(resource_id,'days_select_mode','multiple');}// --------------------------------------------------------------------------------------------------------- // == 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;jdate&&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>> 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){if(true===_wpbc.get_other_param('is_allow_several_months_on_mobile')){return false;}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);});// --------------------------------------------------------------------------------------------------------------------- /* == Check: calendar_dates_start: "2026-01-01", calendar_dates_end: "2026-12-31" == // FixIn: 10.13.1.4. // --------------------------------------------------------------------------------------------------------------------- *//** * Get Start JS Date of starting dates in calendar, from the _wpbc object. * * @param integer resource_id - resource ID, e.g.: 1. */function wpbc_calendar__get_dates_start(resource_id){return wpbc_calendar__get_date_parameter(resource_id,'calendar_dates_start');}/** * Get End JS Date of ending dates in calendar, from the _wpbc object. * * @param integer resource_id - resource ID, e.g.: 1. */function wpbc_calendar__get_dates_end(resource_id){return wpbc_calendar__get_date_parameter(resource_id,'calendar_dates_end');}/** * Get validates date parameter. * * @param resource_id - 1 * @param parameter_str - 'calendar_dates_start' | 'calendar_dates_end' | ... */function wpbc_calendar__get_date_parameter(resource_id,parameter_str){var date_expected_ymd=_wpbc.calendar__get_param_value(resource_id,parameter_str);if(!date_expected_ymd){return false;// '' | 0 | null | undefined -> false. }if(-1!==date_expected_ymd.indexOf('-')){var date_expected_ymd_arr=date_expected_ymd.split('-');// '2025-07-26' -> ['2025', '07', '26'] if(date_expected_ymd_arr.length>0){var year=date_expected_ymd_arr.length>0?parseInt(date_expected_ymd_arr[0]):new Date().getFullYear();// Year. var month=date_expected_ymd_arr.length>1?parseInt(date_expected_ymd_arr[1])-1:0;// (month - 1) or 0 - Jan. var day=date_expected_ymd_arr.length>2?parseInt(date_expected_ymd_arr[2]):1;// date or Otherwise 1st of month var date_js=new Date(year,month,day,0,0,0,0);return date_js;}}return false;// Fallback, if we not parsed this parameter 'calendar_dates_start' = '2025-07-26', for example because of 'calendar_dates_start' = 'sfsdf'. }/** * ==================================================================================================================== * 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);}/** * ==================================================================================================================== * 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']);// Trigger event for calendar before loading Booking data, but after showing Calendar. if(jQuery('#calendar_booking'+params['resource_id']).length>0){var target_elm=jQuery('body').trigger("wpbc_calendar_ajx__before_loaded_data",[params['resource_id']]);//jQuery( 'body' ).on( 'wpbc_calendar_ajx__before_loaded_data', function( event, 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']);// ----------------------------------------------------------------------------------------------------------------- // == Get start / end dates from the Booking Calendar shortcode. == // Example: [booking calendar_dates_start='2026-01-01' calendar_dates_end='2026-12-31' resource_id=1] // FixIn: 10.13.1.4. // ----------------------------------------------------------------------------------------------------------------- if(false!==wpbc_calendar__get_dates_start(params['resource_id'])){if(!params['dates_to_check']){params['dates_to_check']=[];}var dates_start=wpbc_calendar__get_dates_start(params['resource_id']);// E.g. - local__min_date = new Date( 2025, 0, 1 ); if(false!==dates_start){params['dates_to_check'][0]=wpbc__get__sql_class_date(dates_start);}}if(false!==wpbc_calendar__get_dates_end(params['resource_id'])){if(!params['dates_to_check']){params['dates_to_check']=[];}var dates_end=wpbc_calendar__get_dates_end(params['resource_id']);// E.g. - local__min_date = new Date( 2025, 0, 1 ); if(false!==dates_end){params['dates_to_check'][1]=wpbc__get__sql_class_date(dates_end);if(!params['dates_to_check'][0]){params['dates_to_check'][0]=wpbc__get__sql_class_date(new Date());}}}// ----------------------------------------------------------------------------------------------------------------- // 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());if('function'===typeof wpbc_hook__init_timeselector){wpbc_hook__init_timeselector();}// 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.
Please check your error.log 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('function'===typeof wpbc_hook__init_timeselector){wpbc_hook__init_timeselector();}if('undefined'!==typeof response_data['ajx_data']['ajx_after_action_message']&&''!=response_data['ajx_data']['ajx_after_action_message'].replace(/\n/g,"
")){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,"
"),{'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});}if('function'===typeof wpbc_update_capacity_hint){wpbc_update_capacity_hint(response_data['resource_id']);}// Trigger event that calendar has been // FixIn: 10.0.0.44. // FixIn: 10.14.17.2. if(jQuery('#calendar_booking'+response_data['resource_id']).length>0||jQuery('#date_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=''+'Error!'+' '+errorThrown;if(jqXHR.status){error_message+=' ('+jqXHR.status+')';if(403==jqXHR.status){error_message+='
Probably nonce for this page has been expired. Please reload the page.';error_message+='
Otherwise, please check this troubleshooting instruction.
';}}var message_show_delay=3000;if(jqXHR.responseText){error_message+=' '+jqXHR.responseText;message_show_delay=10;}error_message=error_message.replace(/\n/g,"
");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,' '));}/** * ===================================================================================================================== * 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, "
" ), * { '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=''+message;}if(params['type']=='warning'){params['css_class']+=' wpbc_fe_message_warning';message=''+message;}if(params['type']=='info'){params['css_class']+=' wpbc_fe_message_info';}if(params['type']=='success'){params['css_class']+=' wpbc_fe_message_success';message=''+message;}var scroll_to_element='';message='
'+message+'
';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('
'+message+'
');}}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('
'+message+'
');}}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);}}// 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'
'+''+popover_content+'
';},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();}});}/** * WPBC calendar loader bootstrap. * ============================================================================================== * - Finds every .calendar_loader_frame[data-wpbc-rid] on the page (now or later). * - For each loader element, waits a "grace" period (data-wpbc-grace, default 8000 ms): * - If the real calendar appears: do nothing (loader naturally replaced). * - If not: show a helpful message (missing jQuery/_wpbc/datepick) or a duplicate notice. * - Works with multiple calendars and even duplicate RIDs on the same page. * - No inline JS needed in the shortcode/template output. * * File: ../includes/__js/client/cal/wpbc_cal_loader.js * * @since 10.14.5 * @modified 2025-09-07 12:21 * @version 1.0.0 * *//** * WPBC calendar loader bootstrap. * - Auto-detects .calendar_loader_frame[data-wpbc-rid] blocks. * - Waits a "grace" period per element before showing a helpful message * if the real calendar hasn't replaced the loader. * - Multiple calendars and duplicate RIDs are handled. */(function(w,d){'use strict';/* --------------------------------------------------------------------------- * Small utilities (snake_case) * ------------------------------------------------------------------------ *//** Track processed loader elements; fallback to data flag if WeakSet missing. */var processed_set=typeof WeakSet==='function'?new WeakSet():null;/** Return first match inside optional root. */function query_one(selector,root){return(root||d).querySelector(selector);}/** Return NodeList of matches inside optional root. */function query_all(selector,root){return(root||d).querySelectorAll(selector);}/** Run a callback when DOM is ready. */function on_ready(fn){if(d.readyState==='loading'){d.addEventListener('DOMContentLoaded',fn);}else{fn();}}/** Clear interval safely. */function safe_clear(interval_id){try{w.clearInterval(interval_id);}catch(e){}}/** Mark element processed (WeakSet or data attribute). */function mark_processed(el){if(processed_set){processed_set.add(el);}else{try{el.dataset.wpbcProcessed='1';}catch(e){}}}/** Check if element was processed. */function is_processed(el){return processed_set?processed_set.has(el):el&&el.dataset&&el.dataset.wpbcProcessed==='1';}/* --------------------------------------------------------------------------- * Messages (fixed English strings; no i18n) * ------------------------------------------------------------------------ *//** * Build fixed English messages for a resource. * @param {string|number} rid * @return {{duplicate:string,support:string,lib_jq:string,lib_dp:string,lib_wpbc:string}} */function get_messages(rid){var rid_int=parseInt(rid,10);return{duplicate:'You have added the same calendar (ID = '+rid_int+') more than once on this page. '+'Please keep only one calendar with the same ID on a page to avoid conflicts.',init_failed:'The calendar could not be initialized on this page.'+'\n'+'Please check your browser console for JavaScript errors and conflicts with other scripts/plugins.',support:'',/* 'Contact support@wpbookingcalendar.com if you have any questions.', */lib_jq:'It appears that the "jQuery" library is not loading correctly.'+'\n'+'For more information, please refer to this page: https://wpbookingcalendar.com/faq/',lib_dp:'It appears that the "jQuery.datepick" library is not loading correctly.'+'\n'+'For more information, please refer to this page: https://wpbookingcalendar.com/faq/',lib_wpbc:'It appears that the "_wpbc" library is not loading correctly.'+'\n'+'Please enable the loading of JS/CSS files for this page on the "WP Booking Calendar" - "Settings General" - "Advanced" page'+'\n'+'For more information, please refer to this page: https://wpbookingcalendar.com/faq/'};}/** * Wrap plain text (with newlines) in a small HTML container. * @param {string} msg * @return {string} */function wrap_html(msg){return'
'+String(msg||'').replace(/\n/g,'
')+'
';}/** Library presence checks (fast & cheap). */function has_jq(){return!!(w.jQuery&&jQuery.fn&&typeof jQuery.fn.on==='function');}function has_dp(){return!!(w.jQuery&&jQuery.datepick);}function has_wpbc(){return!!(w._wpbc&&typeof w._wpbc.set_other_param==='function');}function normalize_rid(rid){var n=parseInt(rid,10);return n>0?String(n):'';}function get_rid_counts(rid){var r=normalize_rid(rid);return{rid:r,loaders:r?query_all('.calendar_loader_frame[data-wpbc-rid="'+r+'"]').length:0,containers:r?query_all('#calendar_booking'+r).length:0};}function is_duplicate_rid(rid){var c=get_rid_counts(rid);return c.loaders>1||c.containers>1;}/** * Determine if the loader has been replaced by the real calendar. * * @param {Element} el Loader element * @param {string} rid Resource ID * @param {Element|null} container Optional #calendar_booking{rid} element * @return {boolean} */function is_replaced(el,rid,container){var loader_still_in_dom=d.body.contains(el);var calendar_exists=!!query_one('.wpbc_calendar_id_'+rid,container||d);return!loader_still_in_dom||calendar_exists;}/** * Start watcher for a single loader element. * - Polls and observes the calendar container. * - After grace, injects a suitable message if not replaced. * * @param {Element} el */function start_for(el){if(!el||is_processed(el)){return;}mark_processed(el);var rid=el.dataset.wpbcRid;if(!rid){return;}var grace_ms=parseInt(el.dataset.wpbcGrace||'8000',10);if(!(grace_ms>0)){grace_ms=8000;}var container_id='calendar_booking'+rid;var container=d.getElementById(container_id);var text_el=query_one('.calendar_loader_text',el);function replaced_now(){return is_replaced(el,rid,container);}// Already replaced -> nothing to do. if(replaced_now()){return;}// 1) Cheap polling. var poll_id=w.setInterval(function(){if(replaced_now()){safe_clear(poll_id);if(observer){try{observer.disconnect();}catch(e){}}}},250);// 2) MutationObserver for faster reaction. var observer=null;if(container&&'MutationObserver'in w){try{observer=new MutationObserver(function(){if(replaced_now()){safe_clear(poll_id);try{observer.disconnect();}catch(e){}}});observer.observe(container,{childList:true,subtree:true});}catch(e){}}// 3) Final decision after grace period. w.setTimeout(function finalize_after_grace(){if(replaced_now()){safe_clear(poll_id);if(observer){try{observer.disconnect();}catch(e){}}return;}var M=get_messages(rid);var msg;if(!has_jq()){msg=M.lib_jq;}else if(!has_wpbc()){msg=M.lib_wpbc;}else if(!has_dp()){msg=M.lib_dp;}else{// Libraries are present, but loader wasn't replaced -> decide what is most likely. if(is_duplicate_rid(rid)){msg=M.duplicate+'\n\n'+M.support;}else{msg=M.init_failed+'\n\n'+M.support;}}try{if(text_el){text_el.innerHTML=wrap_html(msg);}}catch(e){}safe_clear(poll_id);if(observer){try{observer.disconnect();}catch(e){}}},grace_ms);}/** * Initialize watchers for loader elements already in the DOM. */function bootstrap_existing(){query_all('.calendar_loader_frame[data-wpbc-rid]').forEach(start_for);}/** * Observe the document for any new loader elements inserted later (AJAX, block render). */function observe_new_loaders(){if(!('MutationObserver'in w)){return;}try{var doc_observer=new MutationObserver(function(mutations){for(var i=0;i0&&'pause_submit'===jQuery(target_elm).find('input[name="booking_form_show_summary"]').val()){return false;}// FixIn: 8.4.0.2. var is_error=wpbc_check_errors_in_booking_form(resource_id);if(is_error){return false;}// ------------------------------------------------------------------------- // Show message if no selected days in Calendar(s). // ------------------------------------------------------------------------- var date_input=document.getElementById('date_booking'+resource_id);var date_value=date_input?date_input.value:'';if(''===date_value){var arr_of_selected_additional_calendars=wpbc_get_arr_of_selected_additional_calendars(resource_id);// FixIn: 8.5.2.26. if(!arr_of_selected_additional_calendars||arr_of_selected_additional_calendars.length===0){wpbc_front_end__show_message__error_under_element('#booking_form_div'+resource_id+' .bk_calendar_frame',_wpbc.get_message('message_check_no_selected_dates'),3000);return;}}// ------------------------------------------------------------------------- // FixIn: 6.1.1.3. Time selection availability checks. // ------------------------------------------------------------------------- if(typeof wpbc_is_this_time_selection_not_available==='function'){if(''===date_value){// Primary calendar not selected. var additional_calendars_el=document.getElementById('additional_calendars'+resource_id);if(additional_calendars_el!==null){// Checking additional calendars. var id_additional_str=additional_calendars_el.value;var id_additional_arr=id_additional_str.split(',');var is_times_dates_ok=false;for(var ia=0;ia0){if(jQuery('[name="'+primary_email_name+resource_id+'"]').val()!==inp_value){wpbc_front_end__show_message__warning(element,_wpbc.get_message('message_check_same_email'));// FixIn: 8.5.1.3. return;}}}// Skip one loop for the email verification field. continue;// FixIn: 8.1.2.15. }}// ------------------------------------------------------------- // Get Form Data (legacy format). // ------------------------------------------------------------- if(element.name!=='captcha_input'+resource_id){if(formdata!==''){formdata+='~';}el_type=element.type;if(element.className.indexOf('wpdev-validates-as-email')!==-1){el_type='email';}if(element.className.indexOf('wpdev-validates-as-coupon')!==-1){el_type='coupon';}inp_value=wpbc_escape_serialized_value(inp_value);if(el_type==='select-one'){el_type='selectbox-one';}if(el_type==='select-multiple'){el_type='selectbox-multiple';}formdata+=el_type+'^'+element.name+'^'+inp_value;// Add title/label value (legacy). var clean_field_name=String(element.name);// BUGFIX: replaceAll(RegExp) is not supported in older browsers. // Keep legacy intent: remove [] suffix occurrences. clean_field_name=clean_field_name.replace(/\[\]/gi,'');var resource_id_str=String(resource_id);// Legacy assumed suffix ends with resource_id, make it safe. if(clean_field_name.length>=resource_id_str.length&&clean_field_name.substr(clean_field_name.length-resource_id_str.length)===resource_id_str){clean_field_name=clean_field_name.substr(0,clean_field_name.length-resource_id_str.length);}formdata+='~'+el_type+'^'+clean_field_name+'_val'+resource_id+'^'+inp_title_value;}}}// TODO: here was function for 'Check if visitor finish dates selection. // Captcha verify. var captcha=document.getElementById('wpdev_captcha_challenge_'+resource_id);if(captcha!==null){wpbc_form_submit_send(resource_id,formdata,captcha.value,document.getElementById('captcha_input'+resource_id).value,wpdev_active_locale);}else{wpbc_form_submit_send(resource_id,formdata,'','',wpdev_active_locale);}return;}/** * Gathering params for sending Ajax request and then send it (legacy: form_submit_send). * * @param {number|string} resource_id * @param {string} formdata * @param {string} captcha_chalange * @param {string} user_captcha * @param {string} wpdev_active_locale * * @return {undefined} Legacy behavior. */function wpbc_form_submit_send(resource_id,formdata,captcha_chalange,user_captcha,wpdev_active_locale){resource_id=parseInt(resource_id,10);var my_booking_form='';var booking_form_type_el=document.getElementById('booking_form_type'+resource_id);if(booking_form_type_el!==null){my_booking_form=booking_form_type_el.value;}var my_booking_hash='';if(_wpbc.get_other_param('this_page_booking_hash')!==''){my_booking_hash=_wpbc.get_other_param('this_page_booking_hash');}var is_send_emeils=1;var $is_send_email_toggle=jQuery('#is_send_email_for_pending');var $modal_send_email_toggle=jQuery('#booking_form'+resource_id).closest('.wpbc_modal__add_booking__section').find('[data-wpbc-add-booking-send-emails]').first();if($modal_send_email_toggle.length){$is_send_email_toggle=$modal_send_email_toggle;}if($is_send_email_toggle.length){// FixIn: 8.7.9.5. is_send_emeils=$is_send_email_toggle.is(':checked');if(false===is_send_emeils){is_send_emeils=0;}else{is_send_emeils=1;}}var date_el=document.getElementById('date_booking'+resource_id);var date_value=date_el?date_el.value:'';if(''!==date_value){// FixIn: 6.1.1.3. wpbc_send_ajax_submit(resource_id,formdata,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form,wpdev_active_locale);}else{jQuery('#booking_form_div'+resource_id).hide();jQuery('#submiting'+resource_id).hide();}// ------------------------------------------------------------------------- // Additional calendars submit. // ------------------------------------------------------------------------- var additional_calendars_el=document.getElementById('additional_calendars'+resource_id);if(additional_calendars_el===null){return;}var id_additional_str=additional_calendars_el.value;var id_additional_arr=id_additional_str.split(',');// FixIn: 10.9.4.1. for(var ia=0;ia id_additional. function wpbc_rewrite_field_name_suffix(field_name,old_id,new_id){field_name=String(field_name);var old_id_str=String(old_id);var new_id_str=String(new_id);// Handle fields with []. if(field_name.length>=old_id_str.length+2&&field_name.substr(field_name.length-(old_id_str.length+2))===old_id_str+'[]'){return field_name.substr(0,field_name.length-(old_id_str.length+2))+new_id_str+'[]';}// Handle fields without []. if(field_name.length>=old_id_str.length&&field_name.substr(field_name.length-old_id_str.length)===old_id_str){return field_name.substr(0,field_name.length-old_id_str.length)+new_id_str;}// Fallback: return unchanged (safer than breaking name). return field_name;}for(ia=0;ia0){jQuery('#gateway_payment_forms'+resource_id).after('
');jQuery('#gateway_payment_forms'+resource_id).after('');}// FixIn: 8.5.2.17. wpbc_send_ajax_submit(id_additional,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form,wpdev_active_locale);}}/** * Send Ajax submit (legacy: send_ajax_submit). * * @param {number|string} resource_id * @param {string} formdata * @param {string} captcha_chalange * @param {string} user_captcha * @param {number} is_send_emeils * @param {string} my_booking_hash * @param {string} my_booking_form * @param {string} wpdev_active_locale * * @return {undefined} Legacy behavior. */function wpbc_send_ajax_submit(resource_id,formdata,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form,wpdev_active_locale){resource_id=parseInt(resource_id,10);// Disable Submit | Show spin loader. wpbc_booking_form__on_submit__ui_elements_disable(resource_id);// FixIn: 2026-02-05 - pass preview context to booking create Ajax. var form_status=wpbc__get_form_status_for_submit(resource_id);var preview_args=form_status==='preview'?wpbc__get_bfb_preview_args_from_location():null;var $add_booking_modal=jQuery('#booking_form'+resource_id).closest('#wpbc_modal__add_booking__section');var is_allow_past=0;var has_add_booking_modal_context=$add_booking_modal.length&&$add_booking_modal.is(':visible');if(has_add_booking_modal_context){is_allow_past=$add_booking_modal.find('[data-wpbc-add-booking-allow-past]').first().is(':checked')?1:0;if(!is_allow_past){is_allow_past='1'===String($add_booking_modal.attr('data-wpbc-add-booking-allow-past')||'0')?1:0;}}if(!has_add_booking_modal_context&&'undefined'!==typeof _wpbc){is_allow_past='1'===String(_wpbc.get_other_param('this_page_allow_past')||'0')?1:0;}var request_params={'resource_id':resource_id,'dates_ddmmyy_csv':document.getElementById('date_booking'+resource_id).value,'formdata':formdata,'booking_hash':my_booking_hash,'custom_form':my_booking_form,'aggregate_resource_id_arr':null!==_wpbc.booking__get_param_value(resource_id,'aggregate_resource_id_arr')?_wpbc.booking__get_param_value(resource_id,'aggregate_resource_id_arr').join(','):'','captcha_chalange':captcha_chalange,'captcha_user_input':user_captcha,'is_emails_send':is_send_emeils,'active_locale':wpdev_active_locale,'form_status':form_status,'allow_past':is_allow_past};var $time_override_panel=jQuery('#booking_form'+resource_id).find('[data-wpbc-add-booking-time-override-panel]').first();if(!$time_override_panel.length){$time_override_panel=jQuery('#wpbc_modal__add_booking__section:visible').find('[data-wpbc-add-booking-time-override-panel]').first();}if($time_override_panel.length&&$time_override_panel.find('[data-wpbc-add-booking-time-override-enabled]').first().is(':checked')){request_params['wpbc_time_override_enabled']=1;request_params['wpbc_time_override_source']=$time_override_panel.attr('data-wpbc-add-booking-time-override-source')||'';request_params['wpbc_time_override_start']=$time_override_panel.find('[data-wpbc-add-booking-time-override-field="start"]').first().val()||'';request_params['wpbc_time_override_end']=$time_override_panel.find('[data-wpbc-add-booking-time-override-field="end"]').first().val()||'';}var selected_dates_count=String(request_params['dates_ddmmyy_csv']||'').split(',').filter(function(date_text){return''!==String(date_text||'').replace(/^\s+|\s+$/g,'');}).length;var is_times_availability_override=1===parseInt(request_params['wpbc_time_override_enabled']||0,10)&&'times_availability'===String(request_params['wpbc_time_override_source']||'');if(has_add_booking_modal_context&&'1'===String($add_booking_modal.attr('data-wpbc-add-booking-force-recurrent-time')||'0')||is_times_availability_override&&selected_dates_count>1){request_params['is_use_booking_recurrent_time']=1;}// If preview, pass session identifiers so PHP can load transient snapshot. if(preview_args&&preview_args.token&&preview_args.form_id){request_params['wpbc_bfb_preview']=1;request_params['wpbc_bfb_preview_token']=preview_args.token;request_params['wpbc_bfb_preview_form_id']=preview_args.form_id;request_params['wpbc_bfb_preview_nonce']=preview_args.nonce;// note: URL param is `nonce`. }var is_exit=wpbc_ajx_booking__create(request_params);if(true===is_exit){return;}}// == Helper Functions ================================================================================================= /** * Parse query string into {key:value} (old-browser safe). * * @param {string} qs * @return {Object} */function wpbc__parse_query_string(qs){var out={};qs=qs||'';qs=qs.replace(/^\?/,'');if(!qs){return out;}var parts=qs.split('&');for(var i=0;i