PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 10.11.2 All 203 releases
← All changes | js/client.js +352 -637 10.1.311.8.3 View file →
@@ -1,627 +1,264 @@
1 -// == Submit Booking Data ==============================================================================================
2 -
3 -// Check fields at form and then send request
4 -function mybooking_submit( submit_form , bk_type, wpdev_active_locale){
5 -
6 - var target_elm = jQuery( ".booking_form_div" ).trigger( "booking_form_submit_click", [bk_type, submit_form, wpdev_active_locale] ); //FixIn: 8.8.3.13
7 - if (
8 - ( jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).length > 0 )
9 - && ( 'pause_submit' === jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).val() )
10 - )
11 - {
12 - return false;
13 - }
14 -
15 - //FixIn: 8.4.0.2
16 - var is_error = wpbc_check_errors_in_booking_form( bk_type );
17 - if ( is_error ) { return false; }
18 -
19 - // Show message if no selected days in Calendar(s)
20 - if (document.getElementById('date_booking' + bk_type).value == '') {
21 -
22 - var arr_of_selected_additional_calendars = wpbc_get_arr_of_selected_additional_calendars( bk_type ); //FixIn: 8.5.2.26
23 -
24 - if ( arr_of_selected_additional_calendars.length == 0 ) {
25 - wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', _wpbc.get_message( 'message_check_no_selected_dates' ), 3000 );
26 - return;
27 - }
28 - }
29 -
30 - var count = submit_form.elements.length;
31 - var formdata = '';
32 - var inp_value;
33 - var element;
34 - var el_type;
35 -
36 -
37 - //FixIn:6.1.1.3
38 - if( typeof( wpbc_is_this_time_selection_not_available ) == 'function' ) {
39 -
40 - if ( document.getElementById('date_booking' + bk_type).value == '' ) { // Primary calendar not selected.
41 -
42 - if ( document.getElementById('additional_calendars' + bk_type ) != null ) { // Checking additional calendars.
43 -
44 - var id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign
45 - var id_additional_arr = id_additional_str.split(',');
46 - var is_times_dates_ok = false;
47 - for ( var ia=0;ia<id_additional_arr.length;ia++ ) {
48 - if (
49 - ( document.getElementById('date_booking' + id_additional_arr[ia] ).value != '' )
50 - && ( ! wpbc_is_this_time_selection_not_available( id_additional_arr[ia], submit_form.elements ) )
51 - ){
52 - is_times_dates_ok = true;
53 - }
54 - }
55 - if ( ! is_times_dates_ok ) return;
56 - }
57 - } else { //Primary calendar selected.
58 - if ( wpbc_is_this_time_selection_not_available( bk_type, submit_form.elements ) )
59 - return;
60 - }
61 - }
62 -
63 -
64 -
65 - // Serialize form here
66 - for ( var i = 0; i < count; i++ ){ //FixIn: 9.1.5.1
67 - element = submit_form.elements[i];
68 -
69 - if ( jQuery( element ).closest( '.booking_form_garbage' ).length ) {
70 - continue; // Skip elements from garbage //FixIn: 7.1.2.14
71 - }
72 -
73 - if (
74 - ( element.type !== 'button' )
75 - && ( element.type !== 'hidden' )
76 - && ( element.name !== ( 'date_booking' + bk_type ) )
77 - // && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element
78 - ) { // Skip buttons and hidden element - type //FixIn: 7.2.1.12
79 -
80 -
81 - // Get Element Value
82 - if ( element.type == 'checkbox' ){
83 -
84 - if (element.value == '') {
85 - inp_value = element.checked;
86 - } else {
87 - if (element.checked) inp_value = element.value;
88 - else inp_value = '';
89 - }
90 -
91 - } else if ( element.type == 'radio' ) {
92 -
93 - if (element.checked) {
94 - inp_value = element.value;
95 - } else {
96 - // Check if this radio required, and if it does not check, then show warning, otherwise if it is not required or some other option checked skip this loop
97 - // We need to check it here, because radio have the several options with same name and type, and otherwise we will save several options with selected and empty values.
98 - if ( //FixIn: 7.0.1.62
99 - ( element.className.indexOf('wpdev-validates-as-required') !== -1 )
100 - && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element
101 - && ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) ) {
102 - wpbc_front_end__show_message__warning( element, _wpbc.get_message( 'message_check_required_for_radio_box' ) ); //FixIn: 8.5.1.3
103 - return;
104 - }
105 - continue;
106 - }
107 - } else {
108 - inp_value = element.value;
109 - }
110 -
111 - // Get value in selectbox of multiple selection
112 - if ( (element.type == 'selectbox-multiple') || (element.type == 'select-multiple') ){
113 - inp_value = jQuery('[name="'+element.name+'"]').val() ;
114 - if (( inp_value == null ) || (inp_value.toString() == '' ))
115 - inp_value='';
116 - }
117 -
118 - // Make validation only for visible elements
119 - if ( jQuery( element ).is( ':visible' ) ) { //FixIn: 7.2.1.12.2
120 -
121 -
122 - // Recheck for max num. available visitors selection
123 - if ( typeof (wpbc__is_less_than_required__of_max_available_slots__bl) == 'function' ){
124 - if ( wpbc__is_less_than_required__of_max_available_slots__bl( bk_type, element ) ){
125 - return;
126 - }
127 - }
128 -
129 -
130 - // Phone validation
131 - /*if ( element.name == ('phone'+bk_type) ) {
132 - // we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number - See more at: http://www.w3resource.com/javascript/form/phone-no-validation.php#sthash.U9FHwcdW.dpuf
133 - var reg = /^\d{10}$/;
134 - var message_verif_phone = "Please enter correctly phone number";
135 - if ( inp_value != '' )
136 - if(reg.test(inp_value) == false) {wpbc_front_end__show_message__warning( element , message_verif_phone );return;}
137 - }*/
138 -
139 - // Validation Check --- Requred fields
140 - if ( element.className.indexOf('wpdev-validates-as-required') !== -1 ){
141 - if ((element.type =='checkbox') && ( element.checked === false)) {
142 - if ( ! jQuery(':checkbox[name="'+element.name+'"]', submit_form).is(":checked") ) {
143 - wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required_for_check_box' ) ); //FixIn: 8.5.1.3
144 - return;
145 - }
146 - }
147 - if (element.type =='radio') {
148 - if ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) {
149 - wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required_for_radio_box' ) ); //FixIn: 8.5.1.3
150 - return;
151 - }
152 - }
153 -
154 - if ( (element.type != 'checkbox') && (element.type != 'radio') && ( '' === wpbc_trim( inp_value ) ) ){ //FixIn: 8.8.1.3 //FixIn:7.0.1.39 //FixIn: 8.7.11.12
155 - wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_required' ) ); //FixIn: 8.5.1.3
156 - return;
157 - }
158 - }
159 -
160 - // Validation Check --- Email correct filling field
161 - if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ){
162 - inp_value = inp_value.replace(/^\s+|\s+$/gm,''); // Trim white space //FixIn: 5.4.5
163 - var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/;
164 - if ( inp_value != '' )
165 - if(reg.test(inp_value) == false) {
166 - wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_email' ) ); //FixIn: 8.5.1.3
167 - return;
168 - }
169 - }
170 -
171 - // Validation Check --- Same Email Field
172 - if ( ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) && ( element.className.indexOf('same_as_') !== -1 ) ) {
173 -
174 - // Get the name of Primary Email field from the "same_as_NAME" class
175 - var primary_email_name = element.className.match(/same_as_([^\s])+/gi);
176 - if (primary_email_name != null) { // We found
177 - primary_email_name = primary_email_name[0].substr(8);
178 -
179 - // Recehck if such primary email field exist in the booking form
180 - if (jQuery('[name="' + primary_email_name + bk_type + '"]').length > 0) {
181 -
182 - // Recheck the values of the both emails, if they do not equla show warning
183 - if ( jQuery('[name="' + primary_email_name + bk_type + '"]').val() !== inp_value ) {
184 - wpbc_front_end__show_message__warning( element , _wpbc.get_message( 'message_check_same_email' ) ); //FixIn: 8.5.1.3
185 - return;
186 - }
187 - }
188 - }
189 - // Skip one loop for the email veryfication field
190 - continue; //FixIn: 8.1.2.15
191 - }
192 -
193 - }
194 -
195 - // Get Form Data
196 - if ( element.name !== ('captcha_input' + bk_type) ) {
197 - if (formdata !=='') formdata += '~'; // next field element
198 -
199 - el_type = element.type;
200 - if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email';
201 - if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon';
202 -
203 - inp_value = inp_value + '';
204 - inp_value = inp_value.replace(new RegExp("\\^",'g'), '&#94;'); // replace registered characters
205 - inp_value = inp_value.replace(new RegExp("~",'g'), '&#126;'); // replace registered characters
206 -
207 - inp_value = inp_value.replace(/"/g, '&#34;'); // replace double quot
208 - inp_value = inp_value.replace(/'/g, '&#39;'); // replace single quot
209 -
210 - if ( 'select-one' == el_type ){
211 - el_type = 'selectbox-one'
212 - }
213 - if ( 'select-multiple' == el_type ){
214 - el_type = 'selectbox-multiple'
215 - }
216 -
217 - formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr
218 - }
219 - }
220 -
221 - } // End Fields Loop
222 -
223 -
224 - // TODO: here was function for 'Check if visitor finish dates selection.
225 -
226 -
227 - // Cpatch verify
228 - var captcha = document.getElementById('wpdev_captcha_challenge_' + bk_type);
229 -
230 - //Disable Submit button
231 - if (captcha != null) form_submit_send( bk_type, formdata, captcha.value, document.getElementById('captcha_input' + bk_type).value ,wpdev_active_locale);
232 - else form_submit_send( bk_type, formdata, '', '' , wpdev_active_locale);
233 - return;
234 -}
235 -
236 -
237 -// Gathering params for sending Ajax request and then send it
238 -function form_submit_send( bk_type, formdata, captcha_chalange, user_captcha ,wpdev_active_locale){
239 -
240 - var my_booking_form = '';
241 - if ( document.getElementById( 'booking_form_type' + bk_type ) != undefined ){
242 - my_booking_form = document.getElementById( 'booking_form_type' + bk_type ).value;
243 - }
244 -
245 - var my_booking_hash = '';
246 - if ( _wpbc.get_other_param( 'this_page_booking_hash' ) != '' ){
247 - my_booking_hash = _wpbc.get_other_param( 'this_page_booking_hash' );
248 - }
249 -
250 - var is_send_emeils = 1;
251 - if ( jQuery('#is_send_email_for_pending').length ) {
252 - is_send_emeils = jQuery( '#is_send_email_for_pending' ).is( ':checked' ); //FixIn: 8.7.9.5
253 - if ( false === is_send_emeils ) { is_send_emeils = 0; }
254 - else { is_send_emeils = 1; }
255 - }
256 -
257 - if ( document.getElementById( 'date_booking' + bk_type ).value != '' ){ //FixIn:6.1.1.3
258 - send_ajax_submit( bk_type, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ); // Ajax sending request
259 - } else {
260 - jQuery( '#booking_form_div' + bk_type ).hide();
261 - jQuery( '#submiting' + bk_type ).hide();
262 - }
263 -
264 - var formdata_additional_arr;
265 - var formdata_additional;
266 - var my_form_field;
267 - var id_additional;
268 - var id_additional_str;
269 - var id_additional_arr;
270 - if (document.getElementById('additional_calendars' + bk_type) != null ) {
271 -
272 - id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign
273 - id_additional_arr = id_additional_str.split(',');
274 -
275 -
276 - //TODO: remove this spinner and add the new !!!
277 - //FixIn: 8.5.2.26
278 - if ( ! jQuery( '#booking_form_div' + bk_type ).is( ':visible' ) ) {
279 - jQuery( '#booking_form_div' + bk_type ).after(
280 - '<div class="wpbc_submit_spinner" style="height:20px;width:100%;text-align:center;margin:15px auto;"><img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+_wpbc.get_other_param( 'url_plugin' )+'/assets/img/ajax-loader.gif"></div>'
281 - );
282 - }
283 -
284 -
285 -
286 - for (var ia=0;ia<id_additional_arr.length;ia++) {
287 - formdata_additional_arr = formdata;
288 - formdata_additional = '';
289 - id_additional = id_additional_arr[ia];
290 -
291 -
292 - formdata_additional_arr = formdata_additional_arr.split('~');
293 - for (var j=0;j<formdata_additional_arr.length;j++) {
294 - my_form_field = formdata_additional_arr[j].split('^');
295 - if (formdata_additional !=='') formdata_additional += '~';
296 -
297 - if (my_form_field[1].substr( (my_form_field[1].length -2),2)=='[]')
298 - my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) - 2 ) + id_additional + '[]';
299 - else
300 - my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) ) + id_additional ;
301 -
302 -
303 - formdata_additional += my_form_field[0] + '^' + my_form_field[1] + '^' + my_form_field[2];
304 - }
305 -
306 - if ( jQuery('#gateway_payment_forms' + bk_type).length > 0 ) { // If Payment form for main booking resources is showing then append payment form for additional calendars.
307 - jQuery('#gateway_payment_forms' + bk_type).after('<div id="gateway_payment_forms'+id_additional+'"></div>');
308 - jQuery('#gateway_payment_forms' + bk_type).after('<div id="ajax_respond_insert'+id_additional+'" style="display:none;"></div>');
309 - }
310 - //FixIn: 8.5.2.17
311 - send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); // Submit
312 - }
313 - }
314 -}
315 -
316 -
317 -//<![CDATA[
318 -function send_ajax_submit( resource_id, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ){
319 -
320 - // Disable Submit | Show spin loader
321 - wpbc_booking_form__on_submit__ui_elements_disable( resource_id )
322 -
323 - var is_exit = wpbc_ajx_booking__create( {
324 - 'resource_id' : resource_id,
325 - 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value,
326 - 'formdata' : formdata,
327 - 'booking_hash' : my_booking_hash,
328 - 'custom_form' : my_booking_form,
329 - 'aggregate_resource_id_arr': ( ( null !== _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' ))
330 - ? _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' ).join( ',' ) : ''),
331 - 'captcha_chalange' : captcha_chalange,
332 - 'captcha_user_input' : user_captcha,
333 -
334 - 'is_emails_send' : is_send_emeils,
335 - 'active_locale' : wpdev_active_locale
336 - } );
337 - if ( true === is_exit ){
338 - return;
339 - }
340 -}
341 -//]]>
342 -
343 -
344 -// Hint labels inside of input boxes
345 -jQuery(document).ready( function(){
346 -
347 - jQuery('div.inside_hint').on( 'click', function(){ //FixIn: 8.7.11.12
348 - jQuery(this).css('visibility', 'hidden').siblings('.has-inside-hint').trigger( 'focus' ); //FixIn: 8.7.11.12
349 - });
350 -
351 - jQuery('input.has-inside-hint').on( 'blur', function(){ //FixIn: 8.7.11.12
352 - if ( this.value == '' )
353 - jQuery(this).siblings('.inside_hint').css('visibility', '');
354 - }).on( 'focus', function(){ //FixIn: 8.7.11.12
355 - jQuery(this).siblings('.inside_hint').css('visibility', 'hidden');
356 - });
357 -
358 - jQuery('.booking_form_div input[type=button]').prop("disabled", false);
359 -});
360 -
361 -// == Support Functions ================================================================================================
362 -
363 -//FixIn: 8.8.1.3
364 1 /**
365 - * Trim strings and array joined with (,)
366 - *
367 - * @param string_to_trim string / array
368 - * @returns string
369 - */
370 -function wpbc_trim( string_to_trim ){
371 -
372 - if ( Array.isArray( string_to_trim ) ){
373 - string_to_trim = string_to_trim.join( ',' );
374 - }
375 -
376 - if ( 'string' == typeof (string_to_trim) ){
377 - string_to_trim = string_to_trim.trim();
378 - }
379 -
380 - return string_to_trim;
381 -}
382 -
383 -function wpdev_in_array (array_here, p_val) {
384 - for(var i = 0, l = array_here.length; i < l; i++) {
385 - if(array_here[i] == p_val) {
386 - return true;
387 - }
388 - }
389 - return false;
390 -}
391 -
392 -//FixIn: 8.4.0.2
393 -/**
394 2 * Check errors in booking form fields, and show warnings if some errors exist.
395 - * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone fields, etc...
3 + * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone
4 + * fields, etc...
396 5 *
397 - * @param bk_type int (ID of booking resource)
6 + * @param resource_id int (ID of booking resource)
398 7 */
399 -function wpbc_check_errors_in_booking_form( bk_type ) {
8 +function wpbc_check_errors_in_booking_form( resource_id ) {
9 + var $form = jQuery( '#booking_form' + resource_id );
10 + var fields_with_errors_arr = [];
11 + var is_error_in_field = false;
12 + var skip_element_types = [ 'hidden', 'button' ];
400 13
401 - var is_error_in_field = false; // By default, all is good - no error
14 + if ( ! $form.length ) {
15 + return false;
16 + }
402 17
403 - var my_form = jQuery( '#booking_form' + bk_type );
18 + /**
19 + * Show a validation warning and register the related field as invalid.
20 + *
21 + * @param {HTMLElement|null} field Field to focus after validation.
22 + * @param {HTMLElement|jQuery|string} target Warning message target.
23 + * @param {string} message Warning message.
24 + */
25 + function add_validation_error( field, target, message ) {
26 + wpbc_front_end__show_message__warning( target, message, 'text' );
27 + is_error_in_field = true;
404 28
405 - if ( my_form.length ) {
29 + if ( field ) {
30 + fields_with_errors_arr.push( field );
31 + }
32 + }
406 33
407 - var fields_with_errors_arr = [];
34 + /**
35 + * Validate a required field.
36 + *
37 + * @param {HTMLElement} field Form field.
38 + * @param {jQuery} $field Cached jQuery field.
39 + * @param {string} field_type Field type.
40 + */
41 + function validate_required_field( field, $field, field_type ) {
42 + var warning_target;
408 43
409 - // Pseudo-selector that get form elements <input , <textarea , <select, <button...
410 - my_form.find( ':input' ).each( function( index, el ) {
44 + if ( ! $field.hasClass( 'wpdev-validates-as-required' ) ) {
45 + return;
46 + }
411 47
412 - // Skip some elements
413 - var skip_elements = [ 'hidden', 'button' ];
48 + if ( 'checkbox' === field_type ) {
49 + if ( ! $field.is( ':checked' ) && ! jQuery( ':checkbox[name="' + field.name + '"]', $form ).is( ':checked' ) ) {
50 + warning_target = $field.parents( '.wpdev-form-control-wrap' ).last();
414 51
415 - if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){
52 + if ( ! warning_target.length ) {
53 + warning_target = $field.parents( '.controls' ).last();
54 + }
55 + if ( ! warning_target.length ) {
56 + warning_target = $field;
57 + }
416 58
417 - // Check Calendar Dates Selection
418 - if ( ( 'date_booking' + bk_type ) == jQuery( el ).attr( 'name' ) ) {
59 + add_validation_error( field, warning_target, _wpbc.get_message( 'message_check_required_for_check_box' ) );
60 + }
61 + return;
62 + }
419 63
420 - // Show Warning only if the calendar visible ( we are at step with calendar)
421 - if (
422 - ( ( jQuery( '#calendar_booking' + bk_type ).is( ':visible' ) ) && ( '' == jQuery( el ).val() ) )
423 - && ( wpbc_get_arr_of_selected_additional_calendars( bk_type ).length == 0 ) //FixIn: 8.5.2.26
424 - ){ //FixIn: 8.4.4.5
64 + if ( 'radio' === field_type ) {
65 + if ( ! jQuery( ':radio[name="' + field.name + '"]', $form ).is( ':checked' ) ) {
66 + add_validation_error( field, $field.parents( '.wpdev-form-control-wrap' ), _wpbc.get_message( 'message_check_required_for_radio_box' ) );
67 + }
68 + return;
69 + }
425 70
426 - var notice_message_id = wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', _wpbc.get_message( 'message_check_no_selected_dates' ) , 3000 );
71 + if ( '' === wpbc_trim( $field.val() ) ) {
72 + add_validation_error( field, field, _wpbc.get_message( 'message_check_required' ) );
73 + }
74 + }
427 75
428 - //wpbc_do_scroll('#calendar_booking' + bk_type); // Scroll to the calendar //FixIn: 8.5.1.3
429 - is_error_in_field = true; // Error
430 - }
431 - }
76 + /**
77 + * Validate an email field and return its trimmed value.
78 + *
79 + * @param {HTMLElement} field Form field.
80 + * @param {jQuery} $field Cached jQuery field.
81 + * @returns {string}
82 + */
83 + function validate_email_field( field, $field ) {
84 + var email_value = String( $field.val() || '' ).replace( /^\s+|\s+$/gm, '' );
85 + var email_regex = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/;
432 86
433 - // Check only visible elements at this step
434 - if ( jQuery( el ).is( ':visible' ) ){
435 -// console.log( '|id, type, val, visible|::', jQuery( el ).attr( 'name' ), '|' + jQuery( el ).attr( 'type' ) + '|', jQuery( el ).val(), jQuery( el ).is( ':visible' ) );
87 + if ( '' !== email_value && ! email_regex.test( email_value ) ) {
88 + add_validation_error( field, field, _wpbc.get_message( 'message_check_email' ) );
89 + }
436 90
437 - // Is Required
438 - if ( jQuery( el ).hasClass( 'wpdev-validates-as-required' ) ){
91 + return email_value;
92 + }
439 93
440 - // Checkboxes
441 - if ( 'checkbox' == jQuery( el ).attr( 'type' ) ){
94 + /**
95 + * Validate a confirmation email field using its same_as_NAME class.
96 + *
97 + * @param {HTMLElement} field Form field.
98 + * @param {string} email_value Trimmed confirmation email value.
99 + */
100 + function validate_confirmation_email_field( field, email_value ) {
101 + var primary_email_match;
102 + var primary_email_name;
103 + var $primary_email_field;
442 104
443 - if (
444 - ( ! jQuery( el ).is( ':checked' ))
445 - && ( ! jQuery( ':checkbox[name="' + el.name + '"]', my_form ).is( ":checked" ) ) //FixIn: 8.5.2.12
446 - ){
447 - var checkbox_parent_element;
105 + if ( field.className.indexOf( 'same_as_' ) === -1 ) {
106 + return;
107 + }
448 108
449 - if ( jQuery( el ).parents( '.wpdev-form-control-wrap' ).length > 0 ){
109 + primary_email_match = field.className.match( /same_as_([^\s])+/gi );
110 + if ( null === primary_email_match ) {
111 + return;
112 + }
450 113
451 - checkbox_parent_element = jQuery( el ).parents( '.wpdev-form-control-wrap' );
114 + primary_email_name = primary_email_match[ 0 ].substr( 8 );
115 + $primary_email_field = $form.find( '[name="' + primary_email_name + resource_id + '"]' );
452 116
453 - } else if ( jQuery( el ).parents( '.controls' ).length > 0 ){
117 + if ( $primary_email_field.length && $primary_email_field.val() !== email_value ) {
118 + add_validation_error( field, field, _wpbc.get_message( 'message_check_same_email' ) );
119 + }
120 + }
454 121
455 - checkbox_parent_element = jQuery( el ).parents( '.controls' );
122 + /**
123 + * Validate fields using the validate_as_date, validate_as_digit, or validate_digit_N classes.
124 + *
125 + * @param {HTMLElement} field Form field.
126 + * @param {jQuery} $field Cached jQuery field.
127 + */
128 + function validate_custom_field_classes( field, $field ) {
129 + var class_list = $field.attr( 'class' );
130 + var field_value;
456 131
457 - } else {
132 + if ( ! class_list ) {
133 + return;
134 + }
458 135
459 - checkbox_parent_element = jQuery( el );
460 - }
461 - var notice_message_id = wpbc_front_end__show_message__warning( checkbox_parent_element, _wpbc.get_message( 'message_check_required_for_check_box' ) );
136 + field_value = $field.val();
462 137
463 - fields_with_errors_arr.push( el );
464 - is_error_in_field = true; // Error
465 - }
138 + jQuery.each( class_list.split( /\s+/ ), function ( class_index, class_name ) {
139 + var digits_to_check;
140 + var message;
141 + var validation_regex;
466 142
467 - // Radio boxes
468 - } else if ( 'radio' == jQuery( el ).attr( 'type' ) ){
143 + if ( 'validate_as_date' === class_name ) {
144 + validation_regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' );
145 + message = _wpbc.get_message( 'message_check_valid_date' ).replace( '{date_example}', '09/25/2018' );
469 146
470 - if ( !jQuery( ':radio[name="' + jQuery( el ).attr( 'name' ) + '"]', my_form ).is( ':checked' ) ){
471 - var notice_message_id = wpbc_front_end__show_message__warning( jQuery( el ).parents('.wpdev-form-control-wrap'), _wpbc.get_message( 'message_check_required_for_radio_box' ) );
472 - fields_with_errors_arr.push( el );
473 - is_error_in_field = true; // Error
474 - }
147 + if ( '' !== field_value && ! validation_regex.test( field_value ) ) {
148 + add_validation_error( field, field, message );
149 + }
150 + return;
151 + }
475 152
476 - // Other elements
477 - } else {
153 + if ( 'validate_as_digit' === class_name ) {
154 + validation_regex = new RegExp( '^[0-9]+\\.?[0-9]*$' );
478 155
479 - var inp_value = jQuery( el ).val();
156 + if ( '' !== field_value && ! validation_regex.test( field_value ) ) {
157 + add_validation_error( field, field, _wpbc.get_message( 'message_check_digits_only' ) );
158 + }
159 + return;
160 + }
480 161
481 - if ( '' === wpbc_trim( inp_value ) ){ //FixIn: 8.8.1.3 //FixIn: 8.7.11.12
162 + if ( 'validate_digit_' !== class_name.substring( 0, 15 ) ) {
163 + return;
164 + }
482 165
483 - var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_required' ) );
166 + digits_to_check = parseInt( class_name.substring( 15 ), 10 );
167 + if ( isNaN( digits_to_check ) ) {
168 + return;
169 + }
484 170
485 - fields_with_errors_arr.push( el );
486 - is_error_in_field = true; // Error
487 - }
488 - }
489 - }
171 + validation_regex = new RegExp( '^\\d{' + digits_to_check + '}$' );
172 + message = _wpbc.get_message( 'message_check_digits_count' ).replace( '{digits}', digits_to_check );
490 173
491 - // Validate Email
492 - if ( jQuery( el ).hasClass( 'wpdev-validates-as-email' ) ){
493 - var inp_value = jQuery( el ).val();
494 - inp_value = inp_value.replace( /^\s+|\s+$/gm, '' ); // Trim white space //FixIn: 5.4.5
495 - var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/;
496 - if ( (inp_value != '') && (reg.test( inp_value ) == false) ){
174 + if ( '' !== field_value && ! validation_regex.test( field_value ) ) {
175 + add_validation_error( field, field, message );
176 + }
177 + } );
178 + }
497 179
498 - var notice_message_id = wpbc_front_end__show_message__warning( el, _wpbc.get_message( 'message_check_email' ) );
499 - fields_with_errors_arr.push( el );
500 - is_error_in_field = true; // Error
501 - }
502 - }
180 + $form.find( ':input' ).each( function () {
181 + var field = this;
182 + var $field = jQuery( field );
183 + var field_type = $field.attr( 'type' );
184 + var email_value;
503 185
504 - // Validate For digit entering - for example for - Phone
505 - // <p>Digit Field:<br />[text* dig_field class:validate_as_digit] </p>
506 - // <p>Phone:<br />[text* phone class:validate_digit_8] </p>
186 + if ( -1 !== skip_element_types.indexOf( field_type ) ) {
187 + return;
188 + }
507 189
508 - var classList = jQuery( el ).attr( 'class' );
190 + if ( '1' === String( $field.attr( 'data-wpbc-booking-submit-ignore' ) || '' ) ) {
191 + return;
192 + }
509 193
510 - if ( classList ){
194 + if (
195 + ( 'date_booking' + resource_id === $field.attr( 'name' ) ) &&
196 + jQuery( '#calendar_booking' + resource_id ).is( ':visible' ) &&
197 + ( '' === $field.val() ) &&
198 + ( 0 === wpbc_get_arr_of_selected_additional_calendars( resource_id ).length )
199 + ) {
200 + add_validation_error(
201 + null,
202 + '#booking_form_div' + resource_id + ' .bk_calendar_frame',
203 + _wpbc.get_message( 'message_check_no_selected_dates' )
204 + );
205 + }
511 206
512 - classList = classList.split( /\s+/ );
207 + if ( ! $field.is( ':visible' ) ) {
208 + return;
209 + }
513 210
514 - jQuery.each( classList, function ( cl_index, cl_item ){
211 + validate_required_field( field, $field, field_type );
515 212
516 - ////////////////////////////////////////////////////////////////////////////////////////////
213 + if ( $field.hasClass( 'wpdev-validates-as-email' ) ) {
214 + email_value = validate_email_field( field, $field );
215 + validate_confirmation_email_field( field, email_value );
216 + }
517 217
518 - // Validate field value as "Date" [CSS class - 'validate_as_digit']
519 - if ( 'validate_as_date' === cl_item ) {
218 + validate_custom_field_classes( field, $field );
219 + } );
520 220
521 - // Valid values: 09-25-2018, 09/25/2018, 09-25-2018, 31-9-1918 --- m/d/Y, m.d.Y, m-d-Y, d/m/Y, d.m.Y, d-m-Y
522 - var regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' ); // Check for Date 09/25/2018
523 - var message_verif_phone = 'This field must be valid date like this ' + '09/25/2018';
524 - var inp_value = jQuery( el ).val();
221 + if ( fields_with_errors_arr.length ) {
222 + jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' );
223 + }
525 224
526 - if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){
527 - wpbc_front_end__show_message__warning( el, message_verif_phone );
528 - fields_with_errors_arr.push( el );
529 - is_error_in_field = true; // Error
530 - }
531 - }
225 + return is_error_in_field;
226 +}
532 227
533 - ////////////////////////////////////////////////////////////////////////////////////////////
228 +/**
229 + * Hint labels inside of input boxes.
230 + */
231 +jQuery( document ).ready(
232 + function () {
534 233
535 - // Validate field value as "DIGIT" [CSS class - 'validate_as_digit']
536 - if ( 'validate_as_digit' === cl_item ) {
234 + jQuery( 'div.inside_hint' ).on(
235 + 'click',
236 + function () {
237 + jQuery( this ).css( 'visibility', 'hidden' ).siblings( '.has-inside-hint' ).trigger( 'focus' );
238 + }
239 + );
537 240
538 - var regex = new RegExp( '^[0-9]+\\.?[0-9]*$' ); // Check for digits
539 - var message_verif_phone = 'This field must contain only digits';
540 - var inp_value = jQuery( el ).val();
541 -
542 - if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){
543 - wpbc_front_end__show_message__warning( el, message_verif_phone );
544 - fields_with_errors_arr.push( el );
545 - is_error_in_field = true; // Error
546 - }
547 - }
548 -
549 - ////////////////////////////////////////////////////////////////////////////////////////////
550 -
551 - // Validate field value as "Phone" number or any other valid number wth specific number of digits [CSS class - 'validate_digit_8' || 'validate_digit_10' ]
552 - var is_validate_digit = cl_item.substring( 0, 15 );
553 -
554 - // Check if class start with 'validate_digit_'
555 - if ( 'validate_digit_' === is_validate_digit ){
556 -
557 - // Get number of digit in class: validate_digit_8 => 8 or validate_digit_10 => 10
558 - var digits_to_check = parseInt( cl_item.substring( 15 ) );
559 -
560 - // Check about any errors in
561 - if ( !isNaN( digits_to_check ) ){
562 -
563 - var regex = new RegExp( '^\\d{' + digits_to_check + '}$' ); // We was valid it as parseInt - only integer variable - digits_to_check
564 - var message_verif_phone = 'This field must contain ' + digits_to_check + ' digits';
565 - var inp_value = jQuery( el ).val();
566 -
567 - if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){
568 - wpbc_front_end__show_message__warning( el, message_verif_phone );
569 - fields_with_errors_arr.push( el );
570 - is_error_in_field = true; // Error
571 - }
572 - }
573 - }
574 -
575 - ////////////////////////////////////////////////////////////////////////////////////////////
576 -
577 - });
578 - }
579 - }
241 + jQuery( 'input.has-inside-hint' ).on(
242 + 'blur',
243 + function () {
244 + if ( '' === this.value ) {
245 + jQuery( this ).siblings( '.inside_hint' ).css( 'visibility', '' );
246 + }
580 247 }
581 - } );
248 + ).on(
249 + 'focus',
250 + function () {
251 + jQuery( this ).siblings( '.inside_hint' ).css( 'visibility', 'hidden' );
252 + }
253 + );
582 254
583 - if ( fields_with_errors_arr.length > 0 ){
584 - jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' ); //FixIn: 9.3.1.9
585 - }
255 + jQuery( '.booking_form_div input[type=button]' ).prop( "disabled", false );
586 256 }
257 +);
587 258
588 - return is_error_in_field;
589 -}
259 +// == WIZARD ===========================================================================================================
590 260
591 -//FixIn: 8.4.4.4
592 -function bk_calendar_step_click( el ){
593 - var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val();
594 - var is_error = wpbc_check_errors_in_booking_form( br_id );
595 - if ( is_error ){
596 - return false;
597 - }
598 - if ( br_id != undefined ){
599 - jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "none"} );
600 - jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "block"} );
601 - } else {
602 - jQuery( ".bk_calendar_step" ).css( {"display": "none"} );
603 - jQuery( ".bk_form_step" ).css( {"display": "block"} );
604 - }
605 -}
606 -
607 -function bk_form_step_click( el ){
608 - var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val();
609 - var is_error = false; // wpbc_check_errors_in_booking_form( br_id ); //FixIn: 8.4.5.6
610 - if ( is_error ){
611 - return false;
612 - }
613 - if ( br_id != undefined ){
614 - jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "block"} );
615 - jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "none"} );
616 - wpbc_do_scroll( "#bklnk" + br_id );
617 - } else {
618 - jQuery( ".bk_calendar_step" ).css( {"display": "block"} );
619 - jQuery( ".bk_form_step" ).css( {"display": "none"} );
620 - }
621 -}
622 -
623 -//FixIn: 8.6.1.15
624 261 /**
625 262 * Go to next specific step in Wizard style booking form, with
626 263 * check all required elements specific step, otherwise show warning message!
627 264 *
@@ -628,100 +265,132 @@
628 265 * @param el
629 266 * @param step_num
630 267 * @returns {boolean}
631 268 */
632 -function wpbc_wizard_step( el, step_num, step_from ){
633 - var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val();
269 +function wpbc_wizard_step(el, step_num, step_from) {
634 270
635 - //FixIn: 8.8.1.5
636 - if ( ( undefined == step_from ) || ( step_num > step_from ) ){
637 - if ( 1 != step_num ){ //FixIn: 8.7.7.8
638 - var is_error = wpbc_check_errors_in_booking_form( br_id );
639 - if ( is_error ){
640 - return false;
641 - }
642 - }
643 - }
271 + var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val();
644 272
645 - if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){
646 - if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ){
647 - return false;
648 - }
649 - }
273 + // FixIn: 8.8.1.5.
274 + if ( (undefined == step_from) || (step_num > step_from) ) {
275 + if ( 1 != step_num ) { // FixIn: 8.7.7.8.
276 + var is_error = wpbc_check_errors_in_booking_form( br_id );
277 + if ( is_error ) {
278 + return false;
279 + }
280 + }
281 + }
650 282
651 - if ( br_id != undefined ){
652 - jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( {"display": "none"} ).removeClass('wpbc_wizard_step_hidden');
653 - jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( {"display": "block"} );
654 - }
283 + if ( wpbc_is_some_elements_visible( br_id, [ 'rangetime', 'durationtime', 'starttime', 'endtime' ] ) ) {
284 + if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ) {
285 + return false;
286 + }
287 + }
288 +
289 + if ( br_id != undefined ) {
290 + jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( { "display": "none" } )
291 + .removeClass( 'wpbc_wizard_step_hidden' );
292 + jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( { "display": "block" } );
293 + return jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num );
294 + }
655 295 }
656 296
657 -//FixIn: 10.1.3.2
658 -jQuery( document ).ready( function (){
659 297
660 - // CSS classes in Wizard Next / Prior links can be like this: <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_1">Step 1</a> | <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_2">Step 2</a>
298 +/**
299 + * Init Buttons in Booking form Wizard
300 + */
301 +function wpbc_hook__init_booking_form_wizard_buttons() {
661 302
662 - jQuery( '.wpbc_wizard_step_button' ).attr( {
663 - href: 'javascript:void(0)'
664 - } );
303 + // CSS classes in Wizard Next / Prior links can be like this: <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_1">Step 1</a> | <a class="wpbc_button_light wpbc_wizard_step_button wpbc_wizard_step_2">Step 2</a> .
665 304
666 - jQuery( '.wpbc_wizard_step_button' ).on( 'click', function ( event ){
305 + jQuery( '.wpbc_wizard_step_button' ).attr(
306 + {
307 + href: 'javascript:void(0)',
308 + }
309 + );
667 310
668 - var found_steps_arr = jQuery( this ).attr( 'class' ).match( /wpbc\_wizard\_step\_([\d]+)([\s'"]+|$)/ );
311 + jQuery( '.wpbc_wizard_step_button' ).off( 'click.wpbc_booking_form_wizard' ).on(
312 + 'click.wpbc_booking_form_wizard',
313 + function (event) {
314 + var found_steps_arr = jQuery( this ).attr( 'class' ).match( /wpbc\_wizard\_step\_([\d]+)([\s'"]+|$)/ );
669 315
670 - if ( (null !== found_steps_arr) && (found_steps_arr.length > 2) ){
671 - var step = parseInt( found_steps_arr[ 1 ] );
672 - if ( step > 0 ){
673 - wpbc_wizard_step( this, step );
674 - }
675 - }
676 - } );
316 + if ( (null !== found_steps_arr) && (found_steps_arr.length > 2) ) {
317 + var step = parseInt( found_steps_arr[1] );
318 + if ( step > 0 ) {
319 + var jq_step_element;
320 + // Check actual step in booking form for getting step_from number.
321 + var this_formsteps_arr = jQuery( this ).parents( '.wpbc_wizard_step' ).attr( 'class' ).match( /wpbc\_wizard\_step([\d]+)([\s'"]+|$)/ );
322 + if ( (null !== this_formsteps_arr) && (this_formsteps_arr.length > 2) ) {
323 + var step_from = parseInt( this_formsteps_arr[1] );
324 + jq_step_element = wpbc_wizard_step( this, step, step_from );
325 + } else {
326 + jq_step_element = wpbc_wizard_step( this, step );
327 + }
328 + // Do Scroll.
329 + if ( false !== jq_step_element ) {
330 + wpbc_do_scroll( jq_step_element ); // wpbc_do_scroll( jQuery('.wpbc_wizard_step:visible') );.
331 + }
332 + }
333 + }
334 + }
335 + );
336 +}
677 337
678 -} );
679 338
680 -
681 -//FixIn: 8.6.1.15
682 339 /**
683 340 * Check if at least one element from array of elements names in booking form visible or not.
684 - * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ ... }
341 + * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] )
342 + * ){ ... }
685 343 *
686 - * @param bk_type
344 + * @param resource_id
687 345 * @param elements_names
688 346 * @returns {boolean}
689 347 */
690 -function wpbc_is_some_elements_visible( bk_type, elements_names ){
348 +function wpbc_is_some_elements_visible(resource_id, elements_names) {
691 349
692 - var is_some_elements_visible = false;
350 + var my_form = jQuery( '#booking_form' + resource_id );
693 351
694 - var my_form = jQuery( '#booking_form' + bk_type );
352 + if ( ! my_form.length ) {
353 + return false;
354 + }
695 355
696 - if ( my_form.length ){
356 + var is_some_elements_visible = false;
357 + // Pseudo-selector that get form elements <input , <textarea , <select, <button...
358 + my_form.find( ':input' ).each(
359 + function (index, el) {
697 360
698 - // Pseudo-selector that get form elements <input , <textarea , <select, <button...
699 - my_form.find( ':input' ).each( function ( index, el ){
361 + // Skip some elements.
362 + var skip_elements = [ 'hidden', 'button' ];
700 363
701 - // Skip some elements
702 - var skip_elements = ['hidden', 'button'];
364 + if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ) {
703 365
704 - if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){
366 + for ( var ei = 0; ei < (elements_names.length - 1); ei++ ) {
705 367
706 - for ( var ei = 0; ei < ( elements_names.length - 1) ; ei++ ){
368 + // Check Calendar Dates Selection.
369 + if ( (elements_names[ei] + resource_id) == jQuery( el ).attr( 'name' ) ) {
707 370
708 - // Check Calendar Dates Selection
709 - if ( (elements_names[ ei ] + bk_type) == jQuery( el ).attr( 'name' ) ){
371 + if ( jQuery( el ).is( ':visible' ) ) {
372 + is_some_elements_visible = true;
373 + }
374 + }
375 + }
376 + }
377 + }
378 + );
710 379
711 - if ( jQuery( el ).is( ':visible' ) ){
712 - is_some_elements_visible = true;
713 - }
714 - }
715 - }
716 - }
717 - } );
718 - }
719 - return is_some_elements_visible;
380 + return is_some_elements_visible;
720 381 }
721 382
722 -// == Days Selections - support functions ==============================================================================
723 383
384 +jQuery( document ).ready(
385 + function () {
386 + wpbc_hook__init_booking_form_wizard_buttons();
387 + }
388 +);
389 +
390 +
391 +// == DAYS_SELECTIONS ==================================================================================================
392 +
724 393 /**
725 394 * Get first day of selection
726 395 *
727 396 * @param dates
@@ -758,9 +427,15 @@
758 427 // Single day selection
759 428 return dates; //20.12.2013
760 429 }
761 430
762 -// Get last day of selection
431 +
432 +/**
433 + * Get last day of selection.
434 + *
435 + * @param dates
436 + * @returns {*|string}
437 + */
763 438 function get_last_day_of_selection(dates) {
764 439
765 440 // Multiple days selections
766 441 if ( dates.indexOf(',') != -1 ){
@@ -798,9 +473,9 @@
798 473 *
799 474 * @param int bk_type
800 475 * @returns array
801 476 */
802 -function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ //FixIn: 8.5.2.26
477 +function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ // FixIn: 8.5.2.26.
803 478
804 479 var selected_additionl_calendars = [];
805 480
806 481 // Checking according additional calendars
@@ -808,10 +483,8 @@
808 483
809 484 var id_additional_str = document.getElementById( 'additional_calendars' + bk_type ).value;
810 485 var id_additional_arr = id_additional_str.split( ',' );
811 486
812 - var is_all_additional_days_unselected = true;
813 -
814 487 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){
815 488 if ( document.getElementById( 'date_booking' + id_additional_arr[ ia ] ).value != '' ){
816 489 selected_additionl_calendars.push( id_additional_arr[ ia ] );
817 490 }
@@ -818,4 +491,46 @@
818 491 }
819 492 }
820 493 return selected_additionl_calendars;
821 494 }
495 +
496 +
497 +// == ELEMENTOR Ready Widget Update ====================================================================================
498 +
499 +jQuery( function ($) {
500 + // FixIn: 10.14.15.1.
501 + if ( (window.elementorFrontend) && ('undefined' !== typeof (elementorFrontend.hooks)) ) {
502 +
503 + elementorFrontend.hooks.addAction( 'frontend/element_ready/wpbc_widget_booking_form_1.default', function ($scope) {
504 + // Simulate DOM ready, after updating Elementor Widget.
505 + jQuery( document ).trigger( 'wpbc_elementor_ready' );
506 + } );
507 +
508 + // Catch all widget re-renders.
509 + // elementorFrontend.hooks.addAction( 'frontend/element_ready/global', function ($scope) {
510 + // console.log( 'Some widget was re-rendered:', $scope );
511 + // } );
512 + }
513 +} );
514 +
515 +// Elementor widget reinit. So we need to reinit all "jQuery( document ).ready( ...) " again with custom 'wpbc_elementor_ready' event.
516 +jQuery( document ).on(
517 + 'wpbc_elementor_ready',
518 + function () {
519 +
520 + wpbc_hook__init_booking_form_wizard_buttons();
521 +
522 + if ( 'function' === typeof (wpbc_hook__init_timeselector) ) {
523 + wpbc_hook__init_timeselector();
524 + }
525 +
526 + if ( 'function' === typeof (wpbc_update_capacity_hint) ) {
527 + jQuery( '.booking_form_div' ).on(
528 + 'wpbc_booking_date_or_option_selected',
529 + function (event, resource_id) {
530 + wpbc_update_capacity_hint( resource_id );
531 + }
532 + );
533 + }
534 +
535 + }
536 +);