1jQuery( document ).ready( function( $ ) { 2 'use strict'; 3 4 /* external payment thank you page */ 5 6 if ( $( '#hb-resa-payment-thank-you-page-redirect' ).length ) { 7 if ( typeof window['hbook_reservation_done'] == 'function' ) { 8 window['hbook_reservation_done'](); 9 } 10 $( '#hb-resa-payment-thank-you-page-redirect' ).submit(); 11 } 12 13 /* end external payment thank you page */ 14 15 /* ------------------------------------------------------------------------------------------- */ 16 17 /* padding top */ 18 19 var page_padding_top; 20 if ( typeof hb_booking_form_data !== 'undefined' ) { 21 page_padding_top = hb_booking_form_data.page_padding_top; 22 } else { 23 page_padding_top = hb_payment_confirmation_padding_top; 24 } 25 26 var adminbar_height = 0; 27 if ( $( '#wpadminbar' ).length ) { 28 adminbar_height = $( '#wpadminbar' ).height(); 29 page_padding_top = parseInt( page_padding_top ) + adminbar_height; 30 } 31 32 /* end padding top */ 33 34 /* ------------------------------------------------------------------------------------------- */ 35 36 /* id and for attributes */ 37 38 if ( ( typeof hb_booking_form_data !== 'undefined' ) && ( hb_booking_form_data.is_admin != 'yes' ) ) { 39 var form_nb = 1; 40 $( '.hbook-wrapper' ).each( function() { 41 $( this ).find( 'label' ).each( function() { 42 var new_attr_for = 'hb-form-' + form_nb + '-' + $( this ).attr( 'for' ); 43 $( this ).attr( 'for', new_attr_for ); 44 }); 45 $( this ).find( 'input, select, textarea' ).each( function() { 46 var attr_id = $( this ).attr( 'id' ); 47 if ( attr_id ) { 48 var new_attr_id = 'hb-form-' + form_nb + '-' + attr_id; 49 $( this ).attr( 'id', new_attr_id ); 50 } 51 }); 52 $( this ).find( '.hb-booking-search-form' ).addClass( 'hb-form-' + form_nb ); 53 $( this ).find( '.hb-multi-accom-people-selection-wrapper' ).attr( 'data-form-num', form_nb ); 54 form_nb++; 55 }); 56 } 57 58 /* end id and for attributes */ 59 60 /* ------------------------------------------------------------------------------------------- */ 61 62 /* booking search */ 63 64 $( 'body' ).append( '<div class="hb-people-popup-wrapper"></div>' ); 65 if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ) { 66 $( '.hb-people-popup-wrapper-close' ).css( 'display', 'block' ); 67 } 68 69 $( '.hb-accom-number' ).change( function() { 70 show_people_popup( $( this ) ); 71 }); 72 73 $( 'html' ).click( function( e ) { 74 if ( 75 ! $( e.target ).is( '.hb-people-popup-wrapper' ) && 76 ! $( e.target ).is( '.hb-accom-number' ) && 77 ! $( e.target ).is( '.hb-accom-number option' ) && 78 ! $( e.target ).is( '.hb-multi-accom-adults' ) && 79 ! $( e.target ).is( '.hb-multi-accom-adults option' ) && 80 ! $( e.target ).is( '.hb-multi-accom-children' ) && 81 ! $( e.target ).is( '.hb-multi-accom-children option' ) && 82 $( '.hb-people-popup-wrapper' ).hasClass( 'hb-people-popup-wrapper-visible' ) 83 ) { 84 hide_people_popup(); 85 } 86 if ( $( e.target ).is( '.hb-people-popup-wrapper-close' ) ) { 87 e.preventDefault(); 88 hide_people_popup(); 89 } 90 }); 91 92 function show_people_popup( $accom_people_select ) { 93 if ( ! $( '.hb-people-popup-wrapper' ).hasClass( 'hb-people-popup-wrapper-visible' ) ) { 94 $( '.hb-people-popup-wrapper' ).addClass(' hb-people-popup-wrapper-visible' ).html( '' ); 95 var $accom_people_selection = $accom_people_select.parents( '.hb-booking-search-form' ).find( '.hb-multi-accom-people-selection-wrapper' ); 96 $accom_people_selection.show(); 97 $( '.hb-people-popup-wrapper' ).append( $accom_people_selection ); 98 if ( ! $accom_people_select.parents( '.hb-booking-search-form' ).hasClass( 'hb-search-form-no-people' ) ) { 99 $( '.hb-people-popup-wrapper' ).show(); 100 } 101 } 102 var multi_accom_num = $accom_people_select.val(); 103 if ( multi_accom_num == 'any' ) { 104 multi_accom_num = 1; 105 } 106 $( '.hb-people-popup-wrapper .hb-multi-accom-people-selection' ).hide(); 107 for ( var i = 1; i <= multi_accom_num; i++ ) { 108 $( '.hb-people-popup-wrapper .hb-multi-accom-people-selection-accom-' + i ).show(); 109 } 110 if ( multi_accom_num > 1 ) { 111 $( '.hb-people-popup-wrapper .hb-multi-accom-people-title' ).show(); 112 } else { 113 $( '.hb-people-popup-wrapper .hb-multi-accom-people-title' ).hide(); 114 } 115 if ( $accom_people_select.parents( '.hb-booking-search-form' ).hasClass( 'hb-search-form-no-children' ) ) { 116 $( '.hb-multi-accom-children-wrapper' ).hide(); 117 } else { 118 $( '.hb-multi-accom-children-wrapper' ).show(); 119 } 120 reposition_people_popup(); 121 } 122 123 function hide_people_popup() { 124 if ( $( '.hb-people-popup-wrapper' ).hasClass( 'hb-people-popup-wrapper-visible' ) ) { 125 $( '.hb-people-popup-wrapper' ).hide().removeClass( 'hb-people-popup-wrapper-visible' ); 126 var $accom_people_selection = $( '.hb-people-popup-wrapper .hb-multi-accom-people-selection-wrapper' ); 127 $accom_people_selection.hide(); 128 if ( hb_booking_form_data.is_admin == 'yes' ) { 129 var $form = $( '.hb-booking-search-form' ); 130 } else { 131 var $form = $( '.hb-booking-search-form.hb-form-' + $accom_people_selection.data( 'form-num' ) ); 132 } 133 $form.append( $accom_people_selection ); 134 update_accom_people( $form ); 135 } 136 } 137 138 function update_accom_people( $form ) { 139 var accom_people = []; 140 var total_accom_people = 0; 141 var has_children = false;
142 var new_accom_number = $form.find( '.hb-accom-number' ).val(); 143 if ( new_accom_number == 'any' ) { 144 new_accom_number = 1; 145 $form.find( '.hb-accom-people-any').val( 'yes' ); 146 } else { 147 $form.find( '.hb-accom-people-any').val( 'no' ); 148 } 149 if ( new_accom_number > 0 ) { 150 for ( var i = 1; i <= new_accom_number; i++ ) { 151 var accom_adults = $form.find( '.hb-multi-accom-people-selection-accom-' + i + ' .hb-multi-accom-adults' ).val(); 152 var accom_children = $form.find( '.hb-multi-accom-people-selection-accom-' + i + ' .hb-multi-accom-children' ).val(); 153 if ( accom_children > 0 ) { 154 has_children = true; 155 } 156 accom_people.push( accom_adults + '-' + accom_children ); 157 total_accom_people += parseInt( accom_adults ) + parseInt( accom_children ); 158 } 159 if ( accom_people.length ) { 160 accom_people = accom_people.join( ',' ); 161 } else { 162 accom_people = ''; 163 } 164 $form.find( '.hb-accom-people' ).val( accom_people ); 165 if ( has_children ) { 166 var option_text = hb_text.chosen_persons_in_accom_number.replace( '%nb_persons', total_accom_people ); 167 } else if ( total_accom_people > 1 ) { 168 var option_text = hb_text.chosen_adults_in_accom_number.replace( '%nb_adults', total_accom_people ); 169 } else { 170 var option_text = hb_text.one_adult_chosen_in_accom_number; 171 } 172 option_text = $form.find( '.hb-accom-number option:selected' ).html() + ' ' + option_text; 173 if ( $form.find( '.hb-accom-number option[value="0"]' ).length ) { 174 $form.find( '.hb-accom-number option[value="0"]' ).html( option_text ); 175 $form.find( '.hb-accom-number' ).val( 0 ); 176 } 177 } 178 } 179 180 $( '.hb-booking-search-form' ).on( 'submit', function() { 181 var $form = $( this ), 182 $booking_wrapper = $form.parents( '.hbook-wrapper' );
183 $form.find( 'input[type="submit"]' ).blur(); 184 if ( ! $form.hasClass( 'submitted' ) ) { 185 $booking_wrapper.find( '.hb-booking-details-form' ).hide(); 186 $form.find( '.hb-search-error' ).slideUp(); 187 var check_in = $form.find( '.hb-check-in-date' ).val(), 188 check_out = $form.find( '.hb-check-out-date' ).val(), 189 adults = $form.find( 'select.hb-adults' ).val(), 190 children = $form.find( 'select.hb-children' ).val(), 191 admin_accom_id = '', 192 admin_search_type = '', 193 people_and_date_validation; 194 if ( $form.find( '.hb-admin-search-type' ).length ) { 195 admin_search_type = $form.find( '.hb-admin-search-type' ).val(); 196 } 197 if ( admin_search_type == 'single_accom' ) { 198 admin_accom_id = $form.find( '.hb-accom' ).val(); 199 } 200 if ( ! children || $form.hasClass( 'hb-search-form-no-children' ) ) { 201 $form.find( 'select.hb-children' ).val( 0 ); 202 children = 0; 203 } 204 if ( $form.hasClass( 'hb-search-form-no-people' ) ) { 205 $form.find( 'select.hb-adults' ).val( 1 ); 206 adults = 1; 207 } 208 if ( ! adults ) { 209 $form.find( 'select.hb-adults option:nth-child(2)' ).prop( 'selected', true ); 210 adults = $form.find( 'select.hb-adults' ).val(); 211 } 212 if ( $form.find( 'select.hb-accom-number option:selected' ).val() == -1 ) { 213 $form.find( 'select.hb-accom-number option:nth-child(3)' ).prop( 'selected', true ); 214 update_accom_people( $form ); 215 } 216 var booking_rules = $booking_wrapper.data( 'booking-rules' ); 217 people_and_date_validation = validate_people_and_check_dates( check_in, check_out, adults, children, booking_rules ); 218 if ( ! people_and_date_validation.success ) { 219 search_show_error( $form, people_and_date_validation.error_msg ); 220 } else { 221 disable_form_submission( $form ); 222 $form.find( '.hb-check-in-hidden' ).val( date_to_string( people_and_date_validation.check_in ) ); 223 $form.find( '.hb-check-out-hidden' ).val( date_to_string( people_and_date_validation.check_out ) ); 224 if ( $form.data( 'search-only' ) == 'yes' || $form.data( 'booking-details-redirection' ) == 'yes' ) { 225 return true; 226 } 227 $form.find( '.hb-search-no-result' ).slideUp(); 228 $form.find( '.hb-booking-searching' ).slideDown(); 229 var accom_people = ''; 230 if ( ( admin_search_type == 'multiple_accom' ) || $form.hasClass( 'hb-search-form-multiple-accom' ) ) { 231 accom_people = $form.find( '.hb-accom-people' ).val(); 232 if ( $form.find( '.hb-accom-people-any').val() == 'yes' ) { 233 accom_people = accom_people.split( '-' ); 234 adults = accom_people[0]; 235 children = accom_people[1]; 236 accom_people = ''; 237 } 238 } 239 $.ajax({ 240 url: hb_booking_form_data.ajax_url, 241 type: 'POST', 242 timeout: hb_booking_form_data.ajax_timeout, 243 data: { 244 'action': 'hb_get_available_accom', 245 'check_in': $form.find( '.hb-check-in-hidden' ).val(), 246 'check_out': $form.find( '.hb-check-out-hidden' ).val(), 247 'adults': adults, 248 'children': children, 249 'results_show_only_accom_id': $form.find( '.hb-results-show-only-accom-id' ).val(), 250 'page_accom_id': $booking_wrapper.data( 'page-accom-id' ), 251 'current_page_id': $booking_wrapper.data( 'current-page-id' ), 252 'exists_main_booking_form': $booking_wrapper.data( 'exists-main-booking-form' ), 253 'force_display_thumb': $booking_wrapper.data( 'force-display-thumb' ), 254 'force_display_desc': $booking_wrapper.data( 'force-display-desc' ), 255 'chosen_options': $form.find( '.hb-chosen-options' ).val(), 256 'chosen_accom_num': $form.find( '.hb-chosen-accom-num' ).val(), 257 'is_admin': hb_booking_form_data.is_admin, 258 'admin_accom_id': admin_accom_id, 259 'admin_search_type': admin_search_type, 260 'accom_people': accom_people 261 }, 262 success: function( response ) { 263 search_show_response( response, $form, $booking_wrapper ); 264 }, 265 error: function( jqXHR, textStatus, errorThrown ) { 266 $form.find( '.hb-booking-searching' ).hide(); 267 enable_form_submission( $form ); 268 search_show_error( $form, hb_text.connection_error ); 269 console.log( jqXHR ); 270 console.log( jqXHR.responseText ); 271 console.log( textStatus ); 272 console.log( errorThrown ); 273 } 274 }); 275 } 276 } 277 return false;
278 }); 279 280 function validate_people_and_check_dates( check_in, check_out, adults, children, booking_rules ) { 281 if ( ( check_in == '' ) && ( check_out == '' ) ) { 282 return { success: false, error_msg: hb_text.no_check_in_out_date }; 283 } else if ( check_in == '' ) { 284 return { success: false, error_msg: hb_text.no_check_in_date }; 285 } else if ( check_out == '' ) { 286 return { success: false, error_msg: hb_text.no_check_out_date }; 287 } else if ( adults != parseInt( adults, 10 ) && children != parseInt( children, 10 ) ) { 288 return { success: false, error_msg: hb_text.no_adults_children }; 289 } else if ( adults != parseInt( adults, 10 ) ) { 290 return { success: false, error_msg: hb_text.no_adults }; 291 } else if ( children != parseInt( children, 10 ) ) { 292 return { success: false, error_msg: hb_text.no_children }; 293 } 294 var check_in_date, 295 check_out_date; 296 try { 297 check_in_date = $.datepick.parseDate( hb_date_format, check_in ); 298 } catch( e ) { 299 check_in_date = false; 300 } 301 try { 302 check_out_date = $.datepick.parseDate( hb_date_format, check_out ); 303 } catch( e ) { 304 check_out_date = false; 305 } 306 if ( ! check_in_date && ! check_out_date ) { 307 return { success: false, error_msg: hb_text.invalid_check_in_out_date }; 308 } else if ( ! check_in_date ) { 309 return { success: false, error_msg: hb_text.invalid_check_in_date }; 310 } else if ( ! check_out_date ) { 311 return { success: false, error_msg: hb_text.invalid_check_out_date }; 312 } 313 314 if ( hb_booking_form_data.is_admin == 'yes' ) { 315 if ( check_out_date <= check_in_date ) { 316 return { success: false, error_msg: hb_text.check_out_before_check_in }; 317 } 318 return { success: true, check_in: check_in_date, check_out: check_out_date }; 319 } 320 321 if ( hb_min_date != '0' ) { 322 var min_date = hb_date_str_2_obj( hb_min_date ), 323 txt_min_date = $.datepick.formatDate( hb_date_format, min_date ); 324 if ( check_in_date < min_date ) { 325 return { success: false, error_msg: hb_text.check_in_date_before_date.replace( '%date', txt_min_date ) }; 326 } 327 } 328 if ( hb_max_date != '0' ) { 329 var max_date = hb_date_str_2_obj( hb_max_date ), 330 txt_max_date = $.datepick.formatDate( hb_date_format, max_date ); 331 max_date.setDate( max_date.getDate() + 1 ); 332 if ( check_out_date > max_date ) { 333 return { success: false, error_msg: hb_text.check_out_date_after_date.replace( '%date', txt_max_date ) }; 334 } 335 } 336 337 var yesterday = new Date(); 338 yesterday.setDate( yesterday.getDate() - 1 ); 339 yesterday.setHours( 23, 59, 59 ); 340 if ( check_in_date < yesterday ) { 341 return { success: false, error_msg: hb_text.check_in_date_past }; 342 } else if ( check_out_date <= check_in_date ) { 343 return { success: false, error_msg: hb_text.check_out_before_check_in }; 344 } 345 346 var check_in_day = day_of_week( check_in_date ), 347 check_out_day = day_of_week( check_out_date ), 348 nb_nights = date_diff( check_out_date, check_in_date ), 349 check_in_date_season = hb_get_season_id( check_in_date ), 350 check_out_date_season = hb_get_season_id( check_out_date ); 351 352 if ( booking_rules.allowed_check_in_days != 'all' ) { 353 var allowed_check_in_days = booking_rules.allowed_check_in_days.split( ',' ); 354 if ( allowed_check_in_days.indexOf( check_in_day ) < 0 ) { 355 var allowed_days = day_name_list( allowed_check_in_days ); 356 return { success: false, error_msg: hb_text.check_in_day_not_allowed.replace( '%check_in_days', allowed_days ) }; 357 } 358 } 359 if ( booking_rules.allowed_check_out_days != 'all' ) { 360 var allowed_check_out_days = booking_rules.allowed_check_out_days.split( ',' ); 361 if ( allowed_check_out_days.indexOf( check_out_day ) < 0 ) { 362 var allowed_days = day_name_list( allowed_check_out_days ); 363 return { success: false, error_msg: hb_text.check_out_day_not_allowed.replace( '%check_out_days', allowed_days ) }; 364 } 365 } 366 if ( 367 booking_rules.seasonal_allowed_check_in_days[ check_in_date_season ] && 368 booking_rules.seasonal_allowed_check_in_days[ check_in_date_season ].split( ',' ).indexOf( check_in_day ) < 0 369 ) { 370 return { success: false, error_msg: hb_text.check_in_day_not_allowed_seasonal }; 371 } 372 if ( 373 booking_rules.seasonal_allowed_check_out_days[ check_out_date_season ] && 374 booking_rules.seasonal_allowed_check_out_days[ check_out_date_season ].split( ',' ).indexOf( check_out_day ) < 0 375 ) { 376 return { success: false, error_msg: hb_text.check_out_day_not_allowed_seasonal }; 377 } 378 if ( booking_rules.seasonal_minimum_stay[ check_in_date_season ] ) { 379 if ( nb_nights < booking_rules.seasonal_minimum_stay[ check_in_date_season ] ) { 380 return { success: false, error_msg: hb_text.minimum_stay_seasonal }; 381 } 382 } else if ( nb_nights < booking_rules.minimum_stay ) { 383 return { success: false, error_msg: hb_text.minimum_stay.replace( '%nb_nights', booking_rules.minimum_stay ) }; 384 } 385 if ( booking_rules.seasonal_maximum_stay[ check_in_date_season ] ) { 386 if ( nb_nights > booking_rules.seasonal_maximum_stay[ check_in_date_season ] ) { 387 return { success: false, error_msg: hb_text.maximum_stay_seasonal }; 388 } 389 } else if ( nb_nights > booking_rules.maximum_stay ) { 390 return { success: false, error_msg: hb_text.maximum_stay.replace( '%nb_nights', booking_rules.maximum_stay ) }; 391 } 392 if ( booking_rules.conditional_booking_rules.length ) { 393 for ( var i = 0; i < booking_rules.conditional_booking_rules.length; i++ ) { 394 var rule = booking_rules.conditional_booking_rules[ i ]; 395 if ( rule.check_in_days.indexOf( check_in_day ) > -1 ) { 396 if ( rule.check_out_days.indexOf( check_out_day ) < 0 ) { 397 if ( rule['all_seasons'] == 1 ) { 398 return { 399 success: false, 400 error_msg: hb_text.check_out_day_not_allowed_for_check_in_day 401 .replace( '%check_in_day', day_name( check_in_day ) ) 402 .replace( '%check_out_days', day_name_list( rule.check_out_days.split( ',' ) ) ) 403 }; 404 }
404 else if ( rule['seasons'].split( ',' ).indexOf( check_in_date_season ) > -1 ) { 405 return { success: false, error_msg: hb_text.check_out_day_not_allowed_for_check_in_day_seasonal }; 406 } 407 } 408 if ( nb_nights < rule.minimum_stay ) { 409 if ( rule['all_seasons'] == 1 ) { 410 return { 411 success: false, 412 error_msg: hb_text.minimum_stay_for_check_in_day 413 .replace( '%nb_nights', rule.minimum_stay ) 414 .replace( '%check_in_day', day_name( check_in_day ) ) 415 }; 416 } else if ( rule['seasons'].split( ',' ).indexOf( check_in_date_season ) > -1 ) { 417 return { success: false, error_msg: hb_text.minimum_stay_for_check_in_day_seasonal }; 418 } 419 } 420 if ( nb_nights > rule.maximum_stay ) { 421 if ( rule['all_seasons'] == 1 ) { 422 return { 423 success: false, 424 error_msg: hb_text.maximum_stay_for_check_in_day 425 .replace( '%nb_nights', rule.maximum_stay ) 426 .replace( '%check_in_day', day_name( check_in_day ) ) 427 }; 428 } else if ( rule['
428seasons'].split( ',' ).indexOf( check_in_date_season ) > -1 ) { 429 return { success: false, error_msg: hb_text.maximum_stay_for_check_in_day_seasonal }; 430 } 431 } 432 } 433 } 434 } 435 return { success: true, check_in: check_in_date, check_out: check_out_date }; 436 } 437 438 function day_of_week( date ) { 439 var day = date.getDay(); 440 if ( day == 0 ) { 441 day = 6; 442 } else { 443 day = day - 1; 444 } 445 return day + ''; 446 } 447 448 function day_name( day ) { 449 if ( day == 6 ) { 450 day = 0; 451 } else { 452 day++; 453 } 454 return hb_day_names[ day ]; 455 } 456 457 function day_name_list( days ) { 458 var days_name = []; 459 for ( var i = 0; i < days.length; i++ ) { 460 days_name.push( day_name( days[ i ] ) ); 461 } 462 return days_name.join( ', ' ); 463 } 464 465 function date_diff( check_out_date, check_in_date ) { 466 return Math.round( ( check_out_date - check_in_date ) / 1000 / 60 / 60 / 24 ); 467 } 468 469 function date_to_string( date ) { 470 var y = date.getFullYear(); 471 var m = date.getMonth() + 1; 472 m = m + ''; 473 if ( m.length == 1 ) { 474 m = '0' + m; 475 } 476 var d = date.getDate(); 477 d = d + ''; 478 if ( d.length == 1 ) { 479 d = '0' + d; 480 } 481 return y + '-' + m + '-' + d; 482 } 483 484 function search_show_error( $form, msg ) { 485 if ( $form.find( '.hb-search-error' ).is( ':visible' ) ) { 486 $form.find( '.hb-search-error' ).slideUp( function() { 487 $( this ).html( msg ).slideDown(); 488 }); 489 } else { 490 $form.find( '.hb-search-error' ).html( msg ).slideDown(); 491 } 492 } 493 494 function search_show_response( response_text, $form, $booking_wrapper ) { 495 $form.find( '.hb-booking-searching' ).hide(); 496 enable_form_submission( $form ); 497 try { 498 var response = JSON.parse( response_text ); 499 } catch ( e ) { 500 $form.find( '.hb-search-error' ).html( 'An error occured. ' + response_text ).slideDown(); 501 return false; 502 } 503 if ( ! response.success ) { 504 if ( response.msg ) { 505 $form.find( '.hb-search-no-result' ).html( response.msg ).slideDown(); 506 } else { 507 $form.find( '.hb-search-error' ).html( response_text ).slideDown(); 508 } 509 } else { 510 $form.find( '.hb-chosen-check-in-date span' ).html( $form.find( '.hb-check-in-date' ).val() ); 511 $form.find( '.hb-chosen-check-out-date span' ).html( $form.find( '.hb-check-out-date' ).val() ); 512 $form.find( '.hb-chosen-accom-number span' ).html( $form.find( '.hb-accom-number option:selected' ).html() ); 513 $form.find( '.hb-chosen-admin-search-type span' ).html( $form.find( '.hb-admin-search-type option:selected' ).html() ); 514 $form.find( '.hb-chosen-adults span' ).html( $form.find( 'select.hb-adults' ).val() ); 515 $form.find( '.hb-chosen-children span' ).html( $form.find( 'select.hb-children' ).val() ); 516 $form.find( '.hb-chosen-accom span' ).html( $form.find( '.hb-accom option:selected' ).text() ); 517 $form.find( '.hb-search-fields-and-submit' ).slideUp( function() {}); 518 $form.find( '.hb-searched-summary' ).slideDown(); 519 $booking_wrapper.find( '.hb-accom-list' ).html( response.mark_up ); 520 var is_accom_selected = false; 521 if ( ( $form.find( '.hb-accom' ).length ) && ( $form.find( '.hb-accom' ).val() != 'all' ) ) { 522 set_selected_accom( $booking_wrapper, $form.find( '.hb-accom' ).val() ); 523 is_accom_selected = true; 524 } 525 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 526 if ( $( this ).find( '.hb-accom' ).length == 1 ) { 527 set_selected_accom( $( this ), $( this ).find( '.hb-accom' ).data( 'accom-id' ) ); 528 is_accom_selected = true; 529 } 530 }); 531 if ( ! is_accom_selected && ( $booking_wrapper.find( '.hb-multi-accom-choices' ).length == 1 ) ) { 532 $booking_wrapper.find( '.hb-next-step-1' ).hide(); 533 } 534 if ( $booking_wrapper.attr( 'data-results-show-only-accom-id' ) != '' ) { 535 var accom_ids = $booking_wrapper.attr( 'data-results-show-only-accom-id' ).split( ',' ); 536 $booking_wrapper.find( '.hb-accom' ).hide(); 537 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function( multi_accom_choices_index ) { 538 $booking_wrapper.find( '.hb-accom-id-' + accom_ids[ multi_accom_choices_index ] ).show(); 539 set_selected_accom( $( this ), accom_ids[ multi_accom_choices_index ] ); 540 }); 541 next_step_1( $booking_wrapper ); 542 } 543 accom_left( $booking_wrapper ); 544 $booking_wrapper.find( '.hb-accom-list' ).slideDown(); 545 if ( typeof window['hbook_show_accom_list'] == 'function' ) { 546 window['hbook_show_accom_list'](); 547 } 548 hb_format_date(); 549 resize_price_caption(); 550 } 551 } 552 553 function change_search( $booking_wrapper, show_accom_number ) { 554 $booking_wrapper.data( 'results-show-only-accom-id', '' ); 555 $booking_wrapper.find( '.hb-chosen-options' ).val( '' ); 556 $booking_wrapper.find( '.hb-chosen-accom-num' ).val( '' );
557 $booking_wrapper.find( '.hb-accom-list' ).slideUp(); 558 $booking_wrapper.find( '.hb-booking-details-form' ).slideUp(); 559 $booking_wrapper.find( '.hb-coupon-code' ).val( '' ); 560 $booking_wrapper.find( '.hb-pre-validated-coupon-id' ).val( '' ); 561 $booking_wrapper.find( '.hb-coupon-amount' ).html( '0' ); 562 $booking_wrapper.find( '.hb-coupon-msg, .hb-coupon-error' ).slideUp(); 563 $( '#hb-global-discount-amount' ).val( 0 ); 564 $( '#hb-global-discount-amount-type-fixed' ).prop( 'checked', true ); 565 $booking_wrapper.find( '.hb-searched-summary' ).slideUp( function() { 566 if ( show_accom_number ) { 567 $booking_wrapper.find( '.hb-booking-search-form' ).addClass( 'hb-search-form-multiple-accom' ); 568 } 569 $booking_wrapper.find( '.hb-search-fields-and-submit' ).slideDown(); 570 }); 571 } 572 573 $( '.hb-change-search-wrapper input' ).on( 'click', function( e ) { 574 e.preventDefault(); 575 change_search( $( this ).parents( '.hbook-wrapper' ), false ); 576 }); 577 578 $( '.hbook-wrapper' ).on( 'click', '.hb-search-specific-accom-number a', function( e ) { 579 e.preventDefault(); 580 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 581 var $search_form = $booking_wrapper.find( '.hb-booking-search-form' ); 582 if ( ! $search_form.hasClass('hb-search-form-multiple-accom') ) { 583 var adults = $search_form.find( '.hb-adults' ).val(); 584 var children = $search_form.find( '.hb-children' ).val(); 585 var accom_adults = []; 586 var accom_children = []; 587 for ( var i = 0; i < 2; i++ ) { 588 accom_adults[ i ] = Math.floor( adults / 2 ); 589 accom_children[ i ] = Math.floor( children / 2 ); 590 } 591 accom_adults[0] += adults % 2; 592 accom_children[0] += children % 2; 593 $search_form.find( '.hb-accom-number' ).val( 2 ); 594 for ( var i = 1; i <= 2; i++ ) { 595 $search_form.find( '.hb-multi-accom-people-selection-accom-' + i + ' .hb-multi-accom-adults' ).val( accom_adults[ i - 1 ] ); 596 $search_form.find( '.hb-multi-accom-people-selection-accom-' + i + ' .hb-multi-accom-children' ).val( accom_children[ i - 1 ] ); 597 } 598 update_accom_people( $search_form ); 599 } 600 change_search( $booking_wrapper, true ); 601 }); 602 603 $( '.hbook-wrapper' ).on( 'click', '.hb-other-search', function() { 604 var $form = $( this ).parents( '.hb-booking-search-form' ); 605 $form.data( 'search-only', 'yes' ); 606 $form.submit(); 607 return false; 608 }); 609 610 /* end booking search */ 611 612 /* ------------------------------------------------------------------------------------------- */ 613 614 /* accom selection */ 615 616 $( '.hb-accom-list' ).on( 'click', '.hb-view-price-breakdown', function() { 617 var $self = $( this ); 618 $self.blur(); 619 $self.parents( '.hb-accom' ).find( '.hb-price-breakdown' ).slideToggle( function() { 620 if ( $( this ).is( ':visible' ) ) { 621 $self.find( '.hb-price-bd-hide-text' ).show(); 622 $self.find( '.hb-price-bd-show-text' ).hide(); 623 } else { 624 $self.find( '.hb-price-bd-hide-text' ).hide(); 625 $self.find( '.hb-price-bd-show-text' ).show(); 626 } 627 }); 628 return false; 629 }); 630 631 $( '.hb-accom-list' ).on( 'click', '.hb-view-accom input', function( e ) { 632 e.preventDefault(); 633 $( this ).blur(); 634 window.open( $( this ).data( 'accom-url' ), '_blank' ); 635 }); 636 637 $( '.hb-accom-list' ).on( 'click', '.hb-select-accom input', function( e ) { 638 e.preventDefault(); 639 $( this ).blur(); 640 641 var accom_id = $( this ).parents( '.hb-accom' ).data( 'accom-id' ); 642 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 643 var $current_accom_choices = $( this ).parents( '.hb-multi-accom-choices' ); 644 var $all_accom_choices = $booking_wrapper.find( '.hb-multi-accom-choices' ); 645 var clicked_nb = $all_accom_choices.index( $current_accom_choices ); 646 var clicked_last = ( clicked_nb == $all_accom_choices.length - 1 ); 647 648 $( '.hb-multi-accom-no-accom-selected' ).hide(); 649 set_selected_accom( $current_accom_choices, accom_id ); 650 accom_left( $booking_wrapper ); 651 if ( $booking_wrapper.find( '.hb-accom-selected' ).length < $booking_wrapper.find( '.hb-multi-accom-choices' ).length ) { 652 setTimeout( function() { 653 select_next_accom_scroll( $booking_wrapper ); 654 }, 800 ); 655 } else if ( 656 clicked_last || 657 ( 658 ( $booking_wrapper.find( '.hb-multi-accom-choices' ).length == 1 ) && 659 ( $booking_wrapper.find( '.hb-multi-accom-choices .hb-accom' ).length > 1 ) 660 ) 661 ) { 662 next_step_1( $booking_wrapper ); 663 } 664 }); 665 666 function set_selected_accom( $accom_choices, accom_id ) { 667 $accom_choices.find( '.hb-accom' ).removeClass( 'hb-accom-selected' ); 668 $accom_choices.find( '.hb-accom-id-' + accom_id ).addClass( 'hb-accom-selected' ); 669 } 670 671 function select_next_accom_scroll( $booking_wrapper ) { 672 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 673 var $hb_multi_accom_choices = $( this ); 674 if ( ! $hb_multi_accom_choices.find( '.hb-accom-selected' ).length ) { 675 var top = $hb_multi_accom_choices.offset().top - page_padding_top; 676 var show_select_accom_msg = false;
677 if ( $( window ).scrollTop() > top ) { 678 show_select_accom_msg = true; 679 } 680 $( 'html, body' ).animate({ scrollTop: top }, function() { 681 if ( show_select_accom_msg ) { 682 $hb_multi_accom_choices.find( '.hb-multi-accom-no-accom-selected' ).slideDown(); 683 } 684 }); 685 return false; 686 } 687 }); 688 } 689 690 function accom_left( $booking_wrapper ) { 691 var selected_accom_ids = []; 692 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 693 if ( $( this ).find( '.hb-accom-selected' ).length ) { 694 selected_accom_ids.push( $( this ).find( '.hb-accom-selected' ).data( 'accom-id' ) ); 695 } 696 }); 697 $( '.hb-accom-none-left' ).removeClass( 'hb-accom-none-left' ); 698 $booking_wrapper.find( '.hb-accom-quantity' ).each( function() { 699 var accom_id = $( this ).data( 'accom-id' ); 700 var $accom = $booking_wrapper.find( '.hb-accom.hb-accom-id-' + accom_id ); 701 $accom.each( function() { 702 if ( $( this ).hasClass( 'hb-accom-selected' ) ) { 703 $( this ).find( '.hb-accom-selected-left-wrapper' ).show(); 704 } else { 705 $( this ).find( '.hb-accom-selected-left-wrapper' ).hide(); 706 } 707 }); 708 var nb_selected = 0; 709 for ( var i = 0; i < selected_accom_ids.length; i++ ) { 710 if ( selected_accom_ids[ i ] == accom_id ) { 711 nb_selected++; 712 } 713 } 714 $accom.find( '.hb-nb-accom-selected-nb' ).html( nb_selected ); 715 var updated_quantity = $( this ).data( 'quantity' ) - nb_selected; 716 $accom.find( '.hb-accom-left, .hb-nb-accom-selected' ).hide(); 717 if ( updated_quantity == 0 ) { 718 $accom.each( function() { 719 $( this ).addClass( 'hb-accom-none-left' ); 720 if ( ! $( this ).hasClass( 'hb-accom-selected' ) ) { 721 $( this ).find( '.hb-nb-accom-selected, .hb-no-accom-left, .hb-accom-selected-left-wrapper' ).show(); 722 } 723 }); 724 } else if ( ( hb_booking_form_data.is_admin != 'yes' ) && ( updated_quantity <= hb_booking_form_data.display_accom_left_threshold ) ) { 725 $accom.find( '.hb-accom-selected-left-wrapper' ).show(); 726 if ( updated_quantity == 1 ) { 727 $accom.find( '.hb-one-accom-left' ).show(); 728 } else { 729 $accom.find( '.hb-multiple-accom-left' ).show(); 730 $accom.find( '.hb-accom-left-nb' ).html( updated_quantity ); 731 } 732 } 733 }); 734 } 735 736 /* end accom selection */ 737 738 /* ------------------------------------------------------------------------------------------- */ 739 740 /* steps */ 741 742 function init_step( $booking_wrapper ) { 743 var top = $booking_wrapper.find( '.hb-accom-list' ).offset().top; 744 if ( top ) { 745 top -= page_padding_top; 746 $( 'html, body' ).animate({ scrollTop: top }, function() { 747 $booking_wrapper.find( '.hb-step-wrapper' ).slideUp(); 748 }); 749 } else { 750 $booking_wrapper.find( '.hb-step-wrapper' ).hide(); 751 } 752 } 753 754 $( '.hb-accom-list' ).on( 'click', '.hb-next-step-1 input', function() { 755 $( this ).blur(); 756 next_step_1( $( this ).parents( '.hbook-wrapper' ) ); 757 }); 758 759 function next_step_1( $booking_wrapper ) { 760 var $form = $booking_wrapper.find( '.hb-booking-search-form' ); 761 if ( $form.attr( 'action' ) != '#' ) { 762 $form.data( 'booking-details-redirection', 'yes' ); 763 var accom_ids = []; 764 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 765 accom_ids.push( $( this ).find( '.hb-accom-selected' ).data( 'accom-id' ) ); 766 }); 767 $form.find( '.hb-results-show-only-accom-id' ).val( accom_ids.join( ',' ) ); 768 $form.submit(); 769 return; 770 } 771 772 if ( $booking_wrapper.find( '.hb-accom-selected' ).length < $booking_wrapper.find( '.hb-multi-accom-choices' ).length ) { 773 if ( $booking_wrapper.find( '.hb-multi-accom-choices' ).length == 1 ) { 774 var top = $booking_wrapper.find( '.hb-search-result-title-section .hb-title-select' ).offset().top; 775 top -= page_padding_top; 776 $( 'html, body' ).animate({ scrollTop: top }); 777 return; 778 } else { 779 select_next_accom_scroll( $booking_wrapper ); 780 } 781 return; 782 } 783 $booking_wrapper.find( '.hb-filter-accom-list-wrapper' ).slideUp(); 784 init_step( $booking_wrapper ); 785 786 $booking_wrapper.find( '.hb-coupon-code' ).val( '' ); 787 $booking_wrapper.find( '.hb-coupon-amount' ).html( '0' ); 788 789 calculate_options_price( $booking_wrapper ); 790 791 var accom_ids = []; 792 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 793 accom_ids.push( $( this ).find( '.hb-accom-selected' ).data( 'accom-id' ) ); 794 }); 795 set_details_form_info( $booking_wrapper, accom_ids.join( '-' ) ); 796 toggle_accom_not_available_msg( $booking_wrapper, accom_ids[0] ); 797 $booking_wrapper.find( '.hb-policies-error, .hb-confirm-error, .hb-option, .hb-options-form, .hb-select-accom-num, .hb-booking-details-form, .hb-summary-wrapper' ).hide(); 798 show_hide_country_iso_info( $booking_wrapper ); 799 800 var show_intermediate_step = false;
801 if ( $booking_wrapper.find( '.hb-select-accom-num-form' ).length ) { 802 var has_multiple_num_choice = false; 803 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 804 var select_wrapper_class = '.hb-select-multi-accom-num-accom-' + i + ' .hb-select-accom-num-accom-' + accom_ids[ i - 1 ]; 805 if ( $( select_wrapper_class ).find( 'option' ).length > 2 ) { 806 has_multiple_num_choice = true; 807 } 808 $booking_wrapper.find( select_wrapper_class ).show(); 809 } 810 if ( has_multiple_num_choice ) { 811 $booking_wrapper.find( '.hb-select-accom-num-form' ).show(); 812 show_intermediate_step = true; 813 } else { 814 $booking_wrapper.find( '.hb-select-accom-num-form' ).hide(); 815 $booking_wrapper.find( '.hb-select-accom-num-form option:nth-child(2)' ).prop( 'selected', true ); 816 } 817 } 818 819 var show_options_form = false; 820 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 821 var option_class = '.hb-options-multi-accom-' + i + ' .hb-option-accom-' + accom_ids[ i - 1 ]; 822 if ( $booking_wrapper.find( option_class ).length ) { 823 show_options_form = true; 824 show_intermediate_step = true; 825 $booking_wrapper.find( option_class ).show(); 826 $booking_wrapper.find( '.hb-options-multi-accom-' + i + ' .hb-options-gap' ).show(); 827 } else { 828 $booking_wrapper.find( '.hb-options-multi-accom-' + i + ' .hb-no-options' ).show(); 829 $booking_wrapper.find( '.hb-options-multi-accom-' + i + ' .hb-options-gap' ).hide(); 830 } 831 } 832 if ( $booking_wrapper.find( '.hb-options-multi-accom-global' ).length ) { 833 $booking_wrapper.find( '.hb-options-multi-accom-global .hb-option' ).show(); 834 show_options_form = true; 835 show_intermediate_step = true; 836 } 837 if ( show_options_form ) { 838 $booking_wrapper.find( '.hb-options-form' ).show(); 839 } else { 840 $booking_wrapper.find( '.hb-options-form' ).hide(); 841 } 842 843 if ( show_intermediate_step ) { 844 $booking_wrapper.addClass( 'has-intermediate-step' ); 845 setTimeout( function( ) { 846 $booking_wrapper.find( '.hb-intermediate-step-wrapper' ).slideDown( function() { 847 scroll_to_accom_list_top( $booking_wrapper ); 848 }); 849 }, 800 ); 850 } else { 851 $booking_wrapper.removeClass( 'has-intermediate-step' ); 852 set_summary( $booking_wrapper ); 853 setTimeout( function( ) { 854 $booking_wrapper.find( '.hb-booking-details-form' ).slideDown( function() { 855 resize_forms(); 856 scroll_to_accom_list_top( $booking_wrapper ); 857 }); 858 }, 800 ); 859 } 860 861 return false; 862 } 863 864 $( '.hb-accom-list' ).on( 'click', '.hb-next-step-2 input', function() { 865 $( this ).blur(); 866 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 867 init_step( $booking_wrapper ); 868 if ( $booking_wrapper.find( '.hb-select-accom-num-form' ).length ) { 869 var accom_ids = $booking_wrapper.find( '.hb-details-accom-ids' ).val().split( '-' ); 870 var selected_accom_nums = {}; 871 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 872 selected_accom_nums[ accom_ids[ i - 1 ] ] = []; 873 } 874 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 875 var $select_num_wrapper = $booking_wrapper.find( '.hb-select-multi-accom-num-accom-' + i + ' .hb-select-accom-num-accom-' + accom_ids[ i - 1 ] ); 876 var selected_num = $select_num_wrapper.find( 'select' ).val(); 877 if ( selected_num != 0 ) { 878 selected_accom_nums[ accom_ids[ i - 1 ] ].push( selected_num ); 879 } 880 } 881 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 882 var $select_num_wrapper = $booking_wrapper.find( '.hb-select-multi-accom-num-accom-' + i + ' .hb-select-accom-num-accom-' + accom_ids[ i - 1 ] ); 883 var selected_num = $select_num_wrapper.find( 'select' ).val(); 884 if ( selected_num == 0 ) { 885 for ( var j = 2; j <= $select_num_wrapper.find( 'option' ).length; j++ ) { 886 var $option_num = $select_num_wrapper.find( 'option:nth-child(' + j + ')' ); 887 var candidate_num = $option_num.val(); 888 if ( selected_accom_nums[ accom_ids[ i - 1 ] ].indexOf( candidate_num ) < 0 ) { 889 $option_num.prop( 'selected', true ); 890 selected_accom_nums[ accom_ids[ i - 1 ] ].push( candidate_num ); 891 break; 892 } 893 } 894 } 895 } 896 } 897 set_summary( $booking_wrapper ); 898 setTimeout( function() { 899 $booking_wrapper.find( '.hb-booking-details-form' ).slideDown( function() { 900 resize_forms(); 901 var top = $booking_wrapper.find( '.hb-booking-details-form' ).offset().top - page_padding_top; 902 $( 'html, body' ).animate({ scrollTop: top }); 903 }); 904 }, 800 ); 905 return false;
906 }); 907 908 $( '.hb-accom-list' ).on( 'click', '.hb-previous-step-1 input', function() { 909 $( this ).blur(); 910 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 911 $booking_wrapper.find( '.hb-next-step-1' ).show(); 912 init_step( $booking_wrapper ); 913 setTimeout( function() { 914 $booking_wrapper.find( '.hb-accom-step-wrapper, .hb-filter-accom-list-wrapper' ).slideDown( function() { 915 scroll_to_accom_list_top( $booking_wrapper ); 916 }); 917 }, 800 ); 918 return false; 919 }); 920 921 $( '.hb-previous-step-2 input' ).on( 'click', function() { 922 $( this ).blur(); 923 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 924 init_step( $booking_wrapper ); 925 setTimeout( function() { 926 if ( $booking_wrapper.hasClass( 'has-intermediate-step' ) ) { 927 $booking_wrapper.find( '.hb-intermediate-step-wrapper' ).slideDown( function() { 928 scroll_to_accom_list_top( $booking_wrapper ); 929 }); 930 } else { 931 $booking_wrapper.find( '.hb-accom-step-wrapper' ).slideDown( function() { 932 scroll_to_accom_list_top( $booking_wrapper ); 933 }); 934 $booking_wrapper.find( '.hb-next-step-1' ).show(); 935 } 936 }, 800 ); 937 return false; 938 }); 939 940 function scroll_to_accom_list_top( $booking_wrapper ) { 941 var top = $booking_wrapper.find( '.hb-accom-list' ).offset().top - page_padding_top; 942 $( 'html, body' ).animate({ scrollTop: top }); 943 } 944 945 /* end steps */ 946 947 /* ------------------------------------------------------------------------------------------- */ 948 949 /* accom num selection */ 950 951 $( '.hb-accom-list' ).on( 'change', '.hb-select-accom-num-form select', function() { 952 var accom_id = $( this ).data( 'accom-id' ); 953 var select_id = $( this ).attr( 'id' ); 954 var select_val = $( this ).val(); 955 $( this ).parents( '.hb-select-accom-num-form' ).find( '.hb-select-accom-num-accom-' + accom_id + ' select' ).each( function() { 956 if ( 957 ( $( this ).attr( 'id' ) != select_id ) && 958 ( $( this ).val() == select_val ) 959 ) { 960 $( this ).val( '0' ).focus(); 961 } 962 }); 963 }); 964 965 /* end accom num selection */ 966 967 /* ------------------------------------------------------------------------------------------- */ 968 969 /* options selection */ 970 971 $( '.hb-accom-list' ).on( 'click', '.hb-option', function() { 972 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 973 verify_option_max( $booking_wrapper ); 974 calculate_options_price( $booking_wrapper ); 975 }); 976 977 $( '.hb-accom-list' ).on( 'keyup', '.hb-option input', function() { 978 var $booking_wrapper = $( this ).parents( '.hbook-wrapper' ); 979 verify_option_max( $booking_wrapper ); 980 calculate_options_price( $booking_wrapper ); 981 }); 982 983 function verify_option_max( $booking_wrapper ) { 984 $booking_wrapper.find( '.hb-option' ).each( function() { 985 if ( $( this ).hasClass( 'hb-quantity-option' ) && $( this ).find( 'input' ).attr( 'max' ) ) { 986 if ( parseInt( $( this ).find( 'input' ).val() ) > parseInt( $( this ).find( 'input' ).attr( 'max' ) ) ) { 987 $( this ).find( 'input' ).val( $( this ).find( 'input' ).attr( 'max' ) ); 988 } 989 } 990 }); 991 } 992 993 function calculate_options_price( $booking_wrapper ) { 994 var options_price = 0; 995 var accom_ids = []; 996 997 $booking_wrapper.find( '.hb-multi-accom-choices' ).each( function() { 998 accom_ids.push( $( this ).find( '.hb-accom-selected' ).data( 'accom-id' ) ); 999 }); 1000 accom_ids.push( 'global' ); 1001 1002 for ( var i = 1; i < accom_ids.length + 1; i++ ) { 1003 var $options_wrapper = $booking_wrapper.find( '.hb-options-multi-accom-' + i ); 1004 if ( accom_ids[ i - 1 ] == 'global' ) { 1005 $options_wrapper = $booking_wrapper.find( '.hb-options-multi-accom-global' ); 1006 } 1007 $options_wrapper.find( '.hb-option' ).each( function() { 1008 if ( 1009 $( this ).hasClass( 'hb-option-accom-' + accom_ids[ i - 1 ] ) || 1010 $( this ).hasClass( 'hb-option-global' ) 1011 ) { 1012 if ( $( this ).hasClass( 'hb-quantity-option' ) ) { 1013 if ( $( this ).find( 'input' ).val() < 0 ) { 1014 $( this ).find( 'input' ).val( 0 ); 1015 } 1016 options_price += parseFloat( $( this ).find( 'input' ).data( 'price' ) * $( this ).find( 'input' ).val() ); 1017 } else if ( $( this ).hasClass( 'hb-multiple-option' ) && $( this ).find( 'input:checked' ).length ) { 1018 options_price += parseFloat( $( this ).find( 'input:checked' ).data( 'price' ) ); 1019 } else if ( $( this ).hasClass( 'hb-single-option' ) && $( this ).find( 'input' ).is(':checked' ) ) { 1020 options_price += parseFloat( $( this ).find( 'input' ).data( 'price' ) ); 1021 } 1022 } 1023 }); 1024 } 1025 1026 if ( options_price != 0 ) { 1027 options_price = format_price( options_price ); 1028 if ( options_price < 0 ) { 1029 options_price = format_price( options_price * -1 ); 1030 $booking_wrapper.find( '.hb-options-total-price .hb-price-placeholder-minus' ).css( 'display', 'inline' ); 1031 } else { 1032 $booking_wrapper.find( '.hb-options-total-price .hb-price-placeholder-minus' ).css( 'display', 'none' ); 1033 } 1034 $booking_wrapper.find( '.hb-options-total-price .hb-price-placeholder' ).html( options_price ); 1035 $booking_wrapper.find( '.hb-options-total-price' ).show(); 1036 } else { 1037 $booking_wrapper.find( '.hb-options-total-price' ).hide(); 1038 } 1039 1040 } 1041 1042 /* end options selection */ 1043 1044 /* ------------------------------------------------------------------------------------------- */ 1045 1046 /* coupons */ 1047 1048 $( '.hb-apply-coupon' ).on( 'click', function() { 1049 var $form = $( this ).parents( '.hb-booking-details-form' );
1050 $form.find( '.hb-coupon-error, .hb-coupon-msg' ).slideUp(); 1051 if ( ! $form.find( '.hb-coupon-code' ).val() ) { 1052 $form.find( '.hb-coupon-msg' ).html( hb_text.no_coupon ).slideDown(); 1053 $form.find( '.hb-pre-validated-coupon-id' ).val( '' ); 1054 set_summary( $form.parents( '.hbook-wrapper' ) ); 1055 return false; 1056 } 1057 $( this ).prop( 'disabled', true ).blur(); 1058 $form.find( '.hb-processing-coupon' ).show(); 1059 $.ajax({ 1060 data: { 1061 'action': 'hb_verify_coupon', 1062 'check_in': $form.find( '.hb-details-check-in' ).val(), 1063 'check_out': $form.find( '.hb-details-check-out' ).val(), 1064 'accom_ids': $form.find( '.hb-details-accom-ids' ).val(), 1065 'coupon_code': $form.find( '.hb-coupon-code' ).val(), 1066 }, 1067 success: function( response ) { 1068 coupon_verify_result( response, $form ); 1069 }, 1070 type : 'POST', 1071 timeout: hb_booking_form_data.ajax_timeout, 1072 url: hb_booking_form_data.ajax_url, 1073 error: function( jqXHR, textStatus, errorThrown ) { 1074 $form.find( '.hb-processing-coupon' ).hide(); 1075 $form.find( '.hb-coupon-error' ).html( hb_text.connection_error ).slideDown(); 1076 $form.find( '.hb-apply-coupon' ).prop( 'disabled', false ); 1077 console.log( jqXHR ); 1078 console.log( textStatus ); 1079 console.log( errorThrown ); 1080 } 1081 }); 1082 return false; 1083 }); 1084 1085 function coupon_verify_result( response_text, $form ) { 1086 $form.find( '.hb-apply-coupon' ).prop( 'disabled', false ); 1087 $form.find( '.hb-processing-coupon' ).hide(); 1088 try { 1089 var response = JSON.parse( response_text ); 1090 } catch ( e ) { 1091 $form.find( '.hb-coupon-error' ).html( 'An error occured. ' + response_text ).slideDown(); 1092 return false; 1093 } 1094 if ( response['success'] ) { 1095 $form.find( '.hb-pre-validated-coupon-id' ).val( response['coupon_id'] ); 1096 } else { 1097 $form.find( '.hb-pre-validated-coupon-id' ).val( '' ); 1098 } 1099 $form.find( '.hb-coupon-msg' ).html( response['msg'] ).slideDown(); 1100 set_summary( $form.parents( '.hbook-wrapper' ) ); 1101 } 1102 1103 /* end coupons */ 1104 1105 /* ------------------------------------------------------------------------------------------- */ 1106 1107 /* admin global discount */ 1108 1109 $( '#hb-global-discount-amount, input[name="hb-global-discount-amount-type"]' ).on( 'change', function() { 1110 summary_on_discount_change(); 1111 }); 1112 1113 $( '#hb-global-discount-amount' ).on( 'keyup', function() { 1114 summary_on_discount_change(); 1115 }); 1116 1117 var summary_reload_timer; 1118 1119 function summary_on_discount_change() { 1120 var $booking_wrapper = $( '.hbook-wrapper' ); 1121 $booking_wrapper.find( '.hb-summary-wrapper' ).hide(); 1122 $booking_wrapper.find( '.hb-loading-summary' ).show(); 1123 clearTimeout( summary_reload_timer ); 1124 summary_reload_timer = setTimeout( function() { 1125 set_summary_on_discount_change( $booking_wrapper ); 1126 }, 500 ); 1127 } 1128 1129 /* end admin global discount */ 1130 1131 /* ------------------------------------------------------------------------------------------- */ 1132 1133 /* update payment info */ 1134 1135 function update_payment_info( $booking_wrapper ) { 1136 var $payment_data = $booking_wrapper.find( '.hb-payment-data-summary' ); 1137 if ( $payment_data.data( 'null-price' ) == 'yes' ) { 1138 $booking_wrapper.find( '.hb-payment-info-wrapper' ).hide(); 1139 $booking_wrapper.find( 'input.hb-payment-type-null-price' ).prop( 'checked', true ); 1140 } else { 1141 var charged_total_price = $payment_data.data( 'charged-total-price' ); 1142 var charged_deposit = $payment_data.data( 'charged-deposit' ); 1143 var charged_total_minus_deposit = $payment_data.data( 'charged-total-minus-deposit' ); 1144 $booking_wrapper.find( '.hb-payment-info-wrapper' ).show(); 1145 $booking_wrapper.find( '.hb-payment-type-explanation-full_amount' ).html( charged_total_price ); 1146 $booking_wrapper.find( '.hb-payment-type-explanation-deposit_amount' ).html( charged_deposit ); 1147 $booking_wrapper.find( '.hb-payment-type-explanation-full_minus_deposit_amount' ).html( charged_total_minus_deposit ); 1148 if ( 1149 ( charged_total_price == charged_deposit ) && 1150 ( $booking_wrapper.find( '.hb-payment-type-deposit-wrapper, .hb-payment-type-full-wrapper' ).length == 2 ) 1151 ) { 1152 $booking_wrapper.find( '.hb-payment-type-deposit-wrapper' ).hide();
1153 if ( $booking_wrapper.find( 'input[name="hb-payment-type"]:checked' ).val() == 'deposit' ) { 1154 $booking_wrapper.find( 'input[name="hb-payment-type"]' ).each( function() { 1155 if ( $( this ).val() != 'deposit' ) { 1156 $( this ).prop( 'checked', true ); 1157 return false; 1158 } 1159 }); 1160 } 1161 if ( $booking_wrapper.find( '.hb-payment-type-wrapper' ).length == 2 ) { 1162 $booking_wrapper.find( '.hb-payment-type-multiple-choice' ).hide(); 1163 } 1164 } else { 1165 $booking_wrapper.find( 'input[name="hb-payment-type"]' ).first().prop( 'checked', true ); 1166 $booking_wrapper.find( '.hb-payment-type-multiple-choice, .hb-payment-type-deposit-wrapper' ).show(); 1167 } 1168 hide_show_payment_explanation( $booking_wrapper.find( '.hb-booking-details-form' ) ); 1169 } 1170 } 1171 1172 /* end update payment info */ 1173 1174 /* ------------------------------------------------------------------------------------------- */ 1175 1176 /* summary */ 1177 1178 function set_summary_on_discount_change( $booking_wrapper ) { 1179 set_summary( $booking_wrapper, true ); 1180 } 1181 1182 function set_summary( $booking_wrapper, on_discount_change ) { 1183 $booking_wrapper.find( '.hb-summary-wrapper' ).hide(); 1184 $booking_wrapper.find( '.hb-loading-summary' ).show(); 1185 var accom_ids = $booking_wrapper.find( '.hb-details-accom-ids' ).val().split( '-' ); 1186 if ( accom_ids.length > 1 ) { 1187 $( '.hb-global-discount-wrapper' ).css( 'display', 'none' ); 1188 } else { 1189 $( '.hb-global-discount-wrapper' ).css( 'display', 'block' ); 1190 } 1191 var $details_form = $booking_wrapper.find( '.hb-booking-details-form' ); 1192 var $options_form = $booking_wrapper.find( '.hb-options-form' ); 1193 var $accom_num_form = $booking_wrapper.find( '.hb-select-accom-num-form' ); 1194 var $forms;
1195 $details_form.find( 'input[name="action"]' ).val( 'hb_get_summary'); 1196 $forms = $details_form.add( $options_form ); 1197 $forms = $forms.add( $accom_num_form ); 1198 $.ajax({ 1199 data: $forms.serialize(), 1200 success: function( response ) { 1201 $booking_wrapper.find( '.hb-loading-summary' ).hide(); 1202 $booking_wrapper.find( '.hb-summary-wrapper' ).html( response ); 1203 hb_format_date(); 1204 $booking_wrapper.find( '.hb-summary-wrapper' ).slideDown(); 1205 if ( hb_booking_form_data.is_admin != 'yes' ) { 1206 update_payment_info( $booking_wrapper ); 1207 } else { 1208 if ( ! on_discount_change ) { 1209 if ( $booking_wrapper.find( '.hb-discount-data-summary' ).length ) { 1210 $( '#hb-global-discount-amount' ).val( $booking_wrapper.find( '.hb-discount-data-summary' ).data( 'discount-amount' ) ); 1211 if ( $booking_wrapper.find( '.hb-discount-data-summary' ).data( 'discount-amount-type' ) == 'fixed' ) { 1212 $( '#hb-global-discount-amount-type-fixed' ).prop( 'checked', true ); 1213 } else { 1214 $( '#hb-global-discount-amount-type-percent' ).prop( 'checked', true ); 1215 } 1216 } else { 1217 $( '#hb-global-discount-amount' ).val( 0 ); 1218 $( '#hb-global-discount-amount-type-fixed' ).prop( 'checked', true ); 1219 } 1220 } 1221 }
1222 $details_form.find( 'input[name="action"]' ).val( 'hb_create_resa' ); 1223 }, 1224 type : 'POST', 1225 timeout: hb_booking_form_data.ajax_timeout, 1226 url: hb_booking_form_data.ajax_url, 1227 error: function( jqXHR, textStatus, errorThrown ) { 1228 $booking_wrapper.find( '.hb-loading-summary' ).hide(); 1229 $details_form.find( 'input[name="action"]' ).val( 'hb_create_resa' ); 1230 alert( hb_text.connection_error ); 1231 console.log( jqXHR ); 1232 console.log( jqXHR.responseText ); 1233 console.log( textStatus ); 1234 console.log( errorThrown ); 1235 } 1236 }); 1237 } 1238 1239 $( '.hb-summary-wrapper' ).on( 'click', '.hb-summary-view-price-breakdown', function() { 1240 var $self = $( this ); 1241 $self.blur(); 1242 $self.parents( '.hb-summary-multi-accom-accom' ).find( '.hb-summary-price-details' ).slideToggle( function() { 1243 if ( $( this ).is( ':visible' ) ) { 1244 $self.find( '.hb-summary-price-breakdown-hide-text' ).show(); 1245 $self.find( '.hb-summary-price-breakdown-show-text' ).hide(); 1246 } else { 1247 $self.find( '.hb-summary-price-breakdown-hide-text' ).hide(); 1248 $self.find( '.hb-summary-price-breakdown-show-text' ).show(); 1249 } 1250 }); 1251 return false; 1252 }); 1253 1254 /* end summary */ 1255 1256 /* ------------------------------------------------------------------------------------------- */ 1257 1258 /* details form info */ 1259 1260 function toggle_accom_not_available_msg( $booking_wrapper, accom_id ) { 1261 if ( 1262 ( hb_booking_form_data.is_admin != 'yes' ) || 1263 ( $booking_wrapper.find( '.hb-admin-search-type' ).val() == 'multiple_accom' ) || 1264 $booking_wrapper.find( '.hb-accom-id-' + accom_id ).hasClass( 'hb-accom-available' ) 1265 ) { 1266 $( '#hb-resa-customer-details-wrap, .hb-confirm-area' ).slideDown(); 1267 $( '.hb-accom-not-available-msg' ).slideUp(); 1268 } else { 1269 $( '#hb-resa-customer-details-wrap, .hb-confirm-area' ).slide
1269Up(); 1270 $( '.hb-accom-not-available-msg' ).slideDown(); 1271 } 1272 } 1273 1274 function set_details_form_info( $booking_wrapper, accom_ids ) { 1275 $booking_wrapper.find( '.hb-details-check-in' ).val( $booking_wrapper.find( '.hb-check-in-hidden' ).val() ); 1276 $booking_wrapper.find( '.hb-details-check-out' ).val( $booking_wrapper.find( '.hb-check-out-hidden' ).val() ); 1277 $booking_wrapper.find( '.hb-details-adults' ).val( $booking_wrapper.find( '.hb-booking-nb-adults' ).val() ); 1278 $booking_wrapper.find( '.hb-details-children' ).val( $booking_wrapper.find( '.hb-booking-nb-children' ).val() ); 1279 $booking_wrapper.find( '.hb-details-accom-ids' ).val( accom_ids ); 1280 $booking_wrapper.find( '.hb-details-is-admin' ).val( hb_booking_form_data.is_admin ); 1281 } 1282 1283 /* end details form info */ 1284 1285 /* ------------------------------------------------------------------------------------------- */ 1286 1287 /* country iso */ 1288 1289 $( 'select[name="hb_country_iso"]' ).on( 'change', function() { 1290 show_hide_country_iso_info( $( this ).parents( '.hbook-wrapper' ) ); 1291 }); 1292 1293 function show_hide_country_iso_info( $booking_wrapper ) { 1294 $booking_wrapper.find( '.hb-country-iso-additional-info-wrapper' ).hide(); 1295 $booking_wrapper.find( '.hb-country-iso-additional-info-wrapper select' ).attr( 'data-validation', '' ); 1296 var selected_country_iso = $booking_wrapper.find( 'select[name="hb_country_iso"]' ).val(); 1297 var selected_country_required = false; 1298 if ( $booking_wrapper.find( 'select[name="hb_country_iso"]' ).data( 'validation' ) == 'required' ) { 1299 selected_country_required = true; 1300 } 1301 if ( selected_country_iso == 'US' ) { 1302 $booking_wrapper.find( '.hb-usa-state-iso-wrapper' ).show(); 1303 if ( selected_country_required ) { 1304 $booking_wrapper.find( 'select[name="hb_usa_state_iso"]' ).attr( 'data-validation', 'required' ); 1305 } 1306 } else if ( selected_country_iso == 'CA' ) { 1307 $booking_wrapper.find( '.hb-canada-province-iso-wrapper' ).show(); 1308 if ( selected_country_required ) { 1309 $booking_wrapper.find( 'select[name="hb_canada_province_iso"]' ).attr( 'data-validation', 'required' ); 1310 } 1311 } 1312 } 1313 1314 /* end country iso */ 1315 1316 /* ------------------------------------------------------------------------------------------- */ 1317 1318 /* details form validation */ 1319 1320 if ( ( typeof hb_booking_form_data !== 'undefined' ) && ( hb_booking_form_data.is_admin != 'yes' ) && $( '.hb-booking-details-form' ).length ) { 1321 $.validate({ 1322 form: '.hb-booking-details-form', 1323 validateOnBlur: false, 1324 language: { 1325 badEmail: hb_text.invalid_email, 1326 requiredField: hb_text.required_field, 1327 requiredFields: hb_text.required_field, 1328 groupCheckedTooFewStart: hb_text.required_field + '<span style="display: none">', 1329 groupCheckedEnd: '</span>', 1330 badInt: hb_text.invalid_number 1331 }, 1332 borderColorOnError: false, 1333 scrollToTopOnError: false, 1334 onError: function( $form ) { 1335 $form.find( '.hb-confirm-button input' ).blur(); 1336 $( 'html, body' ).animate({ scrollTop: $( '.has-error' ).first().offset().top - page_padding_top }, 400 ); 1337 }, 1338 onSuccess: function( $form ) { 1339 submit_booking_details( $form ); 1340 return false; 1341 } 1342 }); 1343 } 1344 1345 if ( ( typeof hb_booking_form_data !== 'undefined' ) && ( hb_booking_form_data.is_admin == 'yes' ) ) { 1346 $( '.hb-booking-details-form' ).submit( function() { 1347 $( this ).find( 'input[type="submit"]' ).blur(); 1348 if ( $( '#hb-admin-customer-type-id:checked' ).length ) {
1349 if ( ! $( '#hb-add-resa-customer-id-list' ).val() ) { 1350 alert( hb_text.customer_not_selected ); 1351 return false; 1352 } 1353 } 1354 submit_booking_details( $( this ) ); 1355 return false; 1356 }); 1357 } 1358 1359 /* end details form validation */ 1360 1361 /* ------------------------------------------------------------------------------------------- */ 1362 1363 /* save reservation details */ 1364 1365 function submit_booking_details( $form ) { 1366 $form.find( '.hb-confirm-button input' ).blur(); 1367 1368 if ( $form.hasClass( 'submitted' ) ) { 1369 return false; 1370 } 1371 1372 var policies_error = ''; 1373 $form.find( '.hb-policies-error, .hb-confirm-error' ).hide(); 1374 if ( $form.find( 'input[name="hb_terms_and_cond"]' ).length && ! $form.find( 'input[name="hb_terms_and_cond"]' ).prop( 'checked' ) ) { 1375 policies_error = hb_text.terms_and_cond_error; 1376 } 1377 if ( $form.find( 'input[name="hb_privacy_policy"]' ).length && ! $form.find( 'input[name="hb_privacy_policy"]' ).prop( 'checked' ) ) { 1378 if ( policies_error ) { 1379 policies_error += '<br/>'; 1380 } 1381 policies_error += hb_text.privacy_policy_error; 1382 } 1383 if ( policies_error ) { 1384 $form.find( '.hb-policies-error' ).html( policies_error ).slideDown(); 1385 $( 'html, body' ).animate({ 1386 scrollTop: $form.find( '.hb-policies-area' ).offset().top - page_padding_top 1387 }, 1000 ); 1388 return false; 1389 } 1390
1391 var payment_type = $form.find( 'input[name="hb-payment-type"]:checked' ).val(), 1392 payment_processing = false; 1393 1394 if ( payment_type == 'store_credit_card' || payment_type == 'deposit' || payment_type == 'full' ) { 1395 $form.find( '.hb-payment-flag' ).val( 'yes' ); 1396 var gateway_id = $form.find( 'input[name="hb-payment-gateway"]:checked' ).val(), 1397 payment_process_function = 'hb_' + gateway_id + '_payment_process'; 1398 if ( ! gateway_id ) { 1399 alert( 'Error: all payment gateways are inactive.' ); 1400 return; 1401 } 1402 if ( typeof window[ payment_process_function ] == 'function' ) { 1403 disable_form_submission( $form ); 1404 payment_processing = window[ payment_process_function ]( $form, save_resa_details ); 1405 if ( ! payment_processing ) { 1406 enable_form_submission( $form ); 1407 return; 1408 } 1409 } 1410 } else { 1411 $form.find( '.hb-payment-flag' ).val( '' ); 1412 } 1413 1414 if ( ! payment_processing ) { 1415 $form.find( '.hb-saving-resa' ).slideDown(); 1416 save_resa_details( $form ); 1417 } 1418 } 1419 1420 function save_resa_details( $form ) { 1421 disable_form_submission( $form ); 1422 var $options_form = $form.parents( '.hbook-wrapper' ).find( '.hb-options-form' ), 1423 $accom_num_form = $form.parents( '.hbook-wrapper' ).find( '.hb-select-accom-num-form' ), 1424 $forms; 1425 $forms = $form.add( $options_form ); 1426 $forms = $forms.add( $accom_num_form ); 1427 $.ajax({ 1428 data: $forms.serialize(), 1429 success: function( response ) { 1430 after_form_details_submit( response, $form ); 1431 }, 1432 type : 'POST', 1433 timeout: hb_booking_form_data.ajax_timeout, 1434 url: hb_booking_form_data.ajax_url, 1435 error: function( jqXHR, textStatus, errorThrown ) { 1436 $form.find( '.hb-saving-resa, .hb-confirm-error, .hb-policies-error' ).slideUp(); 1437 $form.find( '.hb-confirm-error' ).html( hb_text.connection_error ).slideDown(); 1438 console.log( jqXHR ); 1439 console.log( jqXHR.responseText ); 1440 console.log( textStatus ); 1441 console.log( errorThrown ); 1442 enable_form_submission( $form ); 1443 } 1444 }); 1445 } 1446 1447 function after_form_details_submit( response_text, $form ) { 1448 try { 1449 var response = JSON.parse( response_text ); 1450 } catch ( e ) { 1451 enable_form_submission( $form ); 1452 $form.find( '.hb-saving-resa' ).slideUp(); 1453 $form.find( '.hb-confirm-error' ).html( response_text ).slideDown(); 1454 return false; 1455 } 1456 if ( response['success'] ) {
1457 var payment_type = $form.find( 'input[name="hb-payment-type"]:checked' ).val(), 1458 payment_has_redirection = $form.find( 'input[name="hb-payment-gateway"]:checked' ).data( 'has-redirection' ); 1459 if ( ( payment_type == 'deposit' || payment_type == 'full' ) && ( payment_has_redirection == 'yes' ) ) { 1460 var gateway_id = $form.find( 'input[name="hb-payment-gateway"]:checked' ).val(), 1461 payment_process_redirection = 'hb_' + gateway_id + '_payment_redirection'; 1462 window[ payment_process_redirection ]( $form, response ); 1463 } else { 1464 $form.find( '.hb-saving-resa' ).slideUp(); 1465 if ( hb_booking_form_data.is_admin != 'yes' ) { 1466 var $thank_you_page_form = $form.parents( '.hbook-wrapper' ).find( '.hb-thank-you-page-form' ); 1467 if ( $thank_you_page_form.length ) { 1468 $( 'body' ).addClass( 'no-hbook-unload' ); 1469 $thank_you_page_form.find( '.hb-resa-id' ).val( response.resa_id ); 1470 $thank_you_page_form.find( '.hb-resa-is-parent' ).val( response.resa_is_parent ); 1471 $thank_you_page_form.find( '.hb-resa-payment-type' ).val( payment_type ); 1472 $thank_you_page_form.submit(); 1473 return; 1474 }
1475 $form.find( '.hb-resa-done-email' ).html( $form.find( 'input[name="hb_email"]' ).val() ); 1476 $( 'html, body' ).animate({ scrollTop: $form.parents( '.hbook-wrapper' ).offset().top - page_padding_top }, 1000, function() { 1477 $form.parents( '.hbook-wrapper' ).find( '.hb-booking-search-form, .hb-accom-list, .hb-step-button, .hb-details-fields, .hb-coupons-area, .hb-confirm-area, .hb-policies-area, .hb-payment-info-wrapper, .hb-resa-summary' ).fadeOut( 1000, function() { 1478 if ( payment_type == 'deposit' || payment_type == 'full' ) { 1479 $form.find( '.hb-resa-payment-msg' ).show(); 1480 } else { 1481 $form.find( '.hb-resa-done-msg' ).show(); 1482 } 1483 $form.find( '.hb-resa-summary' ).slideDown(); 1484 }); 1485 }); 1486 if ( typeof window['hbook_reservation_done'] == 'function' ) { 1487 window['hbook_reservation_done'](); 1488 } 1489 } else { 1490 hb_new_admin_resas = response['resas']; 1491 enable_form_submission( $form ); 1492 change_search( $form.parents( '.hbook-wrapper' ) ); 1493 $( '#hb-process-new-admin-resa' ).submit(); 1494 } 1495 } 1496 } else { 1497 if ( response['error_msg'] == 'payment_requires_action' ) {
1498 var gateway_id = $form.find( 'input[name="hb-payment-gateway"]:checked' ).val(), 1499 payment_requires_action = 'hb_' + gateway_id + '_payment_requires_action'; 1500 window[ payment_requires_action ]( $form, response ); 1501 } else { 1502 enable_form_submission( $form ); 1503 $form.find( '.hb-saving-resa' ).slideUp(); 1504 $form.find( '.hb-confirm-error' ).html( response['error_msg'] ).slideDown(); 1505 } 1506 } 1507 } 1508 1509 /* end save reservation details */ 1510 1511 /* ------------------------------------------------------------------------------------------- */ 1512 1513 /* external payment confirmation */ 1514 1515 if ( $( '#hb-resa-confirm-done' ).length ) { 1516 $( '#hb-resa-confirm-done' ).parent('.hb-accom-list-booking-form' ).show(); 1517 hb_format_date(); 1518 if ( typeof window['hbook_reservation_done'] == 'function' ) { 1519 window['hbook_reservation_done'](); 1520 } 1521 $( 'html, body' ).animate({ scrollTop: $( '#hb-resa-confirm-done' ).offset().top - page_padding_top }, 1000 ); 1522 } 1523 1524 /* end external payment confirmation */ 1525 1526 /* ------------------------------------------------------------------------------------------- */ 1527 1528 /* payment type and method init */ 1529 1530 $( '.hb-booking-details-form' ).each( function() { 1531 $( this ).find( 'input[name="hb-payment-type"]' ).first().prop( 'checked', true ); 1532 $( this ).find( 'input[name="hb-payment-gateway"]' ).first().prop( 'checked', true ); 1533 hide_show_payment_explanation( $( this ) ); 1534 hide_show_payment_gateway_choice( $( this ) ); 1535 hide_show_payment_gateway_form( $( this ) ); 1536 hide_show_bottom_area( $( this ) ); 1537 }); 1538 1539 /* end payment type and method init */ 1540 1541 /* ------------------------------------------------------------------------------------------- */ 1542 1543 /* payment gateway choice */ 1544 1545 $( 'input[name="hb-payment-type"]' ).on( 'change', function() { 1546 hide_show_payment_explanation( $( this ).parents( 'form' ) ); 1547 hide_show_payment_gateway_choice( $( this ).parents( 'form' ) ); 1548 hide_show_bottom_area( $( this ).parents( 'form' ) ); 1549 }); 1550 1551 $( 'input[name="hb-payment-gateway"]' ).on( 'change', function() { 1552 hide_show_payment_gateway_form( $( this ).parents( 'form' ) ); 1553 hide_show_bottom_area( $( this ).parents( 'form' ) ); 1554 }); 1555 1556 function hide_show_payment_explanation( $form ) {
1557 var payment_type = $form.find( 'input[name="hb-payment-type"]:checked' ).val(); 1558 $form.find( '.hb-payment-type-explanation' ).hide(); 1559 $form.find( '.hb-payment-type-explanation-' + payment_type ).slideDown(); 1560 } 1561 1562 function hide_show_payment_gateway_choice( $form ) { 1563 var payment_type = $form.find( 'input[name="hb-payment-type"]:checked' ).val(); 1564 if ( payment_type == 'store_credit_card' || payment_type == 'deposit' || payment_type == 'full' ) { 1565 $form.find( '.hb-payment-method-wrapper' ).slideDown(); 1566 } else { 1567 $form.find( '.hb-payment-method-wrapper' ).slideUp(); 1568 } 1569 if ( payment_type == 'store_credit_card' ) { 1570 $form.find( '.hb-payment-method' ).slideUp(); 1571 $form.find( 'input[name="hb-payment-gateway"][value="stripe"]' ).prop( 'checked', true ); 1572 if ( $form.find( '.hb-payment-form-stripe' ).css( 'display' ) == 'none' ) { 1573 $form.find( '.hb-payment-form' ).slideUp(); 1574 $form.find( '.hb-payment-form-stripe' ).slideDown(); 1575 } 1576 } else { 1577 $form.find( '.hb-payment-method' ).slideDown(); 1578 } 1579 } 1580 1581 function hide_show_payment_gateway_form( $form ) { 1582 $form.find( '.hb-payment-form' ).slideUp();
1583 var gateway_id = $form.find( 'input[name="hb-payment-gateway"]:checked' ).val(); 1584 $form.find( '.hb-payment-form-' + gateway_id ).slideDown(); 1585 } 1586 1587 function hide_show_bottom_area( $form ) { 1588 var payment_type = $form.find( 'input[name="hb-payment-type"]:checked' ).val(); 1589 if ( payment_type == 'deposit' || payment_type == 'full' ) { 1590 var gateway_id = $form.find( 'input[name="hb-payment-gateway"]:checked' ).val(); 1591 if ( $form.find( '.hb-bottom-area-content-' + gateway_id ).length ) { 1592 var bottom_area_content = $form.find( '.hb-bottom-area-content-' + gateway_id ).html(); 1593 $form.find( '.hb-bottom-area' ).html( bottom_area_content ).slideDown(); 1594 } else { 1595 $form.find( '.hb-bottom-area' ).slideUp(); 1596 } 1597 } else { 1598 $form.find( '.hb-bottom-area' ).slideUp(); 1599 } 1600 } 1601 1602 /* end payment gateway choice */ 1603 1604 /* ------------------------------------------------------------------------------------------- */ 1605 1606 /* misc */ 1607 1608 function format_price( price ) { 1609 if ( hb_booking_form_data.price_precision == 'no_decimals' ) { 1610 var formatted_price = Math.round( price ); 1611 } else { 1612 var formatted_price = parseFloat( price ).toFixed( 2 ); 1613 } 1614 var price_parts = formatted_price.toString().split( '.' ); 1615 if ( hb_booking_form_data.thousands_sep ) { 1616 price_parts[0] = price_parts[0].replace( /\B(?=(\d{3})+(?!\d))/g, hb_booking_form_data.thousands_sep ); 1617 } 1618 return price_parts.join( hb_booking_form_data.decimal_point ); 1619 } 1620 1621 function disable_form_submission( $form ) { 1622 $form.addClass( 'submitted' );
1623 $form.find( 'input[type="submit"]' ).prop( 'disabled', true ); 1624 } 1625 1626 function enable_form_submission( $form ) { 1627 $form.removeClass( 'submitted' ); 1628 $form.find( 'input[type="submit"]' ).prop( 'disabled', false ); 1629 } 1630 1631 function debouncer( func ) { 1632 var timeoutID, 1633 timeout = 50; 1634 return function () { 1635 var scope = this, 1636 args = arguments; 1637 clearTimeout( timeoutID ); 1638 timeoutID = setTimeout( function () { 1639 func.apply( scope, Array.prototype.slice.call( args ) ); 1640 }, timeout ); 1641 } 1642 } 1643 1644 function resize_forms() { 1645 $( '.hb-booking-search-form' ).each( function() { 1646 var body_class = ''; 1647 if ( $( this ).attr( 'id' ) != '' ) { 1648 body_class = 'hb-' + $( this ).attr('id') + '-is-vertical'; 1649 } 1650 if ( $( this ).width() < hb_booking_form_data.horizontal_form_min_width ) { 1651 $( this ).addClass( 'hb-vertical-search-form' ); 1652 $( this ).removeClass( 'hb-horizontal-search-form' ); 1653 $( 'body' ).addClass( body_class ); 1654 } else { 1655 $( this ).removeClass( 'hb-vertical-search-form' ); 1656 $( this ).addClass( 'hb-horizontal-search-form' ); 1657 $( 'body' ).removeClass( body_class ); 1658 } 1659 if ( $( this ).width() < 400 ) { 1660 $( this ).addClass( 'hb-narrow-search-form' ); 1661 } else { 1662 $( this ).removeClass( 'hb-narrow-search-form' ); 1663 } 1664 }); 1665 $( '.hb-booking-details-form' ).each( function() { 1666 if ( $( this ).width() < hb_booking_form_data.details_form_stack_width ) { 1667 $( this ).addClass( 'hb-details-form-stacked' ); 1668 } else { 1669 $( this ).removeClass( 'hb-details-form-stacked' ); 1670 } 1671 }); 1672 } 1673 1674 function resize_price_caption() { 1675 $( '.hb-accom-list' ).each( function() { 1676 if ( $( this ).width() < 600 ) { 1677 $( this ).find( '.hb-accom-price-caption br' ).show(); 1678 $( this ).find( '.hb-accom-price-caption-dash' ).hide(); 1679 $( this ).find( '.hb-accom-price-caption' ).addClass( 'hb-accom-price-caption-small' ); 1680 } else { 1681 $( this ).find( '.hb-accom-price-caption br' ).hide(); 1682 $( this ).find( '.hb-accom-price-caption-dash' ).show(); 1683 $( this ).find( '.hb-accom-price-caption' ).removeClass( 'hb-accom-price-caption-small' ); 1684 } 1685 }); 1686 } 1687 1688 function reposition_people_popup() { 1689 var $people_popup = $( '.hb-people-popup-wrapper-visible' ); 1690 if ( $people_popup.length ) { 1691 var $accom_people_selection = $people_popup.find( '.hb-multi-accom-people-selection-wrapper' ); 1692 if ( hb_booking_form_data.is_admin == 'yes' ) { 1693 var $select = $( '.hb-booking-search-form .hb-accom-number' ); 1694 } else { 1695 var form_num = $accom_people_selection.data( 'form-num' ); 1696 var $select = $( '.hb-booking-search-form.hb-form-' + form_num + ' .hb-accom-number' ); 1697 } 1698 var scroll_y = $( window ).scrollTop(); 1699 var select_top = $select.offset().top; 1700 var select_bottom = select_top + $select.outerHeight( true ); 1701 var select_left = $select.offset().left; 1702 var available_space_above = select_top - scroll_y; 1703 var available_space_below = $( window ).height() - select_bottom + scroll_y; 1704 var people_popup_height = $( '.hb-people-popup-wrapper' ).outerHeight( true ); 1705 if ( available_space_below > people_popup_height ) { 1706 $( '.hb-people-popup-wrapper' ).css( 'top', select_bottom ); 1707 } else if ( available_space_above > people_popup_height ) { 1708 $( '.hb-people-popup-wrapper' ).css( 'top', select_top - peo
1708ple_popup_height ); 1709 } else { 1710 $( '.hb-people-popup-wrapper' ).css( 'top', scroll_y ); 1711 } 1712 $( '.hb-people-popup-wrapper' ).css( 'left', select_left ); 1713 } 1714 } 1715 1716 $( window ).resize( debouncer ( function () { 1717 resize_forms(); 1718 resize_price_caption(); 1719 reposition_people_popup(); 1720 })).resize(); 1721 1722 $( window ).on( 'beforeunload', function() { 1723 if ( ! $( 'body' ).hasClass( 'no-hbook-unload' ) ) { 1724 $( '.hb-accom-list, .hb-booking-details-form' ).each( function() { 1725 if ( $( this ).is( ':visible' ) ) { 1726 var scroll_top = $( window ).scrollTop(); 1727 var offset = $( this ).offset().top; 1728 var height = $( this ).outerHeight( true ); 1729 $( this ).hide(); 1730 if ( scroll_top > offset + height ) { 1731 $( 'html, body' ).scrollTop( scroll_top - height ); 1732 } else if ( scroll_top > offset ) { 1733 $( 'html, body' ).scrollTop( offset ); 1734 } 1735 } 1736 }); 1737 } 1738 }); 1739 1740 /* end misc */ 1741 1742 /* ------------------------------------------------------------------------------------------- */ 1743 1744 /* status processing */ 1745 1746 $( '.hbook-wrapper-booking-form' ).each( function() { 1747 var $booking_wrapper = $( this ), 1748 $search_form = $booking_wrapper.find( '.hb-booking-search-form' ); 1749 if ( $search_form.find( '.hb-check-in-hidden' ).val() != '' ) { 1750 var check_in = hb_date_str_2_obj( $search_form.find( '.hb-check-in-hidden' ).val() ), 1751 check_out = hb_date_str_2_obj( $search_form.find( '.hb-check-out-hidden' ).val() ); 1752 check_in = $.datepick.formatDate( hb_date_format, check_in ); 1753 check_out = $.datepick.formatDate( hb_date_format, check_out ); 1754 $search_form.find( '.hb-check-in-date' ).val( check_in ); 1755 $search_form.find( '.hb-check-out-date' ).val( check_out ); 1756 $search_form.find( 'select.hb-adults' ).val( $search_form.find( '.hb-adults-hidden' ).val() ); 1757 $search_form.find( 'select.hb-children' ).val( $search_form.find( '.hb-children-hidden' ).val() ); 1758 } 1759 var accom_people = $( '.hb-accom-people' ).val(); 1760 if ( ( typeof accom_people !== 'undefined' ) && ( accom_people != '' ) ) { 1761 accom_people = accom_people.split( ',' ); 1762 $search_form.find( 'select.hb-accom-number' ).val( accom_people.length ); 1763 for ( var i = 0; i < accom_people.length; i++ ) { 1764 var multi_accom_num = i + 1; 1765 var accom_adults = accom_people[i].split( '-' )[0]; 1766 var accom_children = accom_people[i].split( '-' )[1]; 1767 $search_form.find( '.hb-multi-accom-people-selection-accom-' + multi_accom_num + ' .hb-multi-accom-adults' ).val( accom_adults ); 1768 $search_form.find( '.hb-multi-accom-people-selection-accom-' + multi_accom_num + ' .hb-multi-accom-children' ).val( accom_children ); 1769 } 1770 update_accom_people( $search_form ); 1771 } else { 1772 setTimeout( function() { 1773 if ( $search_form.find( 'select.hb-accom-number option[value="-1"]' ).length ) { 1774 $search_form.find( 'select.hb-accom-number' ).val( -1 ); 1775 $search_form.find( '.hb-accom-people' ).val( '' ); 1776 } 1777 }, 1000 ); 1778 } 1779 1780 if ( $booking_wrapper.data( 'status' ) == 'search-accom' ) { 1781 $( 'html, body' ).animate({ scrollTop: $search_form.offset().top - page_padding_top }, function() { 1782 $search_form.submit(); 1783 }); 1784 return false; 1785 } 1786 1787 if ( $booking_wrapper.data( 'status' ) == 'external-payment-cancel' ) { 1788 // $search_form.submit(); 1789 // return false; 1790 } 1791 1792 if ( $booking_wrapper.data( 'status' ) == 'external-payment-timeout' ) { 1793 alert( hb_text.timeout_error ); 1794 } 1795 1796 if ( $booking_wrapper.data( 'status' ) == 'external-payment-confirm-error' ) { 1797 alert( hb_payment_confirmation_error ); 1798 } 1799 }); 1800 1801 /* end status processing */ 1802 1803 /* ------------------------------------------------------------------------------------------- */ 1804 1805});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.