PageSourceSearch

https://sirchristopherwren.co.uk/wp-content/themes/sarova-hotels/js/booking-form.js?ver=8.6.0

js sirchristopherwren.co.uk collected 2026-09-26 13:16:59 UTC 9,453 bytes, 170 lines download raw bytes

1document.addEventListener("DOMContentLoaded", (function() {
2	themeData.themeUrl;
3	const t = document.getElementById("room-number"),
4		e = document.getElementById("overlay-container"),
5		n = document.getElementById("close-overlay"),
6		o = document.getElementById("rooms-container"),
7		l = (document.querySelector(".sarova-booking-container"), document.getElementById("sarova-content")),
8		r = document.querySelector("#booking-form-container"),
9		i = document.querySelector("#fixed-book-now"),
10		c = (document.querySelector(".on-load-book-now"), new URLSearchParams(window.location.search).get("Code"));
11	if (c) {
12		const t = document.getElementById("promo-code");
13		t && (t.value = c)
14	}
15
16	function a(t) {
17		let e = document.getElementById("toast-container");
18		e ? e.style.display = "flex" : (e = document.createElement("div"), e.id = "toast-container", e.style.position = "fixed", e.style.bottom = "20px", e.style.right = "20px", e.style.display = "flex", e.style.flexDirection = "column", e.style.alignItems = "flex-end", document.body.appendChild(e));
19		const n = document.createElement("div");
20		n.className = "toast", n.textContent = t, e.appendChild(n), setTimeout((() => {
21			n.classList.add("show")
22		}), 100), setTimeout((() => {
23			n.classList.remove("show"), n.addEventListener("transitionend", (() => {
24				e.removeChild(n), 0 === e.childElementCount && (e.style.display = "none")
25			}))
26		}), 3100)
27	}
28	t && (t.value = "1 Room | 2 Adults | 0 Children");
29	const d = document.querySelector(".book-now-primary");
30
31	function s() {
32		const e = document.querySelectorAll(".room");
33		let n = e.length,
34			o = 0,
35			l = 0;
36		e.forEach((t => {
37			const e = t.getAttribute("data-room"),
38				n = parseInt(t.querySelector(`#adults-${e}`).value, 10) || 0,
39				r = parseInt(t.querySelector(`#children-${e}`).value, 10) || 0;
40			o += n, l += r
41		}));
42		const r = 1 === n ? "Room" : "Rooms",
43			i = 1 === o ? "Adult" : "Adults",
44			c = 1 === l ? "Child" : "Children";
45		t && (t.value = `${n} ${r} | ${o} ${i} | ${l} ${c}`)
46	}
47	d && d.addEventListener("click", (function(t) {
48		t.preventDefault();
49		try {
50			const t = themeData.bookingWidgetUrl || "https://www.sarova.com",
51				e = themeData.hotelBookingId || "75003",
52				n = document.getElementById("datepicker").value;
53			if (!n) return void a("Please select your Arrival and Departure dates.");
54			const o = n.split(" - ");
55			if (2 !== o.length) return void a("Error: Invalid date range format.");
56			const months = {Jan:"01",Feb:"02",Mar:"03",Apr:"04",May:"05",Jun:"06",Jul:"07",Aug:"08",Sep:"09",Oct:"10",N
56ov:"11",Dec:"12"};
57			const [l, r] = o.map((t => {
58				const p = t.trim().split(" ");
59				return `${p[2]}-${months[p[1]]}-${p[0].padStart(2,"0")}`;
60			}));
61			if (r <= l) return void a("Your stay must be at least 1 night. Please select a later check-out date.");
62			let i = `hotel=${e}&arrival=${l}&departure=${r}`;
63			const c = document.querySelectorAll(".room");
64			i += `&rooms=${c.length}`, c.forEach(((t, e) => {
65				const n = e + 1,
66					o = t.querySelector(`#adults-${n}`).value,
67					l = t.querySelector(`#children-${n}`).value;
68				i += `&adults%5B${n}%5D=${o}&children%5B${n}%5D=${l}`, l > 0 && t.querySelectorAll(`#children-ages-${n} select`).forEach(((t, e) => {
69					const o = t.value;
70					i += `&childAge%5B${n}%5D%5B${e+1}%5D=${o}`
71				}))
72			}));
73			const d = document.getElementById("promo-code"),
74			s = d ? d.value.trim() : "",
75			u = `${t}/?${i}${s?`&code=${s}`:""}`,
76			targetUrl = themeData.bookingSystem ? `/booking-page-maintenance/?${i}${s?`&code=${s}`:""}` : u;
77			window.open(targetUrl, "_blank")
78		} catch (t) {
79			console.error("Form Submission Error:", t), a("An error occurred during form submission. Please contact the hotel to make a booking.")
80		}
81	})), t && e && t.addEventListener("click", (() => {
82		e.classList.add("show")
83	})), n && n.addEventListener("click", (() => {
84		s(), e && e.classList.remove("show")
85	}));
86	const u = document.getElementById("add-room");
87
88	function m(t) {
89		const e = t.split("-")[1],
90			n = parseInt(document.getElementById(`children-${e}`).value, 10),
91			o = document.getElementById(`children-ages-${e}`);
92		o.innerHTML = "";
93		const l = document.createDocumentFragment();
94		for (let t = 1; t <= n; t++) {
95			const n = document.createElement("label");
96			n.textContent = `Child ${t} `;
97			const o = document.createElement("select");
98			o.name = `childAge-${e}-${t}`, o.required = !0, o.className = "child-age-select";
99			for (let t = 1; t <= 12; t++) {
100				const e = document.createElement("option");
101				e.value = t, e.textContent = `${t} yr${t>1?"s":""}`, o.appendChild(e)
102			}
103			n.appendChild(o), l.appendChild(n)
104		}
105		o.appendChild(l)
106	}
107
108	function y() {
109		const t = document.querySelectorAll(".room");
110		t.forEach(((e, n) => {
111			const o = e.querySelector(".remove-room");
112			o && (o.style.display = t.length > 1 ? "inline-block" : "none")
113		}))
114	}
115
116	function h(t) {
117		r && (t ? (r.classList.remove("hide"), r.classList.add("show"), r.style.display = "block", l && l.classList.add("nofocus")) : (r.classList.remove("show"), r.classList.add("hide"), setTimeout((() => {
118			r.style.display = "none", "function" == typeof window.checkVisibilityAndStickyNav && window.checkVisibilityAndStickyNav()
119		}), 500), l && l.classList.remove("nofocus")), "function" == typeof window.checkVisibilityAndStickyNav && window.checkVisibilityAndStickyNav())
120	}
121	u && o && u.addEventListener("click", (function() {
122		if (o.children.length >= 3) return void a("You can only add up to 3 rooms.");
123		const t = o.children.length + 1,
124			e = document.createElement("div");
125		e.classList.add("room"), e.setAttribute("data-room", t), e.innerHTML = function(t) {
126			return `\n\t\t\t\t<div class="room-nr-title">\n\t\t\t\t\tRoom ${t} \n\t\t\t\t\t${t>1?`<button type="button" class="remove-room" data-room="${t}">Remove Room</button>`:""}\n\t\t\t\t</div>\n\t\t\t\t<div class="form-group">\n\t\t\t\t\t<div class="label-input">\n\t\t\t\t\t\t<label for="adults-${t}">Adults</label>\n\t\t\t\t\t\t<div class="quantity-control">\n\t\t\t\t\t\t\t<button type="button" class="quantity-btn minus-icon" data-target="adults-${t}" data-action="decrement">-</button>\n\t\t\t\t\t\t\t<input type="text" id="adults-${t}" name="adults-${t}" value="2" readonly>\n\t\t\t\t\t\t\t<button type="button" class="quantity-btn plus-icon" data-target="adults-${t}" data-action="increment">+</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class="label-input">\n\t\t\t\t\t\t<label for="children-${t}">Children</label>\n\t\t\t\t\t\t<div class="quantity-control">\n\t\t\t\t\t\t\t<button type="button" class="quantity-btn minus-icon" data-target="children-${t}" data-action="decrement">-</button>\n\t\t\t\t\t\t\t<input type="text" id="children-${t}" name="children-${t}
126" value="0" readonly>\n\t\t\t\t\t\t\t<button type="button" class="quantity-btn plus-icon" data-target="children-${t}" data-action="increment">+</button>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div id="children-ages-${t}" class="child-nr-box"></div>\n\t\t\t`
127		}(t), o.appendChild(e), y(), s()
128	})), document.addEventListener("click", (function(t) {
129		const e = t.target;
130		e.classList.contains("quantity-btn") ? function(t) {
131			const e = t.getAttribute("data-target"),
132				n = t.getAttribute("data-action"),
133				[o, l] = e.split("-"),
134				r = document.getElementById(`adults-${l}`),
135				i = document.getElementById(`children-${l}`);
136			if (!r || !i) return;
137			let c = parseInt(r.value, 10),
138				d = parseInt(i.value, 10);
139			const u = c + d,
140				y = 4;
141			"increment" === n ? u < y ? e.startsWith("adults") ? r.value = c + 1 : e.startsWith("children") && (i.value = d + 1, m(e)) : a(`Maximum ${y} guests per room.`) : "decrement" === n && (e.startsWith("adults") && c > 1 ? r.value = c - 1 : e.startsWith("children") && d > 0 && (i.value = d - 1, m(e))), s()
142		}(e) : e.classList.contains("remove-room") && function(t) {
143			const e = document.querySelector(`.room[data-room="${t}"]`);
144			e && (e.remove(), document.querySelectorAll(".room").forEach(((t, e) => {
145				const n = e + 1;
146				t.setAttribute("data-room", n);
147				const o = t.querySelector(".room-nr-title");
148				o && (o.innerHTML = `Room ${n} ${n>1?`<button type="button" class="remove-room" data-room="${n}">Remove Room</button>`:""}`);
149				const l = t.querySelector('label[for^="adults"]');
150				l && l.setAttribute("for", `adults-${n}`);
151				const r = t.querySelector('label[for^="children"]');
152				r && r.setAttribute("for", `children-${n}`);
153				const i = t.querySelector('input[id^="adults"]');
154				i && (i.setAttribute("id", `adults-${n}`), i.setAttribute("name", `adults-${n}`));
155				const c = t.querySelector('input[id^="children"]');
156				c && (c.setAttribute("id", `children-${n}`), c.setAttribute("name", `children-${n}`));
157				const a = t.querySelector('div[id^="children-ages"]');
158				a && a.setAttribute("id", `children-ages-${n}`)
159			})), y(), s())
160		}(e.getAttribute("data-room"))
161	})), window.toggleBookingFormVisibility = h, document.querySelectorAll("#fixed-book-now .book-now-primary, .offer-content .btn-primary, .offer-text-overlay .btn-primary, .offer-details .btn-primary").forEach((function(t) {
162		t.addEventListener("click", (function() {
163			h(!0), l && l.classList.add("nofocus"), i && (i.style.display = "none")
164		}))
165	}));
166	const v = document.getElementById("close-booking-form");
167	v && v.addEventListener("click", (function() {
168		h(!1), l && l.classList.remove("nofocus")
169	}))
170}));

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.