PageSourceSearch

https://www.citybreakapartments.com/wp-content/plugins/custom-search-form/assets/form-script.js

js citybreakapartments.com collected 2026-10-05 02:55:49 UTC 6,023 bytes, 174 lines download raw bytes

1jQuery(document).ready(function ($) {
2    const isMobile = window.innerWidth <= 768; // You can adjust 768px as needed
3
4    const fp = flatpickr("#date-range", {
5        mode: "range",
6        dateFormat: "Y-m-d",
7        minDate: "today",
8        showMonths: isMobile ? 1 : 2,
9        static: false,
10        clickOpens: true,
11        closeOnSelect: false,
12		locale: {
13			firstDayOfWeek: 1 // Monday as the first day
14		},
15        onReady: function (selectedDates, dateStr, instance) {
16            const container = instance.calendarContainer;
17    
18            if (!container.querySelector(".flatpickr-footer")) {
19                const footer = document.createElement("div");
20                footer.className = "flatpickr-footer";
21                footer.innerHTML = `
22                    <button type="button" class="flatpickr-cancel">Cancel</button>
23                    <button type="button" class="flatpickr-confirm">Confirm</button>
24                `;
25                container.appendChild(footer);
26    
27                //footer.querySelector(".flatpickr-cancel").onclick = () => instance.clear();
28				footer.querySelector(".flatpickr-cancel").onclick = () => {
29					instance.clear();
30					instance.selectedDates = []; 
31					$("#arrival-date").val('');
32					$("#departure-date").val('');
33					instance.close();
34				};
35                footer.querySelector(".flatpickr-confirm").onclick = () => instance.close(); // only this closes it now
36            }
37        },
38        onChange: function (selectedDates) {
39            if (selectedDates.length === 2) {
40                const start = selectedDates[0].toLocaleDateString("en-GB", {
41                    weekday: "short",
42                    day: "2-digit",
43                    month: "short",
44                    year: "numeric",
45                });
46                const end = selectedDates[1].toLocaleDateString("en-GB", {
47                    weekday: "short",
48                    day: "2-digit",
49                    month: "short",
50                    year: "numeric",
51                });
52    
53                $("#arrival-date").val(flatpickr.formatDate(selectedDates[0], "Y-m-d"));
54                $("#departure-date").val(flatpickr.formatDate(selectedDates[1], "Y-m-d"));
55                $("#date-range").val(`${start} – ${end}`);
56            }
57        }
58    });
59    
60    $(window).on('resize', function() {
61        const newIsMobile = window.innerWidth <= 768;
62        if ((newIsMobile && fp.config.showMonths !== 1) || (!newIsMobile && fp.config.showMonths !== 2)) {
63            fp.set('showMonths', newIsMobile ? 1 : 2);
64        }
65    });
66
67    $('#guest-summary-wrapper').on('click', function (e) {
68        $('#guest-popup').toggle();
69        e.stopPropagation();
70    });
71
72    $(document).on('click', function (e) {
73        if (!$(e.target).closest('#guest-summary-wrapper').length && !$(e.target).closest('#guest-popup').length) {
74            $('#guest-popup').hide();
75        }
76    });
77	
78	function updateGuestButtons() {
79		const a = parseInt($('#guest-adult-input').val());
80		const c = parseInt($('#guest-child-input').val());
81		const i = parseInt($('#guest-infant-input').val());
82		const total = a + c + i;
83
84		// Disable plus buttons if total is 10
85		if (total >= 10) {
86			$('.plus').prop('disabled', true).addClass('disabled');
87		} else {
88			$('.plus').prop('disabled', false).removeClass('disabled');
89		}
90
91		// Disable minus for adults if value is 1
92		if (a <= 1) {
93			$('[data-target="guest-adult-input"].minus').prop('disabled', true).addClass('disabled');
94		} else {
95			$('[data-target="guest-adult-input"].minus').prop('disabled', false).removeClass('disabled');
96		}
97
98		// Disable minus buttons for 0 minimum on children and infants
99		$('[data-target="guest-child-input"].minus').prop('disabled', c <= 0).toggleClass('disabled', c <= 0);
100		$('[data-target="guest-infant-input"].minus').prop('disabled', i <= 0).toggleClass('disabled', i <= 0);
101	}
102    // Attach event
103	$('.plus, .minus').on('click', function (e) {
104		e.stopPropagation();
105		const input = $('#' + $(this).data('target'));
106		let val = parseInt(input.val());
107
108		const a = parseInt($('#guest-adult-input').val());
109		const c = parseInt($('#guest-child-input').val());
110		const i = parseInt($('#guest-infant-input').val());
111		const total = a + c + i;
112
113		if ($(this).hasClass('plus')) {
114			if (total < 10) {
115				val++;
116			}
117		} else {
118			const min = parseInt(input.attr('min')) || 0;
119			val = Math.max(val - 1, min);
120		}
121
122		input.val(val).trigger('change');
123		updateGuestButtons();
124	});
125
126    $('#guest-popup input').on('change', function () {
127		const a = parseInt($('#guest-adult-input').val());
128		const c = parseInt($('#guest-child-input').val());
129		const i = parseInt($('#guest-infant-input').val());
130
131		let summary = `${a} Ad`;
132		if (c > 0) summary += `, ${c} Ch`;
133		if (i > 0) summary += `, ${i} In`;
134
135		$('#guest-summary').val(summary);
136		$('#guest-adult').val(a);
137		$('#guest-child').val(c);
138		$('#guest-infant').val(i);
139
140		updateGuestButtons();
141	});
142
143    $('#custom-booking-form').on('submit', function (e) {
144		e.preventDefault();
145		const arrival = $('#arrival-date').val();
146		const departure = $('#departure-date').val();
147		const guests = `adult.${$('#guest-adult').val()}-child.${$('#guest-child').val()}-infant.${$('#guest-infant').val()}`;
148
149		if (!arrival || !departure) {
150			showCustomAlert("Please select dates and guests to continue");
151			return;
152		}
153
154		window.open(`https://booking.citybreakapartments.com/?arrival=${arrival}&departure=${departure}&guests=${guests}`, '_blank');
155	});
156	// Function to show alert
157	function showCustomAlert(message) {
158		const alertBox = $(`
159			<div class="search-form-custom-alert">
160				<span class="custom-alert-icon"><i class="fi-info" aria-hidden="true"></i></span>
161				<span>${message}</span>
162			</div>
163		`);
164		$('body').append(alertBox);
165		setTimeout(() => {
166			alertBox.fadeOut(500, function () {
167				$(this).remove();
168			});
169		}, 4000);
170	}
171    $('.input-button').on('click', function () {
172        $(this).find('#date-range').focus();
173    });
174});

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.