1(function($){ 2 "use strict"; 3 4 // Detect Mobile Device 5 var tourmaster_mobile = false; 6 if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/BlackBerry/i) || 7 navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/Windows Phone/i) ){ 8 tourmaster_mobile = true; 9 }else{ 10 tourmaster_mobile = false; 11 } 12 13 // Detect Screen 14 var tourmaster_display = 'desktop'; 15 if( typeof(window.matchMedia) == 'function' ){ 16 $(window).on('load resize', function(){ 17 if( window.matchMedia('(max-width: 419px)').matches ){ 18 tourmaster_display = 'mobile-portrait'; 19 }else if( window.matchMedia('(max-width: 767px)').matches ){ 20 tourmaster_display = 'mobile-landscape' 21 }else if( window.matchMedia('(max-width: 999px)').matches ){ 22 tourmaster_display = 'tablet' 23 }else{ 24 tourmaster_display = 'desktop'; 25 } 26 }); 27 }else{ 28 $(window).on('load resize', function(){ 29 if( $(window).innerWidth() <= 419 ){ 30 tourmaster_display = 'mobile-portrait'; 31 }else if( $(window).innerWidth() <= 767 ){ 32 tourmaster_display = 'mobile-landscape' 33 }else if( $(window).innerWidth() <= 999 ){ 34 tourmaster_display = 'tablet' 35 }else{ 36 tourmaster_display = 'desktop'; 37 } 38 }); 39 } 40 41 function tourmaster_get_form_array_data( object, name, value ){ 42 var name_match = name.match(/^[A-Za-z\-\_]+/); 43 if( name_match ){ 44 if( typeof(object[name_match[0]]) != 'object' ){ 45 object[name_match[0]] = {}; 46 } 47 var last_name = name.replace(name_match[0], ''); 48 object[name_match[0]] = tourmaster_get_form_array_data(object[name_match[0]], last_name, value); 49 }else{ 50 var array_match = name.match(/\[(\d+)\]/); 51 if( array_match ){ 52 if( typeof(object[array_match[1]]) != 'object' ){ 53 object[array_match[1]] = {}; 54 } 55 var last_name = name.replace(array_match[1], ''); 56 object[array_match[1]] = tourmaster_get_form_array_data(object[array_match[1]], last_name, value); 57 }else{ 58 return value; 59 } 60 } 61 62 return object; 63 } 64 function tourmaster_get_form_data( form ){ 65 var ret = {}; 66 67 form.find('input[name], select[name], textarea[name]').each(function(){ 68 var key = $(this).attr('name'); 69 var value; 70 71 if( $(this).is('[type="checkbox"]') ){ 72 var value = $(this).is(':checked')? $(this).val(): 0; 73 }else if( $(this).is('[type="radio"]') ){ 74 if( $(this).is(':checked') ){ 75 var value = $(this).val(); 76 }else{ 77 return; 78 } 79 }else{ 80 var value = $(this).val(); 81 } 82 83 if( (key.lastIndexOf('[]') == (key.length - 2)) ){ 84 key = key.substr(0, key.length - 2); 85 if( typeof(ret[key]) != 'object' ){ 86 ret[key] = [] 87 } 88 89 ret[key].push(value); 90 }else{ 91 ret = tourmaster_get_form_array_data(ret, $(this).attr('name'), value); 92 // ret[$(this).attr('name')] = value; 93 } 94 }); 95 96 return ret; 97 } 98 99 // tour booking bar 100 function tourmaster_room_booking_ajax( ajax_url, ajax_settings, ajax_data ){ 101 102 var ajax_settings = $.extend({ 103 beforeSend: function( jqXHR, settings ){}, 104 error: function( jqXHR, textStatus, errorThrown ){ 105 106 // print error message for debug purpose 107 console.log(jqXHR, textStatus, errorThrown); 108 }, 109 success: function( data ){ 110 // console.log('success', data); 111 } 112 }, ajax_settings); 113 114 var ajax_data = $.extend({ 115 action: '', 116 }, ajax_data); 117 118 $.ajax({ 119 type: 'POST', 120 url: ajax_url, 121 data: ajax_data, 122 dataType: 'json', 123 beforeSend: ajax_settings.beforeSend, 124 error: ajax_settings.error, 125 success: ajax_settings.success 126 }); 127 } 128 129 // single review 130 $.fn.tourmaster_room_single_review = function(){ 131 var review_section = $(this); 132 var review_filter = $(this).find('#tourmaster-single-review-filter'); 133 var review_content = $(this).find('#tourmaster-single-review-content'); 134 135 // bind the filter 136 var sort_by = review_filter.find('[data-sort-by]'); 137 138 sort_by.click(function(){ 139 if( $(this).hasClass('tourmaster-active') ) return false; 140 141 $(this).addClass('tourmaster-active').siblings('[data-sort-by]').removeClass('tourmaster-active'); 142 tourmaster_room_get_review_ajax({
143 'action': 'get_single_room_review', 144 'room_id': review_content.attr('data-room-id'), 145 'sort_by': $(this).attr('data-sort-by'), 146 }, review_content); 147 }); 148 149 review_content.on('click', '[data-paged]', function(){ 150 tourmaster_room_get_review_ajax({ 151 'action': 'get_single_room_review', 152 'room_id': review_content.attr('data-room-id'), 153 'paged': $(this).attr('data-paged'), 154 'sort_by': sort_by.filter('.tourmaster-active').attr('data-sort-by'), 155 }, review_content, review_section); 156 }); 157 } 158 function tourmaster_room_get_review_ajax( ajax_data, content_section, scroll_to = null ){ 159 content_section.animate({opacity: 0.2}, 200); 160 161 $.ajax({ 162 type: 'POST', 163 url: content_section.attr('data-ajax-url'), 164 data: ajax_data, 165 dataType: 'json', 166 error: function( jqXHR, textStatus, errorThrown ){ 167 168 content_section.animate({opacity: 1}, 200); 169 170 // print error message for debug purpose 171 console.log(jqXHR, textStatus, errorThrown); 172 }, 173 success: function( data ){ 174 175 if( typeof(data.content) != 'undefined' ){ 176 var old_height = content_section.outerHeight(); 177 content_section.html(data.content); 178 179 var new_height = content_section.outerHeight(); 180 content_section.css({'height': old_height}); 181 content_section.animate({height: new_height}, 200 , function(){ 182 content_section.css({height: 'auto'}); 183 }); 184 } 185 186 content_section.animate({opacity: 1}, 200); 187 188 if( scroll_to != null ){ 189 $('body, html').animate({'scrollTop': scroll_to.offset().top - 150 }); 190 } 191 192 } 193 }); 194 } 195 $.fn.tourmaster_room_review_item = function(){ 196 var review_section = $(this); 197 var review_filter = $(this).find('#tourmaster-single-review-filter'); 198 var review_content = $(this).find('#tourmaster-single-review-content'); 199 var review_settings = $(this).data('settings'); 200 201 // bind the filter 202 var sort_by = review_filter.find('[data-sort-by]'); 203 204 sort_by.click(function(){ 205 if( $(this).hasClass('tourmaster-active') ) return false; 206 207 $(this).addClass('tourmaster-active').siblings('[data-sort-by]').removeClass('tourmaster-active'); 208 tourmaster_room_get_review_ajax({ 209 'action': 'get_room_item_review', 210 'sort_by': $(this).attr('data-sort-by'), 211 'settings': review_settings 212 }, review_content); 213 }); 214 215 review_content.on('click', '[data-paged]', function(){ 216 tourmaster_room_get_review_ajax({ 217 'action': 'get_room_item_review', 218 'paged': $(this).attr('data-paged'), 219 'sort_by': sort_by.filter('.tourmaster-active').attr('data-sort-by'), 220 'settings': review_settings 221 }, review_content, review_section); 222 }); 223 } 224 225 $.fn.tourmaster_room_amount_selection = function(){ 226 227 $(this).each(function(){ 228 var display = $(this).find('.tourmaster-custom-amount-display'); 229 var option_wrap = $(this).find('.tourmaster-custom-amount-selection-wrap'); 230 231 var label = $(this).find('.tourmaster-custom-amount-display .tourmaster-tail'); 232 var items = $(this).find('.tourmaster-custom-amount-selection-item'); 233 var dataMin = display.attr('data-min'); 234 var dataMax = display.attr('data-max'); 235 236 function set_amount_selection_label(){ 237 label.html(''); 238 items.each(function(){ 239 var amount_input = $(this).find('input'); 240 var amount_text = $(this).attr('data-label')? $(this).attr('data-label') + ' ': ''; 241 amount_text += amount_input.val(); 242 243 label.append('<span class="tourmaster-space" ></span>'); 244 label.append('<span class="tourmaster-amount" >' + amount_text + '</span>'); 245 }); 246 } 247 248 items.on('click', '.tourmaster-plus, .tourmaster-minus', function(){ 249 var amount_item = $(this).closest('.tourmaster-custom-amount-selection-item'); 250 var amount_text = $(this).siblings('.tourmaster-amount'); 251 var amount_input = amount_item.find('input'); 252 var amount = parseInt(amount_input.val()); 253 254 if( amount_input.attr('name') == 'adult[]' ){ 255 var min = dataMin? dataMin: 1; 256 var max = dataMax? dataMax: 10; 257 }else{ 258 var min = dataMin? dataMin: 0; 259 var max = dataMax? dataMax: 10; 260 } 261 262 if( $(this).hasClass('tourmaster-plus') ){
263 if( amount < max ){ 264 amount_input.val(amount + 1) 265 amount_text.html(amount + 1); 266 amount_input.trigger('change'); 267 set_amount_selection_label(); 268 } 269 }else if( $(this).hasClass('tourmaster-minus') ){ 270 if( amount > min ){ 271 amount_input.val(amount - 1) 272 amount_text.html(amount - 1); 273 amount_input.trigger('change'); 274 set_amount_selection_label(); 275 } 276 } 277 278 }); 279 280 // click display event 281 display.on('click', function(){ 282 display.addClass('tourmaster-active'); 283 option_wrap.fadeIn(150); 284 }); 285 286 // close amount box when clicking outside the element 287 $(document).on('click', function(e){ 288 if( !display.hasClass('tourmaster-active') ) return; 289 if( $(e.target).closest(display).length ) return; 290 if( $(e.target).closest(option_wrap).length ) return; 291 292 display.removeClass('tourmaster-active'); 293 option_wrap.fadeOut(150); 294 }); 295 296 }); // amount selection 297 298 } 299 300 $(document).ready(function(){ 301 302 var body = $('body'); 303 var login_lb = $('[data-tmlb-id="room-proceed-without-login"]'); 304 305 // room review item 306 $('.tourmaster-room-review-item').tourmaster_room_review_item(); 307 308 // search filter 309 body.on('click', '.tourmaster-room-search-tax-wrap .tourmaster-close-filter', function(){ 310 var content_fitler = $(this).parent('.tourmaster-label').siblings('.tourmaster-filter'); 311 312 if( $(this).hasClass('tourmaster-active') ){ 313 $(this).removeClass('tourmaster-active'); 314 content_fitler.slideDown(150); 315 }else{ 316 $(this).addClass('tourmaster-active'); 317 content_fitler.slideUp(150); 318 } 319 }); 320 321 // initiate cart button 322 function removeCartItem(cartButton, index){ 323 var cart_cookie = tourmaster_read_cookie('tourmaster-room-cart'); 324 if( cart_cookie != '' ){ 325 cart_cookie = JSON.parse(cart_cookie); 326 }else{ 327 cart_cookie = []; 328 } 329 cart_cookie.splice(index, 1); 330 tourmaster_set_cookie('tourmaster-room-cart', JSON.stringify(cart_cookie), 31536000); 331 332 cartButton.each(function(){ 333 var cart_wrap = $(this).closest('.tourmaster-room-navigation-checkout-wrap'); 334 var cart_items = $(this).siblings('.tourmaster-room-cart-item-wrap'); 335 $(cart_items.find('li').get(index)).slideUp(50, function(){ $(this).remove(); }); 336 337 if( cart_cookie.length == 0 ){ 338 cart_wrap.removeClass('tourmaster-active'); 339 $(this).html(cart_button.attr('data-label') + '<span class="tourmaster-count">0</span>'); 340 } 341 }); 342 } 343 function clearCartItem(cartButton){ 344 cartButton.each(function(){ 345 $(this).closest('.tourmaster-room-navigation-checkout-wrap').removeClass('tourmaster-active'); 346 $(this).html(cart_button.attr('data-label') + '<span class="tourmaster-count">0</span>'); 347 }); 348 } 349 350 var cart_button = $('.tourmaster-room-navigation-checkout-button').each(function(){ 351 var cart_wrap = $(this).closest('.tourmaster-room-navigation-checkout-wrap'); 352 var cart_items = $(this).siblings('.tourmaster-room-cart-item-wrap'); 353 354 cart_items.on('click', '.tourmaster-remove', function(){ 355 var index = $(this).closest('li').index(); 356 removeCartItem(cart_button, index); 357 }); 358 359 $(this).on('clear', function(){ 360 clearCartItem(cart_button); 361 }); 362 363 $(this).on('click', function(){ 364 if( cart_wrap.hasClass('tourmaster-active') ) return false; 365 }); 366 }); 367 368 // check if login before proceeding 369 if( login_lb.length ){ 370 $('.tourmaster-checkout-button').on('click', function(){ 371 var lb_content = login_lb.clone(); 372 373 // check for social login plugin 374 if( lb_content.find('.nsl-container-block').length > 0 ){ 375 lb_content.find('.nsl-container-block').replaceWith(login_lb.find('.nsl-container-block').clone(true)); 376 } 377 378 // change link ot cart link 379 lb_content.find('input[name="redirect_to"]').each(function(){ 380 $(this).val($(this).val().replace('type=booking', 'type=cart')); 381 }); 382 lb_content.find('.tourmaster-continue-button').each(function(){ 383 $(this).attr('href', $(this).attr('href').replace('type=booking', 'type=cart')); 384 }); 385 lb_content.find('.tourmaster-register-button').each(function(){ 386 $(this).attr('href', $(this).attr('href').replace('redirect=room-payment', 'redirect=room-payment-cart')); 387 }); 388 389 tourmaster_lightbox(lb_content); 390 391 return false; 392 }); 393 } 394 395 396 // change booking tab 397 if( body.hasClass('single-room') ){ 398 399 body.find('.tourmaster-room-booking-bar-wrap').each(function(){ 400 var title_wrap = $(this).find('.tourmaster-room-booking-bar-title'); 401 var content_wrap = $(this).find('.tourmaster-room-booking-bar-content'); 402 403 title_wrap.on('click', '[data-room-tab]', function(){ 404 var tab_id = $(this).attr('data-room-tab'); 405 $(this).addClass('tourmaster-active').siblings().removeClass('tourmaster-active'); 406 407 var target_tab = content_wrap.find('[data-room-tab="' + tab_id + '"]'); 408 target_tab.siblings().hide().removeClass('tourmaster-active'); 409 target_tab.addClass('tourmaster-active').fadeIn(150); 410 }); 411 }); 412 413 body.find('#tourmaster-room-booking-form').each(function(){ 414 415 // change room amount 416 $(this).on('change', 'input[name="room_amount"]', function(){ 417 var room_amount = parseInt($(this).val()); 418 var guest_selection = $(this).closest('.tourmaster-room-amount-selection').siblings('.tourmaster-room-booking-guest-selection'); 419 var current_guest_selection = guest_selection.children().length; 420 421 if( room_amount == 1 ){ 422 guest_selection.addClass('tourmaster-one'); 423 }else{ 424 guest_selection.removeClass('tourmaster-one'); 425 } 426 427 if( current_guest_selection < room_amount ){ 428 for( var i = current_guest_selection + 1; i <= room_amount; i++ ){ 429 var template = guest_selection.children().first().clone(); 430 template.find('.tourmaster-number').html(i); 431 template.css('display', 'none'); 432 guest_selection.append(template); 433 template.slideDown(150); 434 template.tourmaster_room_amount_selection(); 435 } 436 }else{ 437 guest_selection.children().each(function(index){ 438 if( room_amount < index + 1 ){
439 $(this).slideUp(150, function(){ $(this).remove() }); 440 } 441 }); 442 } 443 guest_selection.children().each(function(index){ 444 445 }); 446 var template = guest_selection.children().first(); 447 448 449 }); 450 451 var booking_area = $(this).closest('.tourmaster-room-booking-bar-wrap'); 452 453 // booking summary area 454 function bind_booking_bar_summary(content_area, cart_row, form, input_data){ 455 content_area.find('.tourmaster-go-back').on('click', function(){ 456 content_area.remove(); 457 booking_area.fadeIn(150); 458 }); 459 460 content_area.on('click', '.tourmaster-add-to-cart', function(){ 461 462 // set cookie 463 var cart_cookie = tourmaster_read_cookie('tourmaster-room-cart'); 464 if( cart_cookie != '' ){ 465 cart_cookie = JSON.parse(cart_cookie); 466 }else{ 467 cart_cookie = []; 468 } 469 cart_cookie.push(input_data); 470 tourmaster_set_cookie('tourmaster-room-cart', JSON.stringify(cart_cookie), 31536000); 471 472 var current_time = (new Date()).getTime(); 473 tourmaster_set_cookie('tourmaster-room-current-id', '', current_time); 474 475 // animation 476 $(this).html($(this).attr('data-complete')).addClass('tourmaster-active').css('opacity', 0); 477 $(this).animate({opacity: 1}, {duration: 150}); 478 setTimeout(function(){ 479 content_area.remove(); 480 booking_area.fadeIn(150); 481 }, 2000); 482 483 // add item to cart 484 if( cart_button.length ){ 485 var cart_wrap = cart_button.closest('.tourmaster-room-navigation-checkout-wrap'); 486 var cart_items = cart_button.siblings('.tourmaster-room-cart-item-wrap'); 487 cart_items.find('ul').append(cart_row); 488 cart_wrap.addClass('tourmaster-active'); 489 490 cart_button.find('.tourmaster-count').html(cart_cookie.length); 491 cart_button.html(cart_button.attr('data-checkout-label') + '<span class="tourmaster-count">' + cart_cookie.length + '</span>'); 492 493 } 494 }); 495 496 content_area.on('click', '.tourmaster-checkout', function(){ 497 498 // set cookie 499 var cart_cookie = tourmaster_read_cookie('tourmaster-room-cart'); 500 if( cart_cookie != '' ){ 501 cart_cookie = JSON.parse(cart_cookie); 502 }else{ 503 cart_cookie = []; 504 } 505 cart_cookie.push(input_data); 506 tourmaster_set_cookie('tourmaster-room-cart', JSON.stringify(cart_cookie), 31536000); 507 508 var current_time = (new Date()).getTime(); 509 tourmaster_set_cookie('tourmaster-room-current-id', '', current_time); 510 511 // check if login before proceeding 512 if( login_lb.length ){ 513 var lb_content = login_lb.clone(); 514 515 // check for social login plugin 516 if( lb_content.find('.nsl-container-block').length > 0 ){ 517 lb_content.find('.nsl-container-block').replaceWith(login_lb.find('.nsl-container-block').clone(true)); 518 } 519 520 tourmaster_lightbox(lb_content); 521 522 return false; 523 }else{ 524 window.location.href = form.attr('action'); 525 } 526 527 }); 528 } 529 530 // submit input 531 $(this).on('click', 'input[type="submit"]', function(){ 532 533 var submit_button = $(this); 534 if( submit_button.hasClass('tourmaster-now-loading') ) return false; 535 submit_button.addClass('tourmaster-now-loading'); 536 537 var error = $(this).siblings('.tourmaster-room-booking-submit-error'); 538 error.slideUp(200, function(){ $(this).remove() }); 539 540 var form = $(this).closest('form'); 541 var input_data = tourmaster_get_form_data(form); 542 543 tourmaster_room_booking_ajax(form.attr('data-ajax-url'), { 544 success: function( data ){
545 if( typeof(data) != 'undefined' ){ 546 if( data.status == 'success' ){ 547 booking_area.hide(); 548 549 var content_area = $(data.content).css('display', 'none'); 550 content_area.insertAfter(booking_area); 551 content_area.fadeIn(150); 552 bind_booking_bar_summary(content_area, data.cart_row, form, input_data); 553 }else if( data.status == 'failed' ){ 554 var error_message = $('<div class="tourmaster-room-booking-submit-error" ></div>'); 555 error_message.append(data.message); 556 error_message.css('display', 'none'); 557 error_message.insertBefore(submit_button); 558 error_message.slideDown(150); 559 } 560 561 } 562 563 submit_button.removeClass('tourmaster-now-loading'); 564 } 565 }, { 566 action: form.attr('data-action'), 567 data: input_data 568 }); 569 570 return false; 571 }); 572 573 }); 574 575 } 576 577 // on single room 578 if( body.hasClass('single-room')){ 579 580 $('#tourmaster-enquiry-form').find('.tourmaster-datepicker').each(function(){ 581 var alternate_field = $(this).siblings('.tourmaster-datepicker-alt'); 582 var date_format = $(this).attr('data-date-format'); 583 584 $(this).datepicker({ 585 dateFormat: date_format, 586 altFormat: 'yy-mm-dd', 587 altField: alternate_field, 588 changeMonth: true, 589 changeYear: true 590 }); 591 }); 592 593 // submit booking form 594 $('#tourmaster-enquiry-form').find('input[type="submit"]').click(function(){ 595 if( $(this).hasClass('tourmaster-now-loading') ){ return false; } 596 597 var form = $(this).closest('form'); 598 var form_button = $(this); 599 var message_box = form.find('.tourmaster-enquiry-form-message').not('.tourmaster-enquiry-term-message'); 600 601 var condition_accepted_input = form.find('[name="tourmaster-require-acceptance"]'); 602 if( condition_accepted_input.length && !condition_accepted_input.is(':checked') ){ 603 condition_accepted_input.siblings('.tourmaster-enquiry-form-message').slideDown(150); 604 return false; 605 }else{ 606 condition_accepted_input.siblings('.tourmaster-enquiry-form-message').slideUp(150); 607 } 608 609 var validate = true; 610 form.find('input[data-required], select[data-required], textarea[data-required]').each(function(){ 611 if( !$(this).val() ){ 612 validate = false; 613 } 614 }); 615 616 if( !validate ){ 617 if( form.attr('data-validate-error') ){ 618 message_box.removeClass('tourmaster-success').addClass('tourmaster-failed'); 619 message_box.html(form.attr('data-validate-error')); 620 message_box.slideDown(300); 621 } 622 }else{ 623 624 message_box.slideUp(300); 625 form_button.addClass('tourmaster-now-loading'); 626 627 $.ajax({
628 type: 'POST', 629 url: form.attr('data-ajax-url'), 630 data: { action: form.attr('data-action'), data: tourmaster_get_form_data(form) }, 631 dataType: 'json', 632 error: function( jqXHR, textStatus, errorThrown ){ 633 // print error message for debug purpose 634 console.log(jqXHR, textStatus, errorThrown); 635 }, 636 success: function( data ){ 637 if( typeof(grecaptcha) != 'undefined' ){ 638 form.find('#g-recaptcha-response').val('gdlr-verfied'); 639 } 640 641 form_button.removeClass('tourmaster-now-loading'); 642 643 if( typeof(data.message) != 'undefined' ){ 644 if( data.status == 'success' ){ 645 form.find('input[name], textarea[name], select[name]').not('[name="tour-id"]').val(''); 646 message_box.removeClass('tourmaster-failed').addClass('tourmaster-success'); 647 }else{ 648 message_box.removeClass('tourmaster-success').addClass('tourmaster-failed'); 649 } 650 651 message_box.html(data.message); 652 message_box.slideDown(300); 653 } 654 655 } 656 }); 657 } 658 659 return false; 660 }); 661 662 // single review 663 $('#tourmaster-room-single-review').tourmaster_room_single_review(); 664 } 665 666 // amount selection 667 $('.tourmaster-room-amount-selection').tourmaster_room_amount_selection(); 668 669 670 // custom datepicker 671 $('.tourmaster-custom-datepicker-wrap').each(function(){ 672 673 var dp_wrap = $(this); 674 var dp_parent = dp_wrap.closest('.tourmaster-room-date-selection'); 675 var start_date_wrap = dp_wrap.siblings('.tourmaster-custom-start-date'); 676 var start_date_input = start_date_wrap.find('[name="start_date"]'); 677 var start_date_label = start_date_wrap.find('.tourmaster-tail'); 678 var end_date_wrap = dp_wrap.siblings('.tourmaster-custom-end-date'); 679 var end_date_input = end_date_wrap.find('[name="end_date"]'); 680 var end_date_label = end_date_wrap.find('.tourmaster-tail'); 681 682 var step = 1; 683 var date_format = dp_wrap.attr('data-date-format'); 684 685 var start_date = start_date_input.val()? new Date(start_date_input.val() + 'T00:00:00'): ''; 686 var end_date = end_date_input.val()? new Date(end_date_input.val() + 'T00:00:00'): ''; 687 688 var min_night_stay = 1; 689 if( typeof(tourmaster_min_night_stay) !== 'undefined' ){ 690 min_night_stay = tourmaster_min_night_stay; 691 } 692 693 var selected_checkin_date = ''; 694 var selected_checkout_date = ''; 695 696 function get_night_amount(date, type = 'min'){ 697 for( var i in tourmaster_night_settings ){ 698 if( tourmaster_night_settings[i].date_list.indexOf(date) >= 0 ){ 699 if( type == 'min' ){ 700 return tourmaster_night_settings[i].min_night; 701 }else if( type == 'all' ){ 702 return { 703 min: tourmaster_night_settings[i].min_night, 704 max: tourmaster_night_settings[i].max_night 705 } 706 } 707 } 708 } 709 710 if( type == 'min' ){ 711 return min_night_stay; 712 }else if( type == 'all' ){ 713 return { 714 min: min_night_stay, 715 max: 0 716 } 717 } 718 } 719 function get_checkout_date(checkin_date){ 720 721 var n = get_night_amount(checkin_date, 'all'); 722 var temp_date = new Date(checkin_date + 'T00:00:00'); 723 724 var min_night = parseInt(n.min); 725 var max_night = parseInt(n.max); 726 var c_night = min_night; 727 if( min_night == 0 ){ 728 min_night = 1; 729 } 730 if( max_night == 0 ){ 731 max_night = 9999; 732 } 733 734 temp_date.setTime(temp_date.getTime() + (min_night * 86400000)); 735 var first_checkout_date = $.datepicker.formatDate('yy-mm-dd', temp_date); 736 while( c_night < max_night && tourmaster_avail_date.indexOf($.datepicker.formatDate('yy-mm-dd', temp_date)) >= 0 ){ 737 temp_date.setTime(temp_date.getTime() + 86400000); 738 c_night++; 739 } 740 var last_checkout_date = $.datepicker.formatDate('yy-mm-dd', temp_date); 741 742 return { 743 'first': first_checkout_date, 744 'last': last_checkout_date, 745 'first_time': (new Date(first_checkout_date + 'T00:00:00')).getTime(), 746 'last_time': (new Date(last_checkout_date + 'T00:00:00')).getTime(), 747 }; 748 } 749 750 if( typeof(tourmaster_avail_date) !== 'undefined' ){ 751 var avail_date = tourmaster_avail_date.split(','); 752 var min_date = new Date(avail_date[0] + 'T00:00:00'); 753 var max_date = new Date(avail_date[avail_date.length-1] + 'T00:00:00'); 754 755 // determine the date available for check in 756 var check_in_date_list = [];
757 for( var d in avail_date ){ 758 759 // check min night 760 var m = parseInt(get_night_amount(avail_date[d])); 761 if( m <= 1 ){ 762 check_in_date_list.push(avail_date[d]); 763 }else{ 764 var temp_date = new Date(avail_date[d] + 'T00:00:00'); 765 766 var stay_date = avail_date[d]; 767 for( var i = 0; i < m - 1; i++ ){ 768 temp_date.setTime(temp_date.getTime() + 86400000); 769 stay_date = stay_date + ',' + $.datepicker.formatDate('yy-mm-dd', temp_date); 770 } 771 if( tourmaster_avail_date.indexOf(stay_date) >= 0 ){ 772 check_in_date_list.push(avail_date[d]); 773 } 774 } 775 } 776 777 // check initial start & end date 778 if( !start_date_input.val() || check_in_date_list.indexOf(start_date_input.val()) < 0 ){ 779 start_date_input.val(check_in_date_list[0]); 780 start_date = new Date(check_in_date_list[0] + 'T00:00:00'); 781 start_date_label.html($.datepicker.formatDate(date_format, start_date)); 782 } 783 784 selected_checkin_date = start_date_input.val(); 785 selected_checkout_date = get_checkout_date(selected_checkin_date); 786 787 if( end_date_input.val() && 788 (end_date.getTime() < selected_checkout_date.first_time || 789 end_date.getTime() > selected_checkout_date.last_time) ){ 790 end_date_input.val(selected_checkout_date.first); 791 end_date = new Date(selected_checkout_date.first + 'T00:00:00'); 792 end_date_label.html($.datepicker.formatDate(date_format, end_date)); 793 } 794 }else{ 795 var avail_date = false; 796 797 if( dp_parent.attr('data-current-date') ){ 798 var min_date = new Date(dp_parent.attr('data-current-date') + 'T00:00:00'); 799 }else{ 800 var min_date = new Date(); 801 } 802 var max_date = undefined; 803 } 804 805 var dp_title = $(this).children('.tourmaster-custom-datepicker-title'); 806 var dp_val; 807 if( start_date && end_date ){ 808 dp_val = { 809 'start_date': $.datepicker.formatDate('yy-mm-dd', start_date), 810 'start_label': $.datepicker.formatDate(date_format, start_date), 811 'end_date': $.datepicker.formatDate('yy-mm-dd', end_date), 812 'end_label': $.datepicker.formatDate(date_format, end_date) 813 }; 814 }else{ 815 dp_val = { 816 'start_date': '', 817 'start_label': '', 818 'end_date': '', 819 'end_label': '' 820 }; 821 } 822 823 function set_dp_title(){ 824 dp_title.html(dp_val.start_label + ' - ' + dp_val.end_label); 825 } 826 function close_dp(){ 827 dp_parent.removeClass('tourmaster-active'); 828 dp_wrap.fadeOut(150); 829 } 830 function set_dp_location(){ 831 dp_wrap.css({ 'right': '', 'left': '' }); 832 833 if( dp_parent.is('.tourmaster-vertical, .tourmaster-mobile') ){ 834 if( step == 1 ){ 835 dp_wrap.css('top', start_date_wrap.outerHeight()); 836 }else if( step == 2 ){ 837 dp_wrap.css('top', ''); 838 } 839 }else{ 840 dp_wrap.css('top', ''); 841 } 842 843 // check left position 844 if( dp_wrap.offset().left + dp_wrap.outerWidth() > $(window).width() ){ 845 dp_wrap.css({ 'right': '0', 'left': 'auto' });
846 } 847 } 848 849 // initiate calendar 850 var number_of_months = dp_parent.hasClass('tourmaster-horizontal')? 2: 1; 851 var dp = dp_wrap.find('.tourmaster-custom-datepicker-calendar').datepicker({ 852 numberOfMonths: number_of_months, 853 stepMonths: 1, 854 minDate: min_date, 855 maxDate: max_date, 856 defaultDate: start_date, 857 changeMonth: true, 858 changeYear: true, 859 860 // determine selectable date 861 beforeShowDay: function(date){ 862 863 var tmp_date = date.getFullYear() + '-'; 864 tmp_date += ('0' +(date.getMonth() + 1)).slice(-2) + '-'; 865 tmp_date += ('0' + date.getDate()).slice(-2); 866 867 var selectable = true; 868 869 if( step == 1 ){ 870 871 if( avail_date && check_in_date_list.indexOf(tmp_date) < 0 ){ 872 selectable = false; 873 } 874 875 if( start_date && end_date ){ 876 if( date.getTime() == start_date.getTime() ){ 877 return [selectable, 'tourmaster-start', '']; 878 }else if( date.getTime() == end_date.getTime() ){ 879 return [selectable, 'tourmaster-end', '']; 880 }else if( date.getTime() > start_date.getTime() && date.getTime() < end_date.getTime() ){ 881 return [selectable, 'tourmaster-interval', '']; 882 } 883 } 884 885 }else if( step == 2 ){ 886 887 if( avail_date ){ 888 if( selected_checkin_date != start_date_input.val() ){ 889 selected_checkin_date = start_date_input.val(); 890 selected_checkout_date = get_checkout_date(selected_checkin_date); 891 } 892 893 if( date.getTime() < selected_checkout_date.first_time || 894 date.getTime() > selected_checkout_date.last_time ){ 895 selectable = false; 896 } 897 } 898 899 if( date.getTime() < start_date.getTime() ){ 900 return [false, '', '']; 901 }else if( date.getTime() == start_date.getTime() ){ 902 return [false, 'tourmaster-start', '']; 903 }else if( date.getTime() == end_date.getTime() ){ 904 return [selectable, 'tourmaster-end', '']; 905 }else if( date.getTime() > start_date.getTime() && date.getTime() < end_date.getTime() ){ 906 return [selectable, 'tourmaster-interval', '']; 907 } 908 909 } 910 911 return [selectable, '', '']; 912 }, 913 914 // for date range 915 onSelect: function( dateText, inst ){ 916 var selected_date = inst.selectedYear + '-'; 917 selected_date += ('0' +(inst.selectedMonth + 1)).slice(-2) + '-'; 918 selected_date += ('0' + inst.selectedDay).slice(-2); 919 920 // start date 921 if( step == 1 ){ 922 923 // checkin date 924 start_date = new Date(selected_date + 'T00:00:00'); 925 dp_val.start_date = $.datepicker.formatDate('yy-mm-dd', start_date) 926 dp_val.start_label = $.datepicker.formatDate(date_format, start_date); 927 start_date_input.val(dp_val.start_date); 928 start_date_label.html(dp_val.start_label); 929 930 // checkout date 931 if( avail_date ){ 932 if( selected_checkin_date != start_date_input.val() ){ 933 selected_checkin_date = start_date_input.val(); 934 selected_checkout_date = get_checkout_date(selected_checkin_date); 935 } 936 end_date = new Date(selected_checkout_date.first + 'T00:00:00'); 937 }else{ 938 end_date = new Date(start_date.getTime() + 86400000 * min_night_stay); 939 } 940 dp_val.end_date = $.datepicker.formatDate('yy-mm-dd', end_date); 941 dp_val.end_label = $.datepicker.formatDate(date_format, end_date); 942 end_date_input.val(dp_val.end_date); 943 end_date_label.html(dp_val.end_label); 944 945 step = 2; 946 set_dp_location(); 947 948 // end date 949 }else if( step == 2 ){ 950 end_date = new Date(selected_date + 'T00:00:00'); 951 dp_val.end_date = $.datepicker.formatDate('yy-mm-dd', end_date); 952 dp_val.end_label = $.datepicker.formatDate(date_format, end_date); 953 end_date_input.val(dp_val.end_date); 954 end_date_label.html(dp_val.end_label); 955 956 step = 1; 957 958 if( dp_parent.is('.tourmaster-vertical, .tourmaster-mobile') ){ 959 close_dp(); 960 } 961 } 962 963 dp_parent.addClass('tourmaster-selected'); 964 dp_parent.attr('data-step', step); 965 set_dp_title(); 966 }, 967 968 }); // tourmaster-custom-datepicker-wrap 969 set_dp_title(); 970 971 // click display event 972 dp_wrap.siblings('.tourmaster-custom-start-date').on('click', function(){ 973 step = 1; 974 dp_parent.addClass('tourmaster-active'); 975 dp_wrap.fadeIn(150); 976 dp_parent.attr('data-step', step); 977 set_dp_location(); 978 979 dp.datepicker('refresh'); 980 }); 981 dp_wrap.siblings('.tourmaster-custom-end-date').on('click', function(){ 982 step = 2; 983 dp_parent.addClass('tourmaster-active'); 984 dp_wrap.fadeIn(150); 985 dp_parent.attr('data-step', step); 986 set_dp_location(); 987 988 dp.datepicker('refresh'); 989 }); 990 991 // close datepicker when clicking outside the element 992 dp_wrap.on('click', '.tourmaster-custom-datepicker-close', function(){ 993 close_dp(); 994 }); 995 $(document).on('click', function(e){
996 if( !dp_parent.hasClass('tourmaster-active') ) return; 997 if( $(e.target).is('.ui-datepicker-prev, .ui-datepicker-next') ) return; 998 if( !$(e.target).closest('.tourmaster-custom-start-date, .tourmaster-custom-end-date, .tourmaster-custom-datepicker-wrap').length ){ 999 close_dp(); 1000 } 1001 }); 1002 1003 // resize action 1004 $(window).on('load resize', function(){ 1005 if( dp_parent.hasClass('tourmaster-horizontal') ){ 1006 if( tourmaster_mobile || tourmaster_display == 'mobile-landscape' || tourmaster_display == 'mobile-portrait' ){ 1007 if( !dp_parent.hasClass('tourmaster-mobile') ){ 1008 dp_parent.addClass('tourmaster-mobile'); 1009 dp.datepicker('option', 'numberOfMonths', 1); 1010 } 1011 }else{ 1012 if( dp_parent.hasClass('tourmaster-mobile') ){ 1013 dp_parent.removeClass('tourmaster-mobile'); 1014 dp.datepicker('option', 'numberOfMonths', number_of_months); 1015 } 1016 } 1017 } 1018 1019 }); 1020 }); // custom datepicker. 1021 1022 // payment only page 1023 $('#tourmaster-room-payment-display-page').each(function(){ 1024 1025 var payment_page = $(this); 1026 1027 var step_wrap = $(this).find('.tourmaster-room-payment-step'); 1028 var step3_wrap = payment_page.find('#tourmaster-step3-wrap'); 1029 var step4_wrap = payment_page.find('#tourmaster-step4-wrap'); 1030 1031 var price_sidebar = $(this).find('.tourmaster-room-price-sidebar'); 1032 var pay_full_amount = true; 1033 1034 function change_step( step ){ 1035 step_wrap.attr('data-step', step); 1036 step_wrap.children().removeClass('tourmaster-active'); 1037 step_wrap.children().slice(0, step).addClass('tourmaster-active'); 1038 } 1039 function display_errors(elem, message){ 1040 var error_html = $('<div class="tourmaster-error-message" ></div>').html(message); 1041 error_html.insertBefore(elem); 1042 error_html.slideDown(150); 1043 } 1044 1045 // select type 1046 price_sidebar.on('click', '.tourmaster-room-pay-type-item', function(){ 1047 var deposit_amount_wrap = $(this).closest('.tourmaster-room-pay-type').siblings('.tourmaster-deposit-amount'); 1048 $(this).addClass('tourmaster-active').siblings().removeClass('tourmaster-active'); 1049 1050 if( $(this).hasClass('tourmaster-deposit') ){ 1051 pay_full_amount = false; 1052 deposit_amount_wrap.slideDown(150); 1053 if( typeof(window.tourmaster_payment_type) !== 'undefined' ){ 1054 window.tourmaster_payment_type = 'partial'; 1055 window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_deposit_amount; 1056 } 1057 }else if( $(this).hasClass('tourmaster-full') ){ 1058 pay_full_amount = true; 1059 deposit_amount_wrap.slideUp(150); 1060 if( typeof(window.tourmaster_payment_type) !== 'undefined' ){ 1061 window.tourmaster_payment_type = 'full'; 1062 window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_full_amount; 1063 } 1064 } 1065 }); 1066 price_sidebar.find('.tourmaster-room-pay-type-item.tourmaster-active').trigger('click'); 1067 1068 // pay now 1069 price_sidebar.on('click', '.tourmaster-pay-now', function(){ 1070 1071 $(this).siblings('.tourmaster-error-message').slideUp(150, function(){ $(this).remove(); }); 1072 1073 var term_service = price_sidebar.find('[name="term-and-service"]'); 1074 if( term_service.length ){ 1075 if( !term_service.is(':checked') ){ 1076 display_errors($(this), term_service.attr('data-error')); 1077 return; 1078 } 1079 } 1080 1081 var payment_method = $(this).closest('.tourmaster-room-payment-method-wrap').find('.tourmaster-payment-selection').val(); 1082 1083 // pay for the room 1084 if( $(this).hasClass('tourmaster-now-loading') ) return; 1085 $(this).addClass('tourmaster-now-loading'); 1086 1087 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1088 success: function(data){ 1089 if( payment_method == 'paypal' && data.payment_content ){ 1090 body.append(data.payment_content); 1091 }else if( data.payment_content ){ 1092 var content = $('<div class="tourmaster-room-payment-lb" ></div>').html(data.payment_content); 1093 tourmaster_lightbox(content); 1094 1095 content.on('payment_complete', function(){ 1096 step3_wrap.hide(); 1097 step4_wrap.fadeIn(150); 1098 change_step(4); 1099 1100 var current_time = (new Date()).getTime(); 1101 tourmaster_set_cookie('tourmaster-room-current-id', '', current_time); 1102 1103 $(this).closest('.tourmaster-lightbox-wrapper').trigger('lightbox_close'); 1104 }); 1105 } 1106 $(this).removeClass('tourmaster-now-loading'); 1107 } 1108 }, { 1109 action: 'tourmaster_room_payd_now', 1110 'tid': payment_page.attr('data-tid'), 1111 'pay_full_amount': pay_full_amount, 1112 'payment_method': payment_method 1113 }); 1114 }); 1115 1116 // pay woocommerce 1117 step3_wrap.on('click', '.tourmaster-pay-woocommerce', function(){ 1118 1119 $(this).siblings('.tourmaster-error-message').slideUp(1
111950, function(){ $(this).remove(); }); 1120 1121 var term_service = step3_wrap.find('[name="term-and-service"]'); 1122 if( term_service.length ){ 1123 if( !term_service.is(':checked') ){ 1124 display_errors($(this), term_service.attr('data-error')); 1125 return; 1126 } 1127 } 1128 1129 // book the room 1130 if( $(this).hasClass('tourmaster-now-loading') ) return; 1131 $(this).addClass('tourmaster-now-loading'); 1132 1133 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1134 success: function(data){ 1135 // do something here 1136 if( typeof(data.redirect_url) != 'undefined' ){ 1137 window.location.replace(data.redirect_url); 1138 } 1139 1140 $(this).removeClass('tourmaster-now-loading'); 1141 } 1142 }, { 1143 action: 'tourmaster_room_payd_woocommerce', 1144 'tid': payment_page.attr('data-tid'), 1145 }); 1146 }); 1147 1148 // paypal 1149 if( typeof(paypal) !== 'undefined' ){ 1150 var paypal_button = step3_wrap.find('#paypal-button-container'); 1151 paypal.Buttons({ 1152 createOrder: (data, actions) => { 1153 1154 paypal_button.siblings('.tourmaster-error-message').slideUp(150, function(){ $(this).remove(); }); 1155 1156 var term_service = step3_wrap.find('[name="term-and-service"]'); 1157 if( term_service.length ){ 1158 if( !term_service.is(':checked') ){ 1159 display_errors(paypal_button, term_service.attr('data-error')); 1160 return false; 1161 } 1162 } 1163 1164 return actions.order.create({ 1165 purchase_units: [{ 1166 amount: { 1167 currency_code: window.tourmaster_paypal_currency_code, 1168 value: window.tourmaster_paypal_pay_amount 1169 } 1170 }] 1171 }); 1172 }, 1173 onApprove: (data, actions) => { 1174 return actions.order.capture().then(function(orderData) { 1175 step3_wrap.animate({opacity: 0.5}); 1176 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1177 success: function(data){ 1178 step3_wrap.hide(); 1179 step4_wrap.fadeIn(150); 1180 change_step(4); 1181 1182 // clear cart 1183 clear_cart(); 1184 } 1185 }, { 1186 action: 'tourmaster_room_payd_now', 1187 'tid': payment_page.attr('data-tid'), 1188 'order_data': orderData, 1189 'pay_full_amount': pay_full_amount, 1190 'payment_method': 'paypal' 1191 }); 1192 }); 1193 } 1194 1195 }).render('#paypal-button-container'); 1196 } 1197 1198 }); 1199 1200 // cart item 1201 $('.tourmaster-room-cart-item').each(function(){ 1202 1203 // remove room 1204 $(this).on('click', '.tourmaster-room-remove-room', function(){ 1205 var service_form = $(this).closest('.tourmaster-room-service-form'); 1206 var i = $(this).attr('data-i'); 1207 var j = $(this).attr('data-j'); 1208 1209 tourmaster_front_confirm_box({ 1210 head: service_form.attr('data-remove-head'), 1211 text: service_form.attr('data-remove-text'), 1212 sub: service_form.attr('data-remove-sub'), 1213 yes: service_form.attr('data-remove-yes'), 1214 no: service_form.attr('data-remove-no'), 1215 success: function(){ 1216 var bd = tourmaster_read_cookie('tourmaster-room-cart'); 1217 bd = JSON.parse(bd); 1218 1219 if( parseInt(bd[i]['room_amount']) <= 1 ){ 1220 bd.splice(i, 1); 1221 }else{ 1222 bd[i]['room_amount'] = parseInt(bd[i]['room_amount']) - 1; 1223 bd[i]['adult'].splice(j, 1); 1224 bd[i]['children'].splice(j, 1); 1225 } 1226 1227 tourmaster_set_cookie('tourmaster-room-cart', JSON.stringify(bd), 31536000); 1228 1229 window.location.reload(); 1230 } 1231 }); 1232 1233 return false; 1234 }); 1235 1236 // price beakdown 1237 $(this).on('click', '.tourmaster-price-breakdown-title', function(){ 1238 var content = $(this).find('.tourmaster-room-single-price-breakdown'); 1239 tourmaster_lightbox(content.clone()); 1240 }); 1241 1242 }); 1243 1244 // if on room payment page 1245 $('#tourmaster-room-payment-page').each(function(){ 1246 var payment_page = $(this); 1247 var step_wrap = $(this).find('.tourmaster-room-payment-step'); 1248 var step2_wrap = payment_page.find('#tourmaster-step2-wrap'); 1249 var step3_wrap = payment_page.find('#tourmaster-step3-wrap'); 1250 var step4_wrap = payment_page.find('#tourmaster-step4-wrap'); 1251 1252 var service_form = payment_page.find('.tourmaster-room-service-form'); 1253 var price_sidebar = $(this).find('.tourmaster-room-price-sidebar-wrap'); 1254 1255 var booking_details = JSON.parse(payment_page.attr('data-booking-details')); 1256 var last_coupon_code = ''; 1257 1258 var pay_full_amount = true; 1259 1260 function change_step( step ){ 1261 step_wrap.attr('data-step', step); 1262 step_wrap.children().removeClass('tourmaster-active'); 1263 step_wrap.children().slice(0, step).addClass('tourmaster-active'); 1264 1265 if( step == 3 ){ 1266 if( typeof(paypal) !== 'undefined' ){ 1267 var paypal_button = step3_wrap.find('#paypal-button-container'); 1268 paypal.Buttons({ 1269 createOrder: (data, actions) => { 1270 1271 paypal_button.siblings('.tourmaster-error-message').slideUp(1
127150, function(){ $(this).remove(); }); 1272 1273 var term_service = step3_wrap.find('[name="term-and-service"]'); 1274 if( term_service.length ){ 1275 if( !term_service.is(':checked') ){ 1276 display_errors(paypal_button, term_service.attr('data-error')); 1277 return false; 1278 } 1279 } 1280 1281 var error = validate_contact_form(); 1282 if( error ){ 1283 display_errors(paypal_button, error); 1284 return false; 1285 } 1286 1287 return actions.order.create({ 1288 purchase_units: [{ 1289 amount: { 1290 currency_code: window.tourmaster_paypal_currency_code, 1291 value: window.tourmaster_paypal_pay_amount 1292 } 1293 }] 1294 }); 1295 }, 1296 onApprove: (data, actions) => { 1297 return actions.order.capture().then(function(orderData) { 1298 step3_wrap.animate({opacity: 0.5}); 1299 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1300 success: function(data){ 1301 step3_wrap.hide(); 1302 step4_wrap.fadeIn(150); 1303 change_step(4); 1304 1305 // clear cart 1306 clear_cart(); 1307 } 1308 }, { 1309 action: 'tourmaster_room_pay_now', 1310 data: get_booking_data(), 1311 'order_data': orderData, 1312 'pay_full_amount': pay_full_amount, 1313 'payment_method': 'paypal' 1314 }); 1315 }); 1316 } 1317 1318 }).render('#paypal-button-container'); 1319 } 1320 } 1321 } 1322 1323 // step 2 1324 // remove booking 1325 service_form.on('click', '.tourmaster-room-remove-room', function(){ 1326 var i = $(this).attr('data-i'); 1327 var j = $(this).attr('data-j'); 1328 1329 tourmaster_front_confirm_box({ 1330 head: service_form.attr('data-remove-head'), 1331 text: service_form.attr('data-remove-text'), 1332 sub: service_form.attr('data-remove-sub'), 1333 yes: service_form.attr('data-remove-yes'), 1334 no: service_form.attr('data-remove-no'), 1335 success: function(){ 1336 if( payment_page.attr('data-type') == 'cart' ){ 1337 var bd = tourmaster_read_cookie('tourmaster-room-cart'); 1338 bd = JSON.parse(bd); 1339 1340 if( parseInt(bd[i]['room_amount']) <= 1 ){ 1341 bd.splice(i, 1); 1342 }else{ 1343 bd[i]['room_amount'] = parseInt(bd[i]['room_amount']) - 1; 1344 bd[i]['adult'].splice(j, 1); 1345 bd[i]['children'].splice(j, 1); 1346 } 1347 1348 tourmaster_set_cookie('tourmaster-room-cart', JSON.stringify(bd), 31536000); 1349 }else{ 1350 tourmaster_set_cookie('tourmaster-room-booking-detail', '', 31536000); 1351 } 1352 1353 window.location.reload(); 1354 } 1355 }); 1356 1357 return false; 1358 }); 1359 1360 // service selection 1361 function set_service_input(checkbox, input_box){ 1362 if( checkbox.is(':checked') ){ 1363 input_box.val(1); 1364 if( input_box.is('[type="text"]') ){ 1365 input_box.prop('disabled', false); 1366 } 1367 }else{ 1368 input_box.val(''); 1369 if( input_box.is('[type="text"]') ){ 1370 input_box.prop('disabled', true); 1371 } 1372 } 1373 } 1374 service_form.find('input[type="checkbox"]').each(function(){ 1375 var checkbox = $(this); 1376 var input_box = $(this).closest('.tourmaster-service').find('input[type="text"], input[type="hidden"]'); 1377 set_service_input(checkbox, input_box); 1378 }); 1379 service_form.on('change', 'input[type="checkbox"]', function(){ 1380 var checkbox = $(this); 1381 var input_box = $(this).closest('.tourmaster-service').find('input[type="text"], input[type="hidden"]'); 1382 set_service_input(checkbox, input_box); 1383 }); 1384 service_form.on('change', tourmaster_debounce(function(){ 1385 var form_data = tourmaster_get_form_data(service_form); 1386 1387 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1388 success: function(data){ 1389 1390 // update price sidebar 1391 if( data.price_sidebar ){ 1392 var price_sidebar_content = $(data.price_sidebar); 1393 price_sidebar_content.find('.tourmaster-room-coupon-code').val(last_coupon_code); 1394 price_sidebar.children('.tourmaster-room-price-sidebar').replaceWith(price_sidebar_content); 1395 } 1396 1397 // update service price 1398 if( data.service_prices ){ 1399 var i = 0, j = 0; 1400 service_form.find('.tourmaster-room-price-summary-block').each(function(){ 1401 $(this).find('.tourmaster-service-total .tourmaster-tail').each(function(){ 1402 if( data.service_prices[i][j] ){ 1403 $(this).html(data.service_prices[i][j]); 1404 } 1405 j++; 1406 }); 1407 1408 i++; j = 0; 1409 }); 1410 } 1411 1412 } 1413 }, { 1414 action: 'tourmaster_room_service_selected', 1415 data: { 1416 'services': form_data['service'], 1417 'booking_details': booking_details 1418 } 1419 }); 1420 1421 }, 1000)); 1422 1423 // checking coupon 1424 price_sidebar.on('input change', '.tourmaster-room-coupon-code', tourmaster_debounce(function(e){
1425 var coupon_input = $(this); 1426 var coupon_code = coupon_input.val(); 1427 if( coupon_code == last_coupon_code ) return; 1428 1429 last_coupon_code = coupon_code; 1430 if( coupon_code == '' ) return; 1431 1432 coupon_input.siblings('.tourmaster-message').fadeOut(100, function(){ $(this).remove(); }); 1433 1434 if( coupon_code ){ 1435 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1436 success: function(data){ 1437 var message = $('<div class="tourmaster-message" ></div>').html(data.message).css('display', 'none'); 1438 message.insertAfter(coupon_input); 1439 message.fadeIn(100); 1440 } 1441 }, { 1442 action: 'tourmaster_room_check_coupon_code', 1443 data: { 'coupon_code': coupon_code } 1444 }); 1445 } 1446 }, 1000)); 1447 1448 // price breakdown 1449 step2_wrap.on('click', '.tourmaster-price-breakdown-title', function(){ 1450 var content = $(this).find('.tourmaster-room-single-price-breakdown'); 1451 tourmaster_lightbox(content.clone()); 1452 }); 1453 1454 // go to step 3 1455 price_sidebar.on('click', '.tourmaster-step2-checkout', function(){ 1456 var payment_button = $(this); 1457 if( payment_button.hasClass('tourmaster-now-loading') ) return; 1458 payment_button.addClass('tourmaster-now-loading'); 1459 1460 var service_form_data = tourmaster_get_form_data(service_form); 1461 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1462 success: function(data){ 1463 step2_wrap.hide(); 1464 step3_wrap.fadeIn(150); 1465 step3_wrap.find('.tourmaster-room-sidebar-summary-wrap').html(data.price_sidebar); 1466 change_step(3); 1467 step3_wrap.find('.tourmaster-room-pay-type-item.tourmaster-active').trigger('click'); 1468 } 1469 }, { 1470 action: 'tourmaster_room_checkout_step', 1471 data: { 1472 'coupon_code': price_sidebar.find('.tourmaster-room-coupon-code').val(), 1473 'services': service_form_data['service'], 1474 'booking_details': booking_details, 1475 } 1476 }); 1477 }); 1478 1479 // step 3 1480 var contact_form = step3_wrap.find('.tourmaster-room-contact-detail-wrap'); 1481 1482 function display_errors(elem, message){ 1483 var error_html = $('<div class="tourmaster-error-message" ></div>').html(message); 1484 error_html.insertBefore(elem); 1485 error_html.slideDown(150); 1486 } 1487 function get_booking_data(){ 1488 var service_form_data = tourmaster_get_form_data(service_form); 1489 var contact_info = tourmaster_get_form_data(contact_form); 1490 var required_billing = contact_form.find('.tourmaster-payment-billing-separate').is(':checked'); 1491 1492 contact_info['required-billing'] = required_billing; 1493 1494 return { 1495 'coupon_code': price_sidebar.find('.tourmaster-room-coupon-code').val(), 1496 'services': service_form_data['service'], 1497 'booking_details': booking_details, 1498 'contact_info': contact_info 1499 } 1500 } 1501 function validate_contact_form(){ 1502 1503 // validate required fields 1504 var error = false; 1505 var required_billing = contact_form.find('.tourmaster-payment-billing-separate').is(':checked'); 1506 contact_form.find('input[data-required], select[data-required], textarea[data-required]').each(function(){ 1507 if( !required_billing && $(this).is('[name^="billing_"]') ) return; 1508 if( !$(this).val() ){ 1509 error = step3_wrap.attr('data-required-error'); 1510 }else if( $(this).is('[type="email"]') ){ 1511 var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; 1512 if( !re.test($(this).val().toLowerCase()) ){ 1513 error = step3_wrap.attr('data-email-error'); 1514 } 1515 }else if( $(this).is('[name="phone"], [name="billing_phone"]') ){ 1516 var re = /^[\d\+\-\s\(\)\.]*$/; 1517 if( !re.test($(this).val().toLowerCase()) ){ 1518 error = step3_wrap.attr('data-phone-error'); 1519 } 1520 } 1521 }); 1522 1523 return error; 1524 } 1525 function clear_cart(){ 1526 var current_time = (new Date()).getTime(); 1527 if( payment_page.attr('data-type') == 'cart' ){ 1528 tourmaster_set_cookie('tourmaster-room-cart', '', current_time); 1529 } 1530 tourmaster_set_cookie('tourmaster-room-booking-detail', '', current_time); 1531 tourmaster_set_cookie('tourmaster-room-current-id', '', current_time); 1532 cart_button.trigger('clear'); 1533 } 1534 1535 step3_wrap.on('change', '.tourmaster-payment-billing-separate', function(){ 1536 var billing_wrap = $(this).closest('.tourmaster-payment-billing-separate-wrap').siblings('.tourmaster-room-payment-billing-wrap'); 1537 1538 if( $(this).is(':checked') ){ 1539 billing_wrap.slideDown(300); 1540 }else{ 1541 billing_wrap.slideUp(300); 1542 } 1543 }); 1544 1545 step3_wrap.on('click', '.tourmaster-room-pay-type-item', function(){ 1546 var deposit_amount_wrap = $(this).closest('.tourmaster-room-pay-type').siblings('.tourmaster-deposit-amount'); 1547 $(this).addClass('tourmaster-active').siblings().removeClass('tourmaster-active'); 1548 1549 if( $(this).hasClass('tourmaster-deposit') ){ 1550 pay_full_amount = false; 1551 deposit_amount_wrap.slideDown(150); 1552 if( typeof(window.tourmaster_payment_type) !== 'undefined' ){ 1553 window.tourmaster_payment_type = 'partial'; 1554 window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_deposit_amount; 1555 } 1556 }else if( $(this).hasClass('tourmaster-full') ){ 1557 pay_full_amount = true;
1558 deposit_amount_wrap.slideUp(150); 1559 if( typeof(window.tourmaster_payment_type) !== 'undefined' ){ 1560 window.tourmaster_payment_type = 'full'; 1561 window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_full_amount; 1562 } 1563 } 1564 }); 1565 1566 // book and pay later 1567 step3_wrap.on('click', '.tourmaster-pay-later', function(){ 1568 1569 $(this).siblings('.tourmaster-error-message').slideUp(150, function(){ $(this).remove(); }); 1570 1571 var term_service = step3_wrap.find('[name="term-and-service"]'); 1572 if( term_service.length ){ 1573 if( !term_service.is(':checked') ){ 1574 display_errors($(this), term_service.attr('data-error')); 1575 return; 1576 } 1577 } 1578 1579 var error = validate_contact_form(); 1580 if( error ){ 1581 display_errors($(this), error); 1582 return false; 1583 } 1584 1585 // book the room 1586 if( $(this).hasClass('tourmaster-now-loading') ) return; 1587 $(this).addClass('tourmaster-now-loading'); 1588 1589 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1590 success: function(data){ 1591 step3_wrap.hide(); 1592 step4_wrap.fadeIn(150); 1593 change_step(4); 1594 1595 $(this).removeClass('tourmaster-now-loading'); 1596 1597 // clear cart 1598 clear_cart(); 1599 } 1600 }, { 1601 action: 'tourmaster_room_pay_later', 1602 data: get_booking_data() 1603 }); 1604 }); 1605 1606 // pay now 1607 step3_wrap.on('click', '.tourmaster-pay-now', function(){ 1608 1609 $(this).siblings('.tourmaster-error-message').slideUp(150, function(){ $(this).remove(); }); 1610 1611 var term_service = step3_wrap.find('[name="term-and-service"]'); 1612 if( term_service.length ){ 1613 if( !term_service.is(':checked') ){ 1614 display_errors($(this), term_service.attr('data-error')); 1615 return; 1616 } 1617 } 1618 1619 var error = validate_contact_form(); 1620 if( error ){ 1621 display_errors($(this), error); 1622 return false; 1623 } 1624 1625 var payment_method = $(this).closest('.tourmaster-room-payment-method-wrap').find('.tourmaster-payment-selection').val(); 1626 1627 // book the room 1628 if( $(this).hasClass('tourmaster-now-loading') ) return; 1629 $(this).addClass('tourmaster-now-loading'); 1630 1631 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1632 success: function(data){ 1633 if( payment_method == 'paypal' && data.payment_content ){ 1634 body.append(data.payment_content); 1635 clear_cart(); 1636 }else if( data.payment_content ){ 1637 var content = $('<div class="tourmaster-room-payment-lb" ></div>').html(data.payment_content); 1638 tourmaster_lightbox(content); 1639 if( typeof(data.order_id) != 'undefined' ){ 1640 tourmaster_set_cookie('tourmaster-room-current-id', data.order_id, 31536000); 1641 } 1642 1643 content.on('payment_complete', function(){ 1644 step3_wrap.hide(); 1645 step4_wrap.fadeIn(150); 1646 change_step(4); 1647 1648 $(this).closest('.tourmaster-lightbox-wrapper').trigger('lightbox_close'); 1649 clear_cart(); 1650 }); 1651 } 1652 $(this).removeClass('tourmaster-now-loading'); 1653 } 1654 }, { 1655 action: 'tourmaster_room_pay_now', 1656 data: get_booking_data(), 1657 'pay_full_amount': pay_full_amount, 1658 'payment_method': payment_method 1659 }); 1660 }); 1661 1662 // pay woocommerce 1663 step3_wrap.on('click', '.tourmaster-pay-woocommerce', function(){ 1664 1665 $(this).siblings('.tourmaster-error-message').slideUp(1
166550, function(){ $(this).remove(); }); 1666 1667 var term_service = step3_wrap.find('[name="term-and-service"]'); 1668 if( term_service.length ){ 1669 if( !term_service.is(':checked') ){ 1670 display_errors($(this), term_service.attr('data-error')); 1671 return; 1672 } 1673 } 1674 1675 var error = validate_contact_form(); 1676 if( error ){ 1677 display_errors($(this), error); 1678 return false; 1679 } 1680 1681 // book the room 1682 if( $(this).hasClass('tourmaster-now-loading') ) return; 1683 $(this).addClass('tourmaster-now-loading'); 1684 1685 tourmaster_room_booking_ajax(payment_page.attr('data-ajax-url'), { 1686 success: function(data){ 1687 // do something here 1688 if( typeof(data.redirect_url) != 'undefined' ){ 1689 window.location.replace(data.redirect_url); 1690 } 1691 1692 $(this).removeClass('tourmaster-now-loading'); 1693 1694 // clear cart 1695 clear_cart(); 1696 } 1697 }, { 1698 action: 'tourmaster_room_pay_woocommerce', 1699 data: get_booking_data() 1700 }); 1701 }); 1702 1703 }); 1704 }); 1705 1706 $(window).on('load', function(){ 1707 1708 1709 }); 1710 1711})(jQuery);
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.