PageSourceSearch

https://parogongroup.co.uk/wp-content/themes/parogon-group/booking/js/booking.js

js parogongroup.co.uk collected 2026-09-24 13:18:44 UTC 21,418 bytes, 664 lines download raw bytes

1/*     ------------------------------
2       Paragon Group Booking Widget
3       Created by Harrison Carloss
4       -------------------------------
5*/
6
7jQuery(document).ready(function ($) {
8  // Shows the booking popup on click
9  function toggleBookingPopup() {
10    $(".book-table").toggleClass("active");
11    $("body").removeClass("menu-open");
12    $(".booking-slide-out").toggleClass("active");
13    $("body").toggleClass("booking-active");
14    $("html").toggleClass("booking-active");
15    $("#container").toggleClass("booking-active");
16    // load in booking columns
17    anime({
18      targets: ".booking-column",
19      translateY: [40, 0],
20      opacity: [0, 1],
21      duration: 1000,
22      delay: anime.stagger(300),
23      easing: "easeInOutQuad",
24    });
25  }
26
27  if (window.location.href.indexOf("#book") > -1) {
28    // toggleBookingPopup();
29  }
30  $(".book-table:not(.inactive), .mobile-close-booking").click(function () {
31    // toggleBookingPopup();
32    // if (window.location.href.indexOf("#book") > 1) {
33    // 	window.location.hash = "";
34    // } else {
35    // 	window.location.hash = "book";
36    // }
37  });
38
39  // Closes the booking popup when clicked out of dropdown
40  $("body").click(function (e) {
41    if (
42      !$(e.target).closest(
43        ".booking-slide-out, .book-table, .booking-date, .ui-corner-all"
44      ).length
45    ) {
46      $(".booking-slide-out.active, .book-table").removeClass("active");
47      $("#container").removeClass("booking-active");
48    }
49  });
50
51  // Define the booking variables
52  var bookingLocation = null;
53  var restaurantName = null;
54  var locationPrefix = null;
55  var locationAuthCode = null;
56  var bookingSession = null;
57  var bookingGuestCount = null;
58  var date = null;
59  var today = new Date();
60  var bookingDayOfWeek = null;
61  var bookingDate = null;
62  var dateToStartBookings = null;
63  var bookingFormattedDate = null;
64  var bookingFormattedTime = null;
65  var guestTitle = null;
66  var guestForename = null;
67  var guestSurname = null;
68  var guestTelephone = null;
69  var guestEmail = null;
70  var message = null;
71  var availableRestaurants = 0;
72  var restaurantsChecked = 0;
73  var phoneNumber = null;
74
75  // Resets any selected criteria
76  function resetCriteria() {
77    $(".times.booking-popup .info .response").html(null);
78    $(".booking-time").val("Select a time").removeClass("selected");
79    $(".choose-session li").removeClass("active");
80    $(".continue-booking").removeClass("active");
81  }
82
83  // Formats the display date
84  var months = new Array(12);
85  months[0] = "January";
86  months[1] = "February";
87  months[2] = "March";
88  months[3] = "April";
89  months[4] = "May";
90  months[5] = "June";
91  months[6] = "July";
92  months[7] = "August";
93  months[8] = "September";
94  months[9] = "October";
95  months[10] = "November";
96  months[11] = "December";
97
98  // Add correct prefix to day
99  function nth(d) {
100    if (d > 3 && d < 21) return "th";
101    switch (d % 10) {
102      case 1:
103        return "st";
104      case 2:
105        return "nd";
106      case 3:
107        return "rd";
108      default:
109        return "th";
110    }
111  }
112
113  // Shows the booking date popup
114  $(".select-date, .display-date").click(function () {
115    $(".booking-date-popup").toggleClass("show");
116  });
117  // don't allow bookings before launch date
118  dateToStartBookings = new Date("2019-09-10");
119  if (today > dateToStartBookings) {
120    dateToStartBookings = today;
121  }
122  // Calls the jQuery datepicker widget
123  $(".booking-date")
124    .datepicker({
125      dateFormat: "yyyy-mm-dd",
126      minDate: dateToStartBookings,
127      onSelect: function () {
128        date = $(this).datepicker("getDate");
129        day = date.getDate();
130        month = date.getMonth();
131        year = date.getFullYear();
132        $(".display-date .day").html(day + nth(day));
133        $(".display-date .monthyear").html(months[month] + " " + year);
134        bookingDayOfWeek = date.toLocaleDateString("en-GB", {
135          weekday: "long",
136        });
137        resetCriteria();
138        $(".booking-date-popup").removeClass("show");
139      },
140    })
141    .datepicker("setDate", new Date());
142
143  // Adds the chosen date into the widget
144  date = $(".booking-date").datepicker("getDate");
145  day = date.getDate();
146  month = date.getMonth();
147  year = date.getFullYear();
148  $(".display-date .day").html(day + nth(day));
149  $(".display-date .monthyear").html(months[month] + " " + year);
150
151  // Stop propagation to prevent hiding "#tooltip" when clicking on it
152  $(".arrow").on("click touch", function (event) {
153    event.stopPropagation();
154  });
155  $(".restaurant-item").click(function (e) {
156    $(".booking-popup.show").removeClass("show");
157    $(".booking-popup.recommend").removeClass("recommend");
158    resetCriteria();
159  });
160
161  // Shows the restaurant list on click
162  $(".locations:not(.inactive), .select-restaurant").click(function () {
163    $(".restaurant-list").toggleClass("show");
164    $(".booking-slide-out").toggleClass("has-popup");
165    // load in pub logos
166    anime({
167      targets: ".booking-slide-out .booking-popup.restaurant-list ul li img",
168      translateY: [40, 0],
169      opacity: [0, 1],
170      duration: 1000,
171      delay: anime.stagger(200),
172      easing: "easeInOutQuad",
173    });
174  });
175
176  // Toggles the selected restaurant
177  $(".location1").addClass("is-selected");
178  $(".restaurant-list li.restaurant-item").click(function () {
179    var tab = $(this).data("restaurant");
180    $(".restaurant-item, .restaurant-image").removeClass("is-selected");
181    $(this).addClass("is-selected");
182    $(".restaurant-image." + tab).addClass("is-selected");
183    $(".restaurant-item." + tab).addClass("is-selected");
184  });
185  $(".restaurant-list li.restaurant-item").hover(function () {
186    $(".restaurant-image").removeClass("preview");
187    var tab = $(this).data("restaurant");
188    $(".restaurant-image." + tab).toggleClass("preview");
189  });
190
191  // Increases / Decreases the amount of guests required
192  $(".increase-guests").click(function () {
193    resetCriteria();
194    var val = $(".guest-count").val();
195    var nextVal = val++ + 1;
196    if (nextVal === 8) {
197      $(".increase-guests").fadeOut();
198    }
199    if (val <= 8) {
200      $(".guest-count").val(function (i, oldval) {
201        return ++oldval;
202      });
203      if (--val >= 1) {
204        $(".decrease-guests").fadeIn();
205      }
206    } else {
207      $(".increase-guests").fadeOut();
208    }
209  });
210  $(".decrease-guests").click(function () {
211    resetCriteria();
212    var val = $(".guest-count").val();
213    var prevVal = val-- - 1;
214    if (prevVal === 1) {
215      $(".decrease-guests").fadeOut();
216    }
217    if (val >= 1) {
218      $(".guest-count").val(function (i, oldval) {
219        return --oldval;
220      });
221      if (--val <= 8) {
222        $(".increase-guests").fadeIn();
223      }
224    } else {
225      $(".decrease-guests").fadeOut();
226    }
227  });
228
229  $(".guest-count").keyup(function () {
230    if ($(".guest-count").val() > 8) {
231      $(".guest-count").val(8);
232      $(".booking-column.guests").addClass("too-many-guests");
233      setTimeout(function () {
234        $(".booking-column.guests").removeClass("too-many-guests");
235      }, 2000);
236    }
237  });
238
239  $("input[readonly]").on("focus", function () {
240    return false;
241  });
242
243  // GetSessionAvailability - sends data to Quadranet to check if the required booking is available
244  $(".showTimes").click(function () {
245    // show or hide breakfast
246    // if (bookingDayOfWeek === 'Saturday' || bookingDayOfWeek === 'Sunday') {
247    //     $('.breakfast-selector').show();
248    // } else {
249    //     $('.breakfast-selector').hide();
250    // }
251    $(".times.booking-popup").addClass("show");
252    $(".times.booking-popup").removeClass("recommend");
253    $(".other-restaurants").removeClass("is-active");
254  });
255  $(".booking-popup .close").click(function () {
256    $(".booking-popup").removeClass("show");
257  });
258  $(".choose-session li").on("click touchend", function () {
259    anime({
260      targets: ".booking-slide-out .other-restaurants .hint",
261      opacity: 0,
262    });
263    $(
264      ".recommend-restaurants, .booking-slide-out .other-restaurants"
265    ).removeClass("is-active");
266    $(".times.booking-popup.show.recommend").removeClass("recommend");
267
268    bookingLocation = $(".restaurant - item.is - selected").data("restaurant");
269    locationPrefix = $(".restaurant-item.is-selected").data("prefix");
270    phoneNumber = $(".restaurant-item.is-selected").data("phone");
271    restaurantName = $(".restaurant-item.is-selected").data("name");
272    bookingSession = $(this).data("session");
273    $(".times.booking-popup .info .response").html(null);
274    $(".continue-booking").removeClass("active");
275    $(".choose-session li").removeClass("active");
276    $(this).addClass("active");
277    $(".times .loader").show();
278    $(".times.booking-popup").addClass("show");
279    bookingGuestCount = $(".guest-count").val();
280    var date = $(".booking-date").datepicker("getDate");
281    bookingFormattedDate = $.datepicker.formatDate("yy-mm-dd", date);
282    $.ajax({
283      type: "POST",
284      url: "/wp-admin/admin-ajax.php",
285      data: {
286        action: "get_times",
287        prefix: locationPrefix,
288        session: bookingSession,
289        productid: "1",
290        atdate: bookingFormattedDate,
291        covers: bookingGuestCount,
292        phone: phoneNumber,
293        restaurantName: restaurantName,
294      },
295      success: function (data) {
296        anime({
297          targets: ".booking-slide-out .other-restaurants .hint",
298          opacity: 1,
299        });
300        $(".times .loader").hide();
301        $(".recommend-restaurants").addClass("is-active");
302        $(".times.booking-popup .info .response").html(data);
303      },
304      error: function (data) {
305        anime({
306          targets: ".booking-slide-out .other-restaurants .hint",
307          opacity: 0,
308        });
309        $(".times .loader").hide();
310        $(".times.booking-popup .info .response").html(
311          '<p class="error">Sorry, there are no times available. Please try another date.</p><a class="go-back">Go back</a>'
312        );
313      },
314    });
315  });
316
317  // Add the selected time to the input
318  var chosenTime = null;
319  $(".times").on("click", "li.time.available", function (event) {
320    $(".times li").removeClass("selected");
321    chosenTime = $(this).data("time");
322    $(this).addClass("selected");
323    $(".booking-popup").removeClass("show");
324    $(".booking-time").val(chosenTime).addClass("selected");
325    $(".continue-booking").addClass("active");
326  });
327
328  $(".times").on("click", "li.time.reserved", function (event) {
329    $(".times li").removeClass("selected");
330    chosenTime = $(this).data("time");
331    $(this).addClass("selected");
332  });
333
334  // CROSS SELLING - Get times for other restaurants
335  function CheckRestaurant(
336    bookingSession,
337    bookingFormattedDate,
338    bookingGuestCount,
339    crossSellLocationPrefix,
340    crossSellRestaurantName,
341    timeWanted
342  ) {
343    $.ajax({
344      type: "POST",
345      url: "/wp-admin/admin-ajax.php",
346      data: {
347        action: "get_times",
348        prefix: crossSellLocationPrefix,
349        session: bookingSession,
350        productid: "1",
351        atdate: bookingFormattedDate,
352        covers: bookingGuestCount,
353        timeWanted: timeWanted,
354      },
355      success: function (data) {
356        restaurantsChecked++;
357        if ($.trim(data) === "true") {
358          availableRestaurants++;
359          $("." + crossSellLocationPrefix)
360            .addClass("is-available")
361            .data("time", timeWanted);
362        }
363        data = null;
364        if (
365          restaurantsChecked ==
366          $(".other-restaurants .restaurants .other-restaurant").length
367        ) {
368          // FIX
369          $(".booking-slide-out .other-restaurants .restaurants").addClass(
370            "visible"
371          );
372          $(".other-restaurants .loader").hide();
373          anime({
374            targets: ".booking-slide-out .other-restaurants .hint",
375            translateY: [20, 0],
376            opacity: [0, 1],
377            duration: 800,
378            delay: anime.stagger(100),
379            easing: "easeInOutQuad",
380          });
381          if (availableRestaurants === 0) {
382            $(".booking-slide-out .other-restaurants .restaurants").removeClass(
383              "visible"
384            );
385            $(".booking-slide-out .other-restaurants .no-restaurants").addClass(
386              "visible"
387            );
388            anime({
389              targets: ".booking-slide-out .other-restaurants .no-restaurants",
390              translateY: [20, 0],
391              opacity: [0, 1],
392              duration: 1000,
393              delay: anime.stagger(200),
394              easing: "easeInOutQuad",
395            });
396          }
397        }
398      },
399    });
400  }
401
402  $(".times").on("click", "li.time.reserved:not(.inactive)", function (event) {
403    restaurantsChecked = 0;
404    anime({
405      targets: ".booking-slide-out .other-restaurants .hint",
406      opacity: 0,
407    });
408    availableRestaurants = 0;
409    $(".booking-slide-out .other-restaurants .no-restaurants").removeClass(
410      "visible"
411    );
412    // sets variable to the time user would like
413    var timeWanted = $(this).data("time");
414    // shows the other restaurants bar
415    $(".booking-popup.times").addClass("recommend");
416    $(".other-restaurants").addClass("is-active");
417    $(".booking-slide-out .other-restaurants .restaurants li").removeClass(
418      "is-available"
419    );
420    $(".booking-slide-out .other-restaurants .restaurants").removeClass(
421      "visible"
422    );
423    $(".other-restaurants .loader").show();
424    $(".other-restaurants .restaurants .other-restaurant").each(function () {
425      var crossSellBookingLocation = $(this).data("restaurant");
426      var crossSellLocationPrefix = $(this).data("prefix");
427      var crossSellRestaurantName = $(this).data("name");
428
429      CheckRestaurant(
430        bookingSession,
431        bookingFormattedDate,
432        bookingGuestCount,
433        crossSellLocationPrefix,
434        crossSellRestaurantName,
435        timeWanted
436      );
437    });
438  });
439
440  $(".times").on("click", ".other-restaurant.is-available", function (event) {
441    $(".booking-time").val($(this).data("time")).addClass("selected");
442    $(".booking-slide-out .booking-popup.show").removeClass("show");
443    $(".booking-slide-out .other-restaurants.is-active").removeClass(
444      "is-active"
445    );
446    $(".booking-slide-out .other-restaurants .restaurants").removeClass(
447      "visible"
448    );
449    var tab = $(this).data("restaurant");
450    $(".restaurant-item, .restaurant-image").removeClass("is-selected");
451    $("." + tab).addClass("is-selected");
452    $(".restaurant-image." + tab).addClass("is-selected");
453    $(".restaurant-item." + tab).addClass("is-selected");
454    $(".booking-popup").removeClass("show");
455    locationPrefix = $(".restaurant-item.is-selected").data("prefix");
456    phoneNumber = $(".restaurant-item.is-selected").data("phone");
457    restaurantName = $(".restaurant-item.is-selected").data("name");
458    $(".continue-booking").addClass("active");
459  });
460  // Ask user for more details to confirm booking
461  $(".booking-widget-container").on(
462    "click",
463    ".continue-booking.active",
464    function (event) {
465      bookingFormattedTime = $(".booking-time").val();
466      $(".confirm-popup").addClass("show");
467      $(".make-booking .guests").html(bookingGuestCount);
468      $(".make-booking .location").html(restaurantName);
469      $(".make-booking .date").html(bookingFormattedDate);
470      $(".make-booking .time").html(bookingFormattedTime);
471      // load in fields
472      anime({
473        targets:
474          ".make-booking .fields input:not(.marketing), .make-booking .fields textarea, .make-booking .marketing",
475        translateY: [40, 0],
476        opacity: [0, 1],
477        duration: 1000,
478        delay: anime.stagger(200),
479        easing: "easeInOutQuad",
480      });
481      anime({
482        targets: ".make-booking .fields .field span",
483        width: "100%",
484        easing: "easeInOutQuad",
485      });
486    }
487  );
488
489  $(".close-others").click(function () {
490    $(".booking-slide-out .other-restaurants.is-active").removeClass(
491      "is-active"
492    );
493    $(".booking-slide-out .other-restaurants .no-restaurants").removeClass(
494      "visible"
495    );
496    $(".times.booking-popup.show.recommend").removeClass("recommend");
497    $(".booking-slide-out .other-restaurants .restaurants").removeClass(
498      "visible"
499    );
500    $(".booking-slide-out .other-restaurants .restaurants .other-restaurant")
501      .removeClass("is-available")
502      .removeClass("is-selected");
503  });
504
505  // book table on click
506  $(".reserve-table").click(function () {
507    var isFormValid = $(".booking-popup form.fields")[0].checkValidity();
508    if (isFormValid === true) {
509      $(".confirm-popup .loader").show();
510      guestTitle = $(".title-prefix").val();
511      guestForename = $(".first-name").val();
512      guestSurname = $(".last-name").val();
513      guestTelephone = $(".telephone-number").val();
514      guestEmail = $(".email-address").val();
515      var marketing = null;
516      if ($(".marketing").is(":checked")) {
517        marketing = "yes";
518      }
519      message = $(".special-preferences").val();
520      $(".confirm-popup .response").html(null);
521      $(".fields").hide();
522      $(".tablefor").hide();
523      bookingDate = date;
524
525      $.ajax({
526        type: "POST",
527        url: "/wp-admin/admin-ajax.php",
528        data: {
529          action: "book_table",
530          prefix: locationPrefix,
531          restaurantName: restaurantName,
532          session: bookingSession,
533          productid: "1",
534          atdate: bookingFormattedDate,
535          attime: bookingFormattedTime,
536          covers: bookingGuestCount,
537          title: guestTitle,
538          forename: guestForename,
539          surname: guestSurname,
540          telephone: guestTelephone,
541          email: guestEmail,
542          message: message,
543          marketing: marketing,
544          phone: phoneNumber,
545          restaurantName: restaurantName,
546        },
547        success: function (data) {
548          $(".confirm-popup .loader").hide();
549          $(".confirm-popup .response").html(data);
550          $(".confirm-popup .guests").html(bookingGuestCount);
551          $(".confirm-popup .location").html(restaurantName);
552          $(".confirm-popup .date").html(bookingFormattedDate);
553          $(".confirm-popup .time").html(bookingFormattedTime);
554        },
555        error: function (data) {
556          $(".confirm-popup .loader").hide();
557          alert("There was an issue making the booking: " + data.responseText);
558        },
559      });
560    }
561  });
562  $(".confirm-popup").on("click", ".response .go-back", function (event) {
563    $(".confirm-popup .response").html(null);
564    $(".fields").show();
565    $(".tablefor").show();
566  });
567
568  // cancel booking
569  $(".cancel-booking").click(function () {
570    $.urlParam = function (name) {
571      var results = new RegExp("[?&]" + name + "=([^&#]*)").exec(
572        window.location.href
573      );
574      if (results == null) {
575        return null;
576      } else {
577        return decodeURI(results[1]) || 0;
578      }
579    };
580    var forename = $.urlParam("forename");
581    var surname = $.urlParam("surname");
582    var date = $.urlParam("date");
583    var time = $.urlParam("time");
584    $("body").addClass("confirm-cancel");
585    $(".cancellation-container .confirmation")
586      .addClass("active")
587      .prepend(
588        '<div class="before-confirm"><h2>Confirmation</h2>' +
589          forename +
590          " " +
591          surname +
592          ", are you sure you want to cancel your booking on " +
593          date +
594          " at " +
595          time +
596          "?</div>"
597      );
598  });
599  $(".confirm-cancel-booking").click(function () {
600    $.urlParam = function (name) {
601      var results = new RegExp("[?&]" + name + "=([^&#]*)").exec(
602        window.location.href
603      );
604      if (results == null) {
605        return null;
606      } else {
607        return decodeURI(results[1]) || 0;
608      }
609    };
610    var bookingRef = $.urlParam("reference");
611    var prefix = $.urlParam("prefix");
612    $(
613      ".cancellation-container .confirmation .before-confirm, .confirm-cancel-booking"
614    ).hide();
615    $(".cancellation-container .loader").show();
616    $.ajax({
617      type: "POST",
618      url: "/wp-admin/admin-ajax.php",
619      data: {
620        action: "cancel_booking",
621        visitID: bookingRef,
622        prefix: prefix,
623      },
624      success: function (data) {
625        $(".cancellation-container .loader").hide();
626        $(".cancellation-container .confirmation").html(data);
627        $(
628          ".cancellation-container > p, .cancellation-container .cancel-booking"
629        ).detach();
630        var delay = 5000;
631        var URL = "/";
632        setTimeout(function () {
633          window.location = URL;
634        }, delay);
635      },
636      error: function (data) {
637        $(".cancellation-container .loader").hide();
638        $(".cancellation-container .confirmation").html(data);
639      },
640    });
641  });
642  $("body").click(function (e) {
643    if (
644      !$(e.target).closest(
645        ".cancellation-container .confirmation, .cancel-booking"
646      ).length
647    ) {
648      $(".cancellation-container .confirmation").removeClass("active");
649      $("body.confirm-cancel").removeClass("confirm-cancel");
650      $(".before-confirm").detach();
651    }
652  });
653
654  $(".confirm-popup").on(
655    "click",
656    ".response .finish-booking",
657    function (event) {
658      $(".booking-slide-out.active, .book-table").removeClass("active");
659      $(".booking-slide-out .booking-popup").removeClass("show");
660      $("#container").removeClass("booking-active");
661      resetCriteria();
662    }
663  );
664});

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.