1// make it a global variable so other scripts can access it 2var booked_load_calendar_date_booking_options, 3 booked_appt_form_options, 4 bookedNewAppointment; 5 6;(function($, window, document, undefined) { 7 8 var $win = $(window); 9 10 $.fn.spin.presets.booked = { 11 lines: 10, // The number of lines to draw 12 length: 7, // The length of each line 13 width: 5, // The line thickness 14 radius: 11, // The radius of the inner circle 15 corners: 1, // Corner roundness (0..1) 16 rotate: 0, // The rotation offset 17 direction: 1, // 1: clockwise, -1: counterclockwise 18 color: '#555', // #rgb or #rrggbb or array of colors 19 speed: 1, // Rounds per second 20 trail: 60, // Afterglow percentage 21 shadow: false, // Whether to render a shadow 22 hwaccel: false, // Whether to use hardware acceleration 23 className: 'booked-spinner', // The CSS class to assign to the spinner 24 zIndex: 2e9, // The z-index (defaults to 2000000000) 25 top: '50%', // Top position relative to parent 26 left: '50%' // Left position relative to parent 27 } 28 29 $.fn.spin.presets.booked_top = { 30 lines: 11, // The number of lines to draw 31 length: 10, // The length of each line 32 width: 6, // The line thickness 33 radius: 15, // The radius of the inner circle 34 corners: 1, // Corner roundness (0..1) 35 rotate: 0, // The rotation offset 36 scale: 0.5, 37 direction: 1, // 1: clockwise, -1: counterclockwise 38 color: '#aaaaaa', // #rgb or #rrggbb or array of colors 39 speed: 1, // Rounds per second 40 trail: 60, // Afterglow percentage 41 shadow: false, // Whether to render a shadow 42 hwaccel: false, // Whether to use hardware acceleration 43 className: 'booked-spinner booked-spinner-top', // The CSS class to assign to the spinner 44 zIndex: 2e9, // The z-index (defaults to 2000000000) 45 top: '15px', // Top position relative to parent 46 left: '50%' // Left position relative to parent 47 } 48 49 $.fn.spin.presets.booked_white = { 50 lines: 13, // The number of lines to draw 51 length: 11, // The length of each line 52 width: 5, // The line thickness 53 radius: 18, // The radius of the inner circle 54 scale: 1, 55 corners: 1, // Corner roundness (0..1) 56 rotate: 0, // The rotation offset 57 direction: 1, // 1: clockwise, -1: counterclockwise 58 color: '#fff', // #rgb or #rrggbb or array of colors 59 speed: 1, // Rounds per second 60 trail: 60, // Afterglow percentage 61 shadow: false, // Whether to render a shadow 62 hwaccel: false, // Whether to use hardware acceleration 63 className: 'booked-spinner booked-white', // The CSS class to assign to the spinner 64 zIndex: 2e9, // The z-index (defaults to 2000000000) 65 top: '50%', // Top position relative to parent 66 left: '50%' // Left position relative to parent 67 } 68 69 // Adjust the calendar sizing when resizing the window 70 $win.on('resize', function(){ 71 72 adjust_calendar_boxes(); 73 resize_booked_modal(); 74 75 }); 76 77 $win.on('load', function() { 78 79 BookedTabs.Init(); 80 81 var ajaxRequests = []; 82 83 // Adjust the calendar sizing on load 84 adjust_calendar_boxes(); 85 86 $('.booked-calendar-wrap').each(function(){ 87 var thisCalendar = $(this); 88 var calendar_month = thisCalendar.find('div.booked-calendar').attr('data-calendar-date'); 89 thisCalendar.attr('data-default',calendar_month); 90 init_tooltips(thisCalendar); 91 }); 92 93 $('.booked-list-view').each(function(){ 94 var thisList = $(this); 95 var list_date = thisList.find('.booked-appt-list').attr('data-list-date'); 96 thisList.attr('data-default',list_date); 97 }); 98 99 bookedRemoveEmptyTRs(); 100 init_appt_list_date_picker(); 101 102 $('.booked_calendar_chooser').change(function(e){ 103 104 e.preventDefault(); 105 106 var $selector = $(this), 107 thisIsCalendar = $selector.parents('.booked-calendarSwitcher').hasClass('calendar'); 108 109 if (!thisIsCalendar){ 110 111 var thisCalendarWrap = $selector.parents('.booked-calendar-shortcode-wrap').find('.booked-list-view'), 112 thisDefaultDate = thisCalendarWrap.attr('data-default'), 113 thisIsCalendar = $selector.parents('.booked-calendarSwitcher').hasClass('calendar'); 114 115 if (typeof thisDefaultDate == 'undefined'){ thisDefaultDate = false; } 116 117 thisCalendarWrap.addClass('booked-loading'); 118 119 var args = { 120 'action' : 'booked_appointment_list_date', 121 'nonce' : booked_js_vars.nonce, 122 'date' : thisDefaultDate, 123 'calendar_id' : $selector.val() 124 }; 125 126 $(document).trigger("booked-before-loading-appointment-list-booking-options"); 127 thisCalendarWrap.spin('booked_top'); 128 129 $.ajax({ 130 url: booked_js_vars.ajax_url, 131 type: 'post', 132 data: args, 133 success: function( html ) { 134 135 thisCalendarWrap.html( html ); 136 137 init_appt_list_date_picker(); 138 setTimeout(function(){ 139 thisCalendarWrap.removeClass('booked-loading'); 140 },1); 141 142 } 143 }); 144 145 } else { 146 147 var thisCalendarWrap = $selector.parents('.booked-calendar-shortcode-wrap').find('.booked-calendar-wrap'), 148 thisDefaultDate = thisCalendarWrap.attr('data-default'); 149 if (typeof thisDefaultDate == 'undefined'){ thisDefaultDate = false; } 150 151 var args = { 152 'action' : 'booked_calendar_month', 153 'nonce' : booked_js_vars.nonce, 154 'gotoMonth' : thisDefaultDate, 155 'calendar_id' : $selector.val() 156 }; 157 158 savingState(true,thisCalendarWrap); 159 160 $.ajax({ 161 url: booked_js_vars.ajax_url, 162 type: 'post', 163 data: args, 164 success: function( html ) { 165 166 thisCalendarWrap.html( html ); 167 168 adjust_calendar_boxes(); 169 bookedRemoveEmptyTRs(); 170 init_tooltips(thisCalendarWrap); 171 $(window).trigger('booked-load-calendar', args, $selector ); 172 173 } 174 }); 175 176 } 177 178 return false;
179 180 }); 181 182 // Calendar Next/Prev Click 183 $('body').on('click', '.booked-calendar-wrap .page-right, .booked-calendar-wrap .page-left, .booked-calendar-wrap .monthName a', function(e) { 184 185 e.preventDefault(); 186 187 var $button = $(this), 188 gotoMonth = $button.attr('data-goto'), 189 thisCalendarWrap = $button.parents('.booked-calendar-wrap'), 190 thisCalendarDefault = thisCalendarWrap.attr('data-default'), 191 calendar_id = $button.parents('div.booked-calendar').attr('data-calendar-id'); 192 193 if (typeof thisCalendarDefault == 'undefined'){ thisCalendarDefault = false; } 194 195 var args = { 196 'action' : 'booked_calendar_month', 197 'nonce' : booked_js_vars.nonce, 198 'gotoMonth' : gotoMonth, 199 'calendar_id' : calendar_id, 200 'force_default' : thisCalendarDefault 201 }; 202 203 savingState(true,thisCalendarWrap); 204 205 $.ajax({ 206 url: booked_js_vars.ajax_url, 207 type: 'post', 208 data: args, 209 success: function( html ) { 210 211 thisCalendarWrap.html( html ); 212 213 adjust_calendar_boxes(); 214 bookedRemoveEmptyTRs(); 215 init_tooltips(thisCalendarWrap); 216 $(window).trigger('booked-load-calendar', args, $button ); 217 218 } 219 }); 220 221 return false; 222 223 }); 224 225 // Calendar Date Click 226 $('body').on('click', '.booked-calendar-wrap .bc-row.week .bc-col', function(e) { 227 228 e.preventDefault(); 229 230 var $thisDate = $(this), 231 booked_calendar_table = $thisDate.parents('div.booked-calendar'), 232 $thisRow = $thisDate.parent(), 233 date = $thisDate.attr('data-date'), 234 calendar_id = booked_calendar_table.attr('data-calendar-id'), 235 colspanSetting = $thisRow.find('.bc-col').length; 236 237 if (!calendar_id){ calendar_id = 0; } 238 239 if ($thisDate.hasClass('blur') || $thisDate.hasClass('booked') && !booked_js_vars.publicAppointments || $thisDate.hasClass('prev-date')){ 240 241 // Do nothing. 242 243 } else if ($thisDate.hasClass('active')){ 244 245 $thisDate.removeClass('active'); 246 $('.bc-row.entryBlock').remove(); 247 248 var calendarHeight = booked_calendar_table.height(); 249 booked_calendar_table.parent().height(calendarHeight); 250 251 } else { 252 253 $('.bc-row.week .bc-col').removeClass('active'); 254 $thisDate.addClass('active'); 255 256 $('.bc-row.entryBlock').remove(); 257 $thisRow.after('<div class="bc-row entryBlock booked-loading"><div class="bc-col"></div></div>'); 258 $('.bc-row.entryBlock').find('.bc-col').spin('booked'); 259 260 booked_load_calendar_date_booking_options = {'action':'booked_calendar_date','nonce': booked_js_vars.nonce,'date':date,'calendar_id':calendar_id}; 261 $(document).trigger("booked-before-loading-calendar-booking-options"); 262 263 var calendarHeight = booked_calendar_table.height(); 264 booked_calendar_table.parent().height(calendarHeight); 265 266 $.ajax({ 267 url: booked_js_vars.ajax_url, 268 type: 'post', 269 data: booked_load_calendar_date_booking_options, 270 success: function( html ) { 271 272 $('.bc-row.entryBlock').find('.bc-col').html( html ); 273 274 $('.bc-row.entryBlock').removeClass('booked-loading'); 275 $('.bc-row.entryBlock').find('.booked-appt-list').fadeIn(300); 276 $('.bc-row.entryBlock').find('.booked-appt-list').addClass('shown'); 277 adjust_calendar_boxes(); 278 279 } 280 }); 281 282 } 283 284 return; 285 286 }); 287 288 // Appointment List Next/Prev Date Click 289 $('body').on('click', '.booked-list-view .booked-list-view-date-prev, .booked-list-view .booked-list-view-date-next', function(e) { 290 291 e.preventDefault(); 292 293 var $thisLink = $(this), 294 date = $thisLink.attr('data-date'), 295 thisList = $thisLink.parents('.booked-list-view'), 296 defaultDate = thisList.attr('data-default'), 297 calendar_id = $thisLink.parents('.booked-list-view-nav').attr('data-calendar-id'); 298 299 if (typeof defaultDate == 'undefined'){ defaultDate = false; } 300 301 if (!calendar_id){ calendar_id = 0; } 302 303 thisList.addClass('booked-loading'); 304 305 var booked_load_list_view_date_booking_options = { 306 'action' : 'booked_appointment_list_date', 307 'nonce' : booked_js_vars.nonce, 308 'date' : date, 309 'calendar_id' : calendar_id, 310 'force_default' : defaultDate 311 }; 312 313 $(document).trigger("booked-before-loading-appointment-list-booking-options"); 314 thisList.spin('booked_top'); 315 316 $.ajax({ 317 url: booked_js_vars.ajax_url, 318 type: 'post', 319 data: booked_load_list_view_date_booking_options, 320 success: function( html ) { 321 322 thisList.html( html ); 323 324 init_appt_list_date_picker(); 325 setTimeout(function(){ 326 thisList.removeClass('booked-loading'); 327 },1); 328 329 } 330 }); 331 332 return false;
333 334 }); 335 336 // New Appointment Click 337 bookedNewAppointment = function(e) { 338 e.preventDefault(); 339 340 var $button = $(this), 341 title = $button.attr('data-title'), 342 timeslot = $button.attr('data-timeslot'), 343 date = $button.attr('data-date'), 344 calendar_id = $button.attr('data-calendar-id'), 345 $thisTimeslot = $button.parents('.timeslot'), 346 is_list_view = $button.parents('.booked-calendar-wrap').hasClass('booked-list-view'); 347 348 if (typeof is_list_view != 'undefined' && is_list_view){ 349 var new_calendar_id = $button.parents('.booked-list-view').find('.booked-list-view-nav').attr('data-calendar-id'); 350 } else { 351 var new_calendar_id = $button.parents('div.booked-calendar').attr('data-calendar-id'); 352 } 353 calendar_id = new_calendar_id ? new_calendar_id : calendar_id; 354 355 booked_appt_form_options = {'action':'booked_new_appointment_form','nonce': booked_js_vars.nonce,'date':date,'timeslot':timeslot,'calendar_id':calendar_id,'title':title}; 356 $(document).trigger("booked-before-loading-booking-form"); 357 358 create_booked_modal(); 359 setTimeout(function(){ 360 361 $.ajax({ 362 url: booked_js_vars.ajax_url, 363 type: 'post', 364 data: booked_appt_form_options, 365 success: function( html ) { 366 367 $('.bm-window').html( html ); 368 369 var bookedModal = $('.booked-modal'); 370 var bmWindow = bookedModal.find('.bm-window'); 371 bmWindow.css({'visibility':'hidden'}); 372 bookedModal.removeClass('bm-loading'); 373 $(document).trigger("booked-on-new-app"); 374 resize_booked_modal(); 375 bmWindow.hide(); 376 $('.booked-modal .bm-overlay').find('.booked-spinner').remove(); 377 378 setTimeout(function(){ 379 bmWindow.css({'visibility':'visible'}); 380 bmWindow.show(); 381 },50); 382 383 } 384 }); 385 386 },100); 387 388 return false; 389 } 390 $('body').on('click', '.booked-calendar-wrap button.new-appt', bookedNewAppointment); 391 392 // Profile Tabs 393 var profileTabs = $('.booked-tabs'); 394 395 if (!profileTabs.find('li.active').length){ 396 profileTabs.find('li:first-child').addClass("active"); 397 } 398 399 if (profileTabs.length){ 400 $('.booked-tab-content').hide(); 401 var activeTab = profileTabs.find('.active > a').attr('href'); 402 activeTab = activeTab.split('#'); 403 activeTab = activeTab[1]; 404 $('#profile-'+activeTab).show(); 405 406 profileTabs.find('li > a').on('click', function(e) { 407 408 e.preventDefault(); 409 $('.booked-tab-content').hide(); 410 profileTabs.find('li').removeClass('active'); 411 412 $(this).parent().addClass('active'); 413 var activeTab = $(this).attr('href'); 414 activeTab = activeTab.split('#'); 415 activeTab = activeTab[1]; 416 417 $('#profile-'+activeTab).show(); 418 return false; 419 420 }); 421 } 422 423 // Show Additional Information 424 $('body').on('click', '.booked-profile-appt-list .booked-show-cf', function(e) { 425 426 e.preventDefault(); 427 var hiddenBlock = $(this).parent().find('.cf-meta-values-hidden'); 428 429 if(hiddenBlock.is(':visible')){ 430 hiddenBlock.hide(); 431 $(this).removeClass('booked-cf-active'); 432 } else { 433 hiddenBlock.show(); 434 $(this).addClass('booked-cf-active'); 435 } 436 437 return false; 438 439 }); 440 441 // Check Login/Registration/Forgot Password forms before Submitting 442 if ($('#loginform').length){ 443 $('#loginform input[type="submit"]').on('click',function(e) { 444 if ($('#loginform input[name="log"]').val() && $('#loginform input[name="pwd"]').val()){ 445 $('#loginform .booked-custom-error').hide(); 446 } else { 447 if ( $('#loginform').parents('.booked-form-wrap').length ){ 448 e.preventDefault(); 449 $('#loginform').parents('.booked-form-wrap').find('.booked-custom-error').fadeOut(200).fadeIn(200); 450 } 451 } 452 }); 453 } 454 455 if ($('#profile-forgot').length){ 456 $('#profile-forgot input[type="submit"]').on('click',function(e) { 457 if ($('#profile-forgot input[name="user_login"]').val()){ 458 $('#profile-forgot .booked-custom-error').hide(); 459 } else { 460 e.preventDefault(); 461 $('#profile-forgot').find('.booked-custom-error').fadeOut(200).fadeIn(200); 462 } 463 }); 464 } 465 466 // Custom Upload Field 467 if ($('.booked-upload-wrap').length){ 468 469 $('.booked-upload-wrap input[type=file]').on('change',function(){ 470 471 var fileName = $(this).val(); 472 $(this).parent().find('span').html(fileName); 473 $(this).parent().addClass('hasFile'); 474 475 }); 476 477 } 478 479 // Delete Appointment 480 $('body').on('click', '.booked-profile-appt-list .appt-block .cancel', function(e) { 481 482 e.preventDefault(); 483 484 var $button = $(this), 485 $thisParent = $button.parents('.appt-block'), 486 appt_id = $thisParent.attr('data-appt-id'); 487 488 confirm_delete = confirm(booked_js_vars.i18n_confirm_appt_delete); 489 if (confirm_delete == true){ 490 491 var currentApptCount = parseInt($('.booked-profile-appt-list').find('h4').find('span.count').html()); 492 currentApptCount = parseInt(currentApptCount - 1); 493 if (currentApptCount < 1){ 494 $('.booked-profile-appt-list').find('h4').find('span.count').html('0'); 495 $('.no-appts-message').slideDown('fast'); 496 } else { 497 $('.booked-profile-appt-list').find('h4').find('span.count').html(currentApptCount); 498 } 499 500 $('.appt-block').animate({'opacity':0.4},0); 501 502 $thisParent.slideUp('fast',function(){ 503 $(this).remove(); 504 }); 505 506 $.ajax({ 507 'url' : booked_js_vars.ajax_url, 508 'method' : 'post', 509 'data' : { 510 'action' : 'booked_cancel_appt', 511 'nonce' : booked_js_vars.nonce, 512 'appt_id' : appt_id 513 }, 514 success: function(data) { 515 $('.appt-block').animate({'opacity':1},150); 516 } 517 }); 518 519 } 520 521 return false;
522 523 }); 524 525 $('body').on('touchstart click','.bm-overlay, .bm-window .close, .booked-form .cancel',function(e){ 526 e.preventDefault(); 527 close_booked_modal(); 528 return false; 529 }); 530 531 $('body') 532 .on('focusin', '.booked-form input', function() { 533 if(this.title==this.value) { 534 $(this).addClass('hasContent'); 535 this.value = ''; 536 } 537 }).on('focusout', '.booked-form input', function(){ 538 if(this.value==='') { 539 $(this).removeClass('hasContent'); 540 this.value = this.title; 541 } 542 }); 543 544 $('body').on('change','.booked-form input',function(){ 545 546 var condition = $(this).attr('data-condition'), 547 thisVal = $(this).val(); 548 549 if (condition && $('.condition-block').length) { 550 $('.condition-block.'+condition).hide(); 551 $('#condition-'+thisVal).fadeIn(200); 552 resize_booked_modal(); 553 } 554 555 }); 556 557 // Perform AJAX login on form submit 558 $('body').on('submit','form#ajaxlogin', function(e){ 559 e.preventDefault(); 560 561 $('form#ajaxlogin p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i> ' + booked_js_vars.i18n_please_wait); 562 resize_booked_modal(); 563 564 var $this = $(this), 565 date = $this.data('date'), 566 title = $this.data('title'), 567 timeslot = $this.data('timeslot'), 568 calendar_id = $this.data('calendar-id'); 569 570 $.ajax({ 571 type : 'post', 572 url : booked_js_vars.ajax_url, 573 data : $('form#ajaxlogin').serialize(), 574 success : function(data) { 575 if (data == 'success'){ 576 //get new nonce as a logged in user 577 $.ajax({ 578 async: false, 579 type : 'post', 580 url : booked_js_vars.ajax_url, 581 data : {action: 'booked_get_new_nonce_after_login'}, 582 success : function(data) { 583 //set the new nonce into the global variable. 584 booked_js_vars.nonce = data.data.nonce; 585 586 // close the modal box 587 close_booked_modal(); 588 589 // reopen the modal box 590 var $button = $( '<button data-title="' + title + '" data-timeslot="' + timeslot + '" data-date="' + date + '" data-calendar-id="' + calendar_id + '"></button>' ); 591 $button.on( 'click', window.bookedNewAppointment ); 592 $button.triggerHandler( 'click' ); 593 $button.unbind( 'click', window.bookedNewAppointment ); 594 $button.detach(); 595 } 596 }); 597 598 } else { 599 $('form#ajaxlogin p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + booked_js_vars.i18n_wrong_username_pass); 600 resize_booked_modal(); 601 } 602 } 603 }); 604 e.preventDefault(); 605 }); 606 607 $('body').on('click','.booked-forgot-password',function(e){ 608 609 e.preventDefault(); 610 $('#ajaxlogin').hide(); 611 $('#ajaxforgot').show(); 612 613 resize_booked_modal(); 614 615 }); 616 617 $('body').on('click','.booked-forgot-goback',function(e){ 618 619 e.preventDefault(); 620 $('#ajaxlogin').show(); 621 $('#ajaxforgot').hide(); 622 623 resize_booked_modal(); 624 625 }); 626 627 /** edit appointment**/ 628 $(document).ready(function () { 629 630 $(document).on("booked-before-loading-calendar-booking-options", function (event) { 631 booked_wc_change_calendar_loading_paramenters(); 632 }); 633 634 $(document).on("booked-before-loading-booking-form", function (event) { 635 booked_wc_change_booking_form_paramenters(); 636 }); 637 638 function booked_wc_change_calendar_loading_paramenters() { 639 if (!booked_load_calendar_date_booking_options) { 640 return; 641 } 642 ; 643 644 var current_url = window.location.href, 645 url_parameters = current_url.replace(/^[^?]+\??/gi, ''), 646 url_parameters_parts = url_parameters ? url_parameters.split('&') : false;
647 648 if (url_parameters_parts && current_url.match('app_action=edit')) { 649 650 // populate additional loading parameters 651 for (var i = 0; i < url_parameters_parts.length; i++) { 652 var data = url_parameters_parts[i].split('='), 653 name = data[0].replace(/_\d+$/, ''), 654 value = data[1]; 655 656 booked_load_calendar_date_booking_options[name] = value; 657 } 658 } 659 ; 660 661 } 662 663 function booked_wc_change_booking_form_paramenters() { 664 if (!booked_appt_form_options) { 665 return; 666 } 667 ; 668 669 var current_url = window.location.href, 670 url_parameters = current_url.replace(/^[^?]+\??/gi, ''), 671 url_parameters_parts = url_parameters ? url_parameters.split('&') : false; 672 673 if (url_parameters_parts && current_url.match('app_action=edit')) { 674 675 // populate additional loading parameters 676 for (var i = 0; i < url_parameters_parts.length; i++) { 677 var data = url_parameters_parts[i].split('='), 678 name = data[0].replace(/_\d+$/, ''), 679 value = data[1]; 680 681 booked_appt_form_options[name] = value; 682 } 683 } 684 ; 685 686 } 687 $('.booked-profile-appt-list .appt-block .edit').on('click', function (event) { 688 689 event.preventDefault(); 690 691 var $button = $(this), 692 appt_id = $button.attr('data-appt-id'), 693 calendar_link = $button.attr('data-app-calendar'); 694 695 if (booked_js_vars.i18n_confirm_appt_edit) { 696 confirm_edit = confirm(booked_js_vars.i18n_confirm_appt_edit); 697 } else { 698 confirm_edit = true; 699 } 700 701 if (confirm_edit === true) { 702 window.location.href = calendar_link; 703 } 704 705 return false; 706 }); 707 $('body').on('click', '.booked-form input#submit-edit-request-appointment', function (e) { 708 709 var $thisButton = $(this); 710 711 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i> ' + booked_js_vars.i18n_please_wait); 712 resize_booked_modal(); 713 714 e.preventDefault(); 715 716 $.ajax({ 717 type: 'post', 718 url: booked_js_vars.ajax_url, 719 data: $('#newAppointmentForm').serialize() + '&nonce=' + booked_js_vars.nonce, 720 success: function (data) { 721 722 data = data.split('###'); 723 var data_result = data[0].substr(data[0].length - 5); 724 725 if (data_result == 'error') { 726 727 $thisButton.attr('disabled', false); 728 $thisButton.parents('form').find('button.cancel').show(); 729 730 $('.booked-form input').each(function () { 731 thisDefault = $(this).attr('title'); 732 thisVal = $(this).val(); 733 if (!thisVal) { 734 $(this).val(thisDefault); 735 } 736 }); 737 738 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + data[1]); 739 resize_booked_modal(); 740 741 } else { 742 743 window.location = booked_js_vars.profilePage 744 745 } 746 747 } 748 }); 749 }); 750 751}); 752 // Perform AJAX login on form submit 753 754 $('body').on('submit','form#ajaxforgot', function(e){ 755 e.preventDefault(); 756 757 $('form#ajaxforgot p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i> ' + booked_js_vars.i18n_please_wait); 758 resize_booked_modal(); 759 760 var $this = $(this); 761 762 $.ajax({ 763 type : 'post', 764 url : booked_js_vars.ajax_url, 765 data : $('form#ajaxforgot').serialize(), 766 success : function(data) { 767 if (data == 'success'){ 768 769 e.preventDefault(); 770 $('#ajaxlogin').show(); 771 $('#ajaxforgot').hide(); 772 773 $('form#ajaxlogin p.status').show().html('<i class="fa-solid fa-check" style="color:#56c477"></i> ' + booked_js_vars.i18n_password_reset); 774 resize_booked_modal(); 775 776 } else { 777 778 //console.log(data); 779 $('form#ajaxforgot p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + booked_js_vars.i18n_password_reset_error); 780 resize_booked_modal(); 781 782 } 783 } 784 }); 785 e.preventDefault(); 786 }); 787 788 789 // Submit the "Request Appointment" Form 790 $('body').on('click','.booked-form input#submit-request-appointment',function(e){ 791 792 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i> ' + booked_js_vars.i18n_please_wait); 793 resize_booked_modal(); 794 795 e.preventDefault(); 796 797 var customerType = $('#newAppointmentForm input[name=customer_type]').val(), 798 customerID = $('#newAppointmentForm input[name=user_id]').val(), 799 name = $('#newAppointmentForm input[name=booked_appt_name]').val(), 800 surname = $('#newAppointmentForm input[name=booked_appt_surname]').val(), 801 surnameActive = $('#newAppointmentForm input[name=booked_appt_surname]').length, 802 guest_name = $('#newAppointmentForm input[name=guest_name]').val(), 803 guest_surname = $('#newAppointmentForm input[name=guest_surname]').val(), 804 guest_surnameActive = $('#newAppointmentForm input[name=guest_surname]').length, 805 guest_email = $('#newAppointmentForm input[name=guest_email]').val(), 806 guest_emailActive = $('#newAppointmentForm input[name=guest_email]').length, 807 email = $('#newAppointmentForm input[name=booked_appt_email]').val(), 808 password = $('#newAppointmentForm input[name=booked_appt_password]').val(), 809 showRequiredError = false, 810 ajaxRequests = []; 811 812 $(this).parents('.booked-form').find('input,textarea,select').each(function(i,field){ 813 814 var required = $(this).attr('required'); 815 816 if (required && $(field).attr('type') == 'hidden'){ 817 var fieldParts = $(field).attr('name'); 818 fieldParts = fieldParts.split('---'); 819 fieldName = fieldParts[0]; 820 fieldNumber = fieldParts[1].split('___'); 821 fieldNumber = fieldNumber[0]; 822 823 if (fieldName == 'radio-buttons-label'){ 824 var radioValue = false;
825 $('input:radio[name="single-radio-button---'+fieldNumber+'[]"]:checked').each(function(){ 826 if ($(this).val()){ 827 radioValue = $(this).val(); 828 } 829 }); 830 if (!radioValue){ 831 showRequiredError = true; 832 } 833 } else if (fieldName == 'checkboxes-label'){ 834 var checkboxValue = false; 835 $('input:checkbox[name="single-checkbox---'+fieldNumber+'[]"]:checked').each(function(){ 836 if ($(this).val()){ 837 checkboxValue = $(this).val(); 838 } 839 }); 840 if (!checkboxValue){ 841 showRequiredError = true; 842 } 843 } 844 845 } else if (required && $(field).attr('type') != 'hidden' && $(field).val() == ''){ 846 showRequiredError = true; 847 } 848 849 }); 850 851 if (showRequiredError) { 852 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + booked_js_vars.i18n_fill_out_required_fields); 853 resize_booked_modal(); 854 return false; 855 } 856 857 if ( customerType == 'new' && !name || customerType == 'new' && surnameActive && !surname || customerType == 'new' && !email || customerType == 'new' && !password ) { 858 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + booked_js_vars.i18n_appt_required_fields); 859 resize_booked_modal(); 860 return false; 861 } 862 863 if ( customerType == 'guest' && !guest_name || customerType == 'guest' && guest_emailActive && !guest_email || customerType == 'guest' && guest_surnameActive && !guest_surname ){ 864 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + booked_js_vars.i18n_appt_required_fields_guest); 865 resize_booked_modal(); 866 return false; 867 } 868 869 if (customerType == 'current' && customerID || 870 customerType == 'guest' && guest_name && !guest_surnameActive && !guest_emailActive || 871 customerType == 'guest' && guest_name && guest_surnameActive && guest_surname && !guest_emailActive || 872 customerType == 'guest' && guest_name && guest_emailActive && guest_email && !guest_surnameActive || 873 customerType == 'guest' && guest_name && guest_emailActive && guest_email && guest_surnameActive && guest_surname ) { 874 875 SubmitRequestAppointment.currentUserOrGuest(); 876 877 } 878 879 if (customerType == 'new' && name && email && password) { 880 if ( !surnameActive || surnameActive && surname ){ 881 SubmitRequestAppointment.newUser(); 882 } 883 } 884 885 }); 886 887 var SubmitRequestAppointment = { 888 889 formSelector: '#newAppointmentForm', 890 formBtnRequestSelector: '.booked-form input#submit-request-appointment', 891 formStatusSelector: 'p.status', 892 formSubmitBtnSelector: '#submit-request-appointment', 893 894 apptContainerSelector: '.booked-appointment-details', 895 896 baseFields: [ 'guest_name','guest_surname','guest_email','action', 'customer_type', 'user_id' ], 897 apptFields: [ 'appoinment', 'calendar_id', 'title', 'date', 'timestamp', 'timeslot' ], 898 userFields: [ 'booked_appt_name','booked_appt_surname','booked_appt_email', 'booked_appt_password' ], 899 captchaFields: [ 'captcha_word', 'captcha_code' ], 900 901 currentApptIndex: false, 902 currentApptCounter: false, 903 hasAnyErrors: false, 904 905 currentUserOrGuest: function() { 906 var total_appts = SubmitRequestAppointment._totalAppts(); 907 908 if ( ! total_appts ) { 909 return; 910 } 911 912 SubmitRequestAppointment._showLoadingMessage(); 913 SubmitRequestAppointment._resetDefaultValues(); 914 915 var data = SubmitRequestAppointment._getBaseData(); 916 917 SubmitRequestAppointment.currentApptIndex = 0; 918 SubmitRequestAppointment.currentApptCounter = 1; 919 SubmitRequestAppointment._doRequestAppointment( data, total_appts ); 920 921 }, 922 923 // pretty much the same as SubmitRequestAppointment.currentUserOrGuest(), however, it include the user name, email and password 924 newUser: function() { 925 var total_appts = SubmitRequestAppointment._totalAppts(); 926 927 if ( ! total_appts ) { 928 return; 929 } 930 931 SubmitRequestAppointment._showLoadingMessage(); 932 SubmitRequestAppointment._resetDefaultValues(); 933 934 var data = SubmitRequestAppointment._getBaseData(); 935 936 // when there are more than one appointment, we need to make the registration request first and then loop the appointments 937 if ( total_appts > 1 ) { 938 var data_obj_with_no_reference = null; 939 data_obj_with_no_reference = $.extend( true, {}, data ); 940 data_obj_with_no_reference = SubmitRequestAppointment._addUserRegistrationData( data_obj_with_no_reference ); 941 SubmitRequestAppointment._requestUserRegistration( data_obj_with_no_reference ); 942 943 data.customer_type = 'current'; 944 } else { 945 // add user registration fields values 946 data = SubmitRequestAppointment._addUserRegistrationData( data ); 947 } 948 949 SubmitRequestAppointment.currentApptIndex = 0; 950 SubmitRequestAppointment._doRequestAppointment( data, total_appts ); 951 }, 952 953 _doRequestAppointment: function( data, total_appts ) { 954 955 var appt_fields = SubmitRequestAppointment.apptFields; 956 957 // for the first item only 958 if ( SubmitRequestAppointment.currentApptIndex === 0 ) { 959 SubmitRequestAppointment._hideCancelBtn(); 960 SubmitRequestAppointment._disableSubmitBtn(); 961 SubmitRequestAppointment.hasAnyErrors = false;
962 } 963 // <------end 964 965 var data_obj_with_no_reference = $.extend( true, {}, data ); 966 967 // add the appointment fields to the data 968 for (var i = 0; i < appt_fields.length; i++) { 969 data_obj_with_no_reference[ appt_fields[i] ] = SubmitRequestAppointment._getFieldVal( appt_fields[i], SubmitRequestAppointment.currentApptIndex ); 970 } 971 972 var calendar_id = SubmitRequestAppointment._getFieldVal( 'calendar_id', SubmitRequestAppointment.currentApptIndex ); 973 data_obj_with_no_reference = SubmitRequestAppointment._addCustomFieldsData( data_obj_with_no_reference, calendar_id ); 974 975 var $appt = SubmitRequestAppointment._getApptElement( SubmitRequestAppointment.currentApptIndex ); 976 977 if ( ! $appt.hasClass('skip') ) { 978 $.ajax({ 979 type : 'post', 980 url : booked_js_vars.ajax_url, 981 data : data_obj_with_no_reference, 982 success : function( response ) { 983 //if action is booked_add_appt 984 //and customer_type: new, get a new nonce 985 if(data.action==='booked_add_appt' && data.customer_type==='new'){ 986 $.ajax({ 987 async: false, 988 type : 'post', 989 url : booked_js_vars.ajax_url, 990 data : {action: 'booked_get_new_nonce_after_login'}, 991 success : function(data) { 992 //set the new nonce into the global variable. 993 booked_js_vars.nonce = data.data.nonce; 994 } 995 }); 996 } 997 //SubmitRequestAppointment._enableSubmitBtn(); 998 //SubmitRequestAppointment._showCancelBtn(); 999 1000 //console.log(response); 1001 //return; 1002 1003 SubmitRequestAppointment._requestAppointmentResponseHandler( response ); 1004 SubmitRequestAppointment.currentApptIndex++; 1005 1006 setTimeout( function() { 1007 if ( SubmitRequestAppointment.currentApptCounter === total_appts ) { 1008 // for the last item only 1009 if ( ! SubmitRequestAppointment.hasAnyErrors ) { 1010 SubmitRequestAppointment._onAfterRequestAppointment(); 1011 } else { 1012 SubmitRequestAppointment._enableSubmitBtn(); 1013 SubmitRequestAppointment._showCancelBtn(); 1014 } 1015 // <------end 1016 } else { 1017 SubmitRequestAppointment.currentApptCounter++; 1018 SubmitRequestAppointment._doRequestAppointment( data, total_appts ); 1019 } 1020 }, 100 ); 1021 } 1022 }); 1023 } else { 1024 SubmitRequestAppointment.currentApptIndex++; 1025 SubmitRequestAppointment.currentApptCounter++; 1026 SubmitRequestAppointment._doRequestAppointment( data, total_appts, SubmitRequestAppointment.currentApptIndex ); 1027 } 1028 }, 1029 1030 _totalAppts: function() { 1031 return $(SubmitRequestAppointment.formSelector + ' input[name="appoinment[]"]').length; 1032 }, 1033 1034 _getBaseData: function() { 1035 var data = {}, 1036 fields = SubmitRequestAppointment.baseFields; 1037 1038 // set up the base form data 1039 for ( var i = 0; i < fields.length; i++ ) { 1040 data[ fields[i] ] = SubmitRequestAppointment._getFieldVal( fields[i] ); 1041 } 1042 1043 data['nonce'] = booked_js_vars.nonce; 1044 data['is_fe_form'] = true; 1045 data['total_appts'] = SubmitRequestAppointment._totalAppts(); 1046 1047 return data; 1048 }, 1049 1050 _getFieldVal: function( field_name, field_index ) { 1051 var field_name = typeof field_name === 'undefined' ? '' : field_name, 1052 field_index = typeof field_index === 'undefined' ? false : field_index, 1053 selector = SubmitRequestAppointment.formSelector + ' '; 1054 1055 if ( field_index === false ) { 1056 selector += ' [name=' + field_name + ']'; 1057 return $( selector ).val(); 1058 } 1059 1060 selector += ' [name="' + field_name + '[]"]'; 1061 return $( selector ).eq( field_index ).val(); 1062 }, 1063 1064 _resetDefaultValues: function() { 1065 $('.booked-form input').each(function(){ 1066 var thisVal = $(this).val(), 1067 thisDefault = $(this).attr('title'); 1068 1069 if ( thisDefault == thisVal ){ 1070 $(this).val(''); 1071 } 1072 }); 1073 }, 1074 1075 _resetToDefaultValues: function() { 1076 $('.booked-form input').each(function(){ 1077 var thisVal = $(this).val(), 1078 thisDefault = $(this).attr('title'); 1079 1080 if ( ! thisVal ){ 1081 $(this).val( thisDefault ); 1082 } 1083 }); 1084 }, 1085 1086 _addUserRegistrationData: function( data ) { 1087 // populate the user data 1088 $.each( SubmitRequestAppointment.userFields, function( index, field_name ) { 1089 data[ field_name ] = SubmitRequestAppointment._getFieldVal( field_name ); 1090 } ); 1091 1092 // populate captcha data if available 1093 $.each( SubmitRequestAppointment.captchaFields, function( index, field_name ) {
1094 var field_value = SubmitRequestAppointment._getFieldVal( field_name ); 1095 1096 if ( ! field_value ) { 1097 return; 1098 } 1099 1100 data[ field_name ] = field_value; 1101 } ); 1102 1103 return data; 1104 }, 1105 1106 _addCustomFieldsData: function( data, calendar_id ) { 1107 var custom_fields_data = $('.cf-block [name]') 1108 .filter( function( index ) { 1109 var $this = $(this); 1110 return parseInt($this.data('calendar-id')) === parseInt(calendar_id) && $this.attr('name').match(/---\d+/g); 1111 } ) 1112 .each( function( index ) { 1113 var $this = $(this), 1114 name = $this.attr('name'), 1115 value = $this.val(), 1116 type = $this.attr('type'); 1117 1118 if ( ! value ) { 1119 return; 1120 } 1121 1122 if ( ! name.match(/checkbox|radio+/g) ) { 1123 data[ name ] = value; 1124 return; 1125 } 1126 1127 if ( name.match(/radio+/g) && $this.is(':checked') ) { 1128 data[ name ] = value; 1129 return; 1130 } 1131 1132 if ( ! name.match(/radio+/g) && typeof data[ name ] === 'undefined' || ! name.match(/radio+/g) && data[ name ].constructor !== Array ) { 1133 data[ name ] = []; 1134 } 1135 1136 if ( ! $this.is(':checked') ) { 1137 return; 1138 } 1139 1140 data[ name ].push( value ); 1141 } ); 1142 1143 return data; 1144 }, 1145 1146 _requestUserRegistration: function( base_data, appt_index ) { 1147 $.ajax({ 1148 type : 'post', 1149 url : booked_js_vars.ajax_url, 1150 data : base_data, 1151 async : false, 1152 success : function( response ) { 1153 SubmitRequestAppointment._requestUserRegistrationResponseHandler( response ); 1154 } 1155 }); 1156 }, 1157 1158 _requestUserRegistrationResponseHandler: function( response ) { 1159 var response_parts = response.split('###'), 1160 data_result = response_parts[0].substr( response_parts[0].length - 5 ); 1161 1162 if ( data_result === 'error' ) { 1163 // do something on registration failure 1164 return; 1165 } 1166 1167 // do something on successful registration 1168 }, 1169 1170 _requestAppointment: function( response ) { 1171 SubmitRequestAppointment._requestAppointmentResponseHandler( response ); 1172 }, 1173 1174 _requestAppointmentResponseHandler: function( response ) { 1175 var response_parts = response.split('###'), 1176 data_result = response_parts[0].substr( response_parts[0].length - 5 ); 1177 1178 if ( data_result === 'error' ) { 1179 SubmitRequestAppointment._requestAppointmentOnError( response_parts ); 1180 return; 1181 } 1182 1183 SubmitRequestAppointment._requestAppointmentOnSuccess( response_parts ); 1184 }, 1185 1186 _requestAppointmentOnError: function( response_parts ) { 1187 var $apptEl = SubmitRequestAppointment._getApptElement(); 1188 1189 $(document).trigger("booked-on-requested-appt-error",[$apptEl]); 1190 1191 SubmitRequestAppointment._highlightAppt(); 1192 1193 SubmitRequestAppointment._setStatusMsg( response_parts[1] ); 1194 1195 SubmitRequestAppointment.hasAnyErrors = true; 1196 1197 resize_booked_modal(); 1198 }, 1199 1200 _requestAppointmentOnSuccess: function( response_parts ) { 1201 var $apptEl = SubmitRequestAppointment._getApptElement(); 1202 1203 $(document).trigger("booked-on-requested-appt-success",[$apptEl]); 1204 1205 SubmitRequestAppointment._unhighlightAppt(); 1206 }, 1207 1208 _onAfterRequestAppointment: function() { 1209 var redirectObj = { redirect : false }; 1210 var redirect = $(document).trigger("booked-on-requested-appointment",[redirectObj]); 1211 1212 if ( redirectObj.redirect ) { 1213 return; 1214 } 1215 1216 if ( booked_js_vars.profilePage ) { 1217 window.location = booked_js_vars.profilePage; 1218 return; 1219 } 1220 1221 SubmitRequestAppointment._reloadApptsList(); 1222 SubmitRequestAppointment._reloadCalendarTable(); 1223 }, 1224 1225 _setStatusMsg: function( msg ) { 1226 var form_status_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formStatusSelector; 1227 $( form_status_selector ).show().html( '<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i> ' + msg ); 1228 }, 1229 1230 _getApptElement: function( appt_index ) { 1231 var appt_index = typeof appt_index === 'undefined' ? SubmitRequestAppointment.currentApptIndex : appt_index, 1232 appt_cnt_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.apptContainerSelector; 1233 1234 return $( appt_cnt_selector ).eq( appt_index ); 1235 }, 1236 1237 _highlightAppt: function( msg ) { 1238 var $apptEl = SubmitRequestAppointment._getApptElement(); 1239 1240 if ( ! $apptEl.length ) { 1241 return; 1242 } 1243 1244 $apptEl.addClass('has-error'); 1245 }, 1246 1247 _unhighlightAppt: function( msg ) { 1248 var $apptEl = SubmitRequestAppointment._getApptElement(); 1249 1250 if ( ! $apptEl.length ) { 1251 return; 1252 } 1253 1254 $apptEl.removeClass('has-error').addClass('skip'); 1255 }, 1256 1257 _enableSubmitBtn: function() { 1258 var btn_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formSubmitBtnSelector; 1259 $( btn_selector ).attr( 'disabled', false ); 1260 }, 1261 1262 _disableSubmitBtn: function() { 1263 var btn_selector = SubmitRequestAppointment.formSelector + ' ' + SubmitRequestAppointment.formSubmitBtnSelector; 1264 $( btn_selector ).attr( 'disabled', true ); 1265 }, 1266 1267 _showCancelBtn: function() { 1268 $( SubmitRequestAppointment.formSelector ).find('button.cancel').show(); 1269 }, 1270 1271 _hideCancelBtn: function() { 1272 $( SubmitRequestAppointment.formSelector ).find('button.cancel').hide(); 1273 }, 1274 1275 _showLoadingMessage: function() { 1276 $('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i> ' + booked_js_vars.i18n_please_wait); 1277 }, 1278 1279 _reloadApptsList: function() { 1280 if ( ! $('.booked-appt-list').length ){ 1281 return; 1282 } 1283 1284 $('.booked-appt-list').each( function() { 1285 var $thisApptList = $(this), 1286 date = $thisApptList.attr('data-list-date'), 1287 thisList = $thisApptList.parents('.booked-list-view'), 1288 defaultDate = thisList.attr('data-default'), 1289 calendar_id = parseInt($thisApptList.find('.booked-list-view-nav').attr('data-calendar-id')) || 0; 1290 1291 defaultDate = typeof defaultDate === 'undefined' ? false : defaultDate; 1292 calendar_id = calendar_id ? calendar_id : 0; 1293 1294 thisList.addClass('booked-loading'); 1295 1296 var booked_load_list_view_date_booking_options = { 1297 'action' : 'booked_appointment_list_date', 1298 'nonce' : booked_js_vars.nonce, 1299 'date' : date, 1300 'calendar_id' : calendar_id, 1301 'force_default' : defaultDate 1302 }; 1303 1304 $(document).trigger("booked-before-loading-appointment-list-booking-options"); 1305 thisList.spin('booked_top'); 1306 1307 $.ajax({ 1308 url: booked_js_vars.ajax_url, 1309 type: 'post', 1310 data: booked_load_list_view_date_booking_options, 1311 success: function( html ) { 1312 thisList.html( html ); 1313 1314 close_booked_modal(); 1315 init_appt_list_date_picker(); 1316 setTimeout(function(){ 1317 thisList.removeClass('booked-loading'); 1318 },1); 1319 } 1320 }); 1321 }); 1322 }, 1323 1324 _reloadCalendarTable: function() { 1325 if ( ! $('.bc-col.active').length ) { 1326 return; 1327 } 1328 1329 var $activeTD = $('.bc-col.active'), 1330 activeDate = $activeTD.attr('data-date'), 1331 calendar_id = parseInt( $activeTD.parents('.booked-calendar').data('calendar-id') ) || 0; 1332 1333 booked_load_calendar_date_booking_options = { 'action':'booked_calendar_date','nonce': booked_js_vars.nonce,'date':activeDate, 'calendar_id':calendar_id }; 1334 $(document).trigger("booked-before-loading-calendar-booking-options"); 1335 1336 $.ajax({ 1337 url: booked_js_vars.ajax_url, 1338 type: 'post', 1339 data: booked_load_calendar_date_booking_options, 1340 success: function( html ) { 1341 1342 $('.bc-row.entryBlock').find('.bc-col').html( html ); 1343 1344 close_booked_modal(); 1345 $('.bc-row.entryBlock').removeClass('booked-loading'); 1346 $('.bc-row.entryBlock').find('.booked-appt-list').hide().fadeIn(300); 1347 $('.bc-row.entryBlock').find('.booked-appt-list').addClass('shown'); 1348 adjust_calendar_boxes(); 1349 } 1350 }); 1351 } 1352 } 1353 }); 1354 1355 function bookedRemoveEmptyTRs(){ 1356 $('div.booked-calendar').find('.bc-row.week').each(function(){ 1357 if ($(this).children().length == 0){ 1358 $(this).remove(); 1359 } 1360 }); 1361 } 1362 1363 // Saving state updater 1364 function savingState(show,limit_to){ 1365 1366 show = typeof show !== 'undefined' ? show : true; 1367 limit_to = typeof limit_to !== 'undefined' ? limit_to : false;
1368 1369 if (limit_to){ 1370 1371 var $savingStateDIV = limit_to.find('li.active .savingState, .topSavingState.savingState, .calendarSavingState'); 1372 var $stuffToHide = limit_to.find('.monthName'); 1373 var $stuffToTransparent = limit_to.find('div.booked-calendar .bc-body'); 1374 1375 } else { 1376 1377 var $savingStateDIV = $('li.active .savingState, .topSavingState.savingState, .calendarSavingState'); 1378 var $stuffToHide = $('.monthName'); 1379 var $stuffToTransparent = $('div.booked-calendar .bc-body'); 1380 1381 } 1382 1383 if (show){ 1384 $savingStateDIV.fadeIn(200); 1385 $stuffToHide.hide(); 1386 $stuffToTransparent.animate({'opacity':0.2},100); 1387 } else { 1388 $savingStateDIV.hide(); 1389 $stuffToHide.show(); 1390 $stuffToTransparent.animate({'opacity':1},0); 1391 } 1392 1393 } 1394 1395 $(document).ajaxStop(function() { 1396 savingState(false); 1397 }); 1398 1399 function init_appt_list_date_picker(){ 1400 1401 $('.booked_list_date_picker').each(function(){ 1402 var thisDatePicker = $(this); 1403 var minDateVal = thisDatePicker.parents('.booked-appt-list').attr('data-min-date'); 1404 var maxDateVal = thisDatePicker.parents('.booked-appt-list').attr('data-max-date'); 1405 if (typeof minDateVal == 'undefined'){ var minDateVal = thisDatePicker.attr('data-min-date'); } 1406 1407 thisDatePicker.datepicker({ 1408 dateFormat: 'yy-mm-dd', 1409 minDate: minDateVal, 1410 maxDate: maxDateVal, 1411 showAnim: false, 1412 beforeShow: function(input, inst) { 1413 $('#ui-datepicker-div').removeClass(); 1414 $('#ui-datepicker-div').addClass('booked_custom_date_picker'); 1415 }, 1416 onClose: function(dateText){ 1417 $('.booked_list_date_picker_trigger').removeClass('booked-dp-active'); 1418 }, 1419 onSelect: function(dateText){ 1420 1421 var thisInput = $(this), 1422 date = dateText, 1423 thisList = thisInput.parents('.booked-list-view'), 1424 defaultDate = thisList.attr('data-default'), 1425 calendar_id = thisInput.parents('.booked-list-view-nav').attr('data-calendar-id'); 1426 1427 if (typeof defaultDate == 'undefined'){ defaultDate = false; } 1428 1429 if (!calendar_id){ calendar_id = 0; } 1430 thisList.addClass('booked-loading'); 1431 1432 var booked_load_list_view_date_booking_options = { 1433 'action' : 'booked_appointment_list_date', 1434 'nonce' : booked_js_vars.nonce, 1435 'date' : date, 1436 'calendar_id' : calendar_id, 1437 'force_default' : defaultDate 1438 }; 1439 1440 $(document).trigger("booked-before-loading-appointment-list-booking-options"); 1441 thisList.spin('booked_top'); 1442 1443 $.ajax({ 1444 url: booked_js_vars.ajax_url, 1445 type: 'post', 1446 data: booked_load_list_view_date_booking_options, 1447 success: function( html ) { 1448 1449 thisList.html( html ); 1450 1451 init_appt_list_date_picker(); 1452 setTimeout(function(){ 1453 thisList.removeClass('booked-loading'); 1454 },1); 1455 1456 } 1457 }); 1458 1459 return false; 1460 } 1461 }); 1462 1463 }); 1464 1465 $('body').on('click','.booked_list_date_picker_trigger',function(e){ 1466 e.preventDefault(); 1467 if (!$(this).hasClass('booked-dp-active')){ 1468 $(this).addClass('booked-dp-active'); 1469 $(this).parents('.booked-appt-list').find('.booked_list_date_picker').datepicker('show'); 1470 } 1471 1472 }); 1473 1474 } 1475 1476 var BookedTabs = { 1477 bookingModalSelector: '.booked-modal', 1478 tabSelector: '.booked-tabs', 1479 tabNavSelector: '.booked-tabs-nav span', 1480 tabCntSelector: '.booked-tabs-cnt', 1481 1482 Init: function() { 1483 $(document).on( 'click', this.tabNavSelector, this.tabsNav ); 1484 }, 1485 1486 tabsNav: function( event ) { 1487 event.preventDefault(); 1488 1489 BookedTabs.switchToTab( $(this) ); 1490 BookedTabs.maybeResizeBookingModal(); 1491 }, 1492 1493 switchToTab: function( tab_nav_item ) { 1494 var $nav_item = tab_nav_item, 1495 tab_cnt_class = '.' + $nav_item.data('tab-cnt'), 1496 $tabs_container = $nav_item.parents( BookedTabs.tabSelector ); 1497 1498 $nav_item 1499 .addClass( 'active' ) 1500 .siblings() 1501 .removeClass( 'active' ) 1502 1503 $tabs_container 1504 .find( BookedTabs.tabCntSelector + ' ' + tab_cnt_class ) 1505 .addClass( 'active' ) 1506 .siblings() 1507 .removeClass( 'active' ); 1508 }, 1509 1510 maybeResizeBookingModal: function() { 1511 if ( ! $(BookedTabs.bookingModalSelector).length ) { 1512 return; 1513 } 1514 1515 resize_booked_modal(); 1516 } 1517 } 1518 1519})(jQuery, window, document); 1520 1521// Create Booked Modal 1522function create_booked_modal(){ 1523 var windowHeight = jQuery(window).height(); 1524 var windowWidth = jQuery(window).width(); 1525 if (windowWidth > 720){ 1526 var maxModalHeight = windowHeight - 295; 1527 } else { 1528 var maxModalHeight = windowHeight; 1529 } 1530 1531 jQuery('body input, body textarea, body select').blur(); 1532 jQuery('body').addClass('booked-noScroll'); 1533 jQuery('<div class="booked-modal bm-loading"><div class="bm-overlay"></div><div class="bm-window"><div style="height:100px"></div></div></div>').appendTo('body'); 1534 jQuery('.booked-modal .bm-overlay').spin('booked_white'); 1535 jQuery('.booked-modal .bm-window').css({'max-height':maxModalHeight+'px'}); 1536} 1537 1538var previousRealModalHeight = 100; 1539 1540function resize_booked_modal(){ 1541 1542 var windowHeight = jQuery(window).height(); 1543 var windowWidth = jQuery(window).width(); 1544 1545 var common43 = 43; 1546 1547 if (jQuery('.booked-modal .bm-window .booked-scrollable').length){ 1548 var realModalHeight = jQuery('.booked-modal .bm-window .booked-scrollable')[0].scrollHeight; 1549 1550 if (realModalHeight < 100){ 1551 realModalHeight = previousRealModalHeight; 1552 } else { 1553 previousRealModalHeight = realModalHeight; 1554 } 1555 1556 } else { 1557 var realModalHeight = 0; 1558 } 1559 var minimumWindowHeight = realModalHeight + common43 + common43; 1560 var modalScrollableHeight = realModalHeight - common43; 1561 var maxModalHeight; 1562 var maxFormHeight; 1563 1564 if (windowHeight < minimumWindowHeight){ 1565 modalScrollableHeight = windowHeight - common43 - common43; 1566 } else { 1567 modalScrollableHeight = realModalHeight; 1568 } 1569 1570 if (windowWidth > 720){
1571 maxModalHeight = modalScrollableHeight - 25; 1572 maxFormHeight = maxModalHeight - 15; 1573 var modalNegMargin = (maxModalHeight + 78) / 2; 1574 } else { 1575 maxModalHeight = windowHeight - common43; 1576 maxFormHeight = maxModalHeight - 60; 1577 var modalNegMargin = (maxModalHeight) / 2; 1578 } 1579 1580 jQuery('.booked-modal').css({'margin-top':'-'+modalNegMargin+'px'}); 1581 jQuery('.booked-modal .bm-window').css({'max-height':maxModalHeight+'px'}); 1582 jQuery('.booked-modal .bm-window .booked-scrollable').css({'max-height':maxFormHeight+'px'}); 1583 1584} 1585 1586function close_booked_modal(){ 1587 var modal = jQuery('.booked-modal'); 1588 modal.fadeOut(200); 1589 modal.addClass('bm-closing'); 1590 jQuery('body').removeClass('booked-noScroll'); 1591 setTimeout(function(){ 1592 modal.remove(); 1593 },300); 1594} 1595 1596function init_tooltips(container){ 1597 jQuery('.tooltipster').tooltipster({ 1598 theme: 'tooltipster-light', 1599 animation: 'grow', 1600 speed: 200, 1601 delay: 50, 1602 offsetY: -15 1603 }); 1604} 1605 1606// Function to adjust calendar sizing 1607function adjust_calendar_boxes(){ 1608 jQuery('div.booked-calendar').each(function(){ 1609 1610 var windowWidth = jQuery(window).width(); 1611 var smallCalendar = jQuery(this).parents('.booked-calendar-wrap').hasClass('small'); 1612 var boxesWidth = jQuery(this).find('.bc-body .bc-row.week .bc-col').width(); 1613 var calendarHeight = jQuery(this).height(); 1614 boxesHeight = boxesWidth * 1; 1615 jQuery(this).find('.bc-body .bc-row.week .bc-col').height(boxesHeight); 1616 jQuery(this).find('.bc-body .bc-row.week .bc-col .date').css('line-height',boxesHeight+'px'); 1617 jQuery(this).find('.bc-body .bc-row.week .bc-col .date .number').css('line-height',boxesHeight+'px'); 1618 if (smallCalendar || windowWidth < 720){ 1619 jQuery(this).find('.bc-body .bc-row.week .bc-col .date .number').css('line-height',boxesHeight+'px'); 1620 } else { 1621 jQuery(this).find('.bc-body .bc-row.week .bc-col .date .number').css('line-height',''); 1622 } 1623 1624 var calendarHeight = jQuery(this).height(); 1625 jQuery(this).parent().height(calendarHeight); 1626 1627 }); 1628}
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.