PageSourceSearch

https://culinaryvietnam.com/wp-content/plugins/travel-booking/assets/js/frontend/booking.js?ver=1.1.6

js culinaryvietnam.com collected 2026-10-03 00:29:13 UTC 13,112 bytes, 410 lines download raw bytes

1/**
2 * Booking tour js
3 *
4 * @author physcode
5 * @version 1.1.6
6 */
7
8;(function ($) {
9	'use strict';
10	var date_validate = [];
11	var date_can_book = [];
12	var date_arr = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
13	var tour_days = '';
14	var date_book = '';
15	var load_notify = false;
16
17	$.fn.tour_booking_init = function () {
18		$.fn.tour_booking();
19
20		$('input[name=number_ticket]').on('keyup mouseup', function () {
21			$.fn.update_tour_total_price($('input[name=date_book]').val());
22		});
23
24		$('input[name=number_children]').on('keyup mouseup', function () {
25			$.fn.update_tour_total_price($('input[name=date_book]').val());
26		});
27
28		if (getCookie('info_user')) {
29			var info_user = JSON.parse(getCookie('info_user'));
30			$('input[name=first_name]').val(info_user.first_name);
31			$('input[name=last_name]').val(info_user.last_name);
32			$('input[name=email_tour]').val(info_user.email);
33			$('input[name=phone]').val(info_user.phone);
34
35			// for billing
36			$('input[name=billing_first_name]').val(info_user.first_name);
37			$('input[name=billing_last_name]').val(info_user.last_name);
38			$('input[name=billing_email]').val(info_user.email);
39			$('input[name=billing_phone]').val(info_user.phone);
40		}
41	};
42
43	$.fn.tour_booking = function () {
44		// get list date available
45		var start_date_str = $('input[name=start_date]').val();
46		var end_date_str = $('input[name=end_date]').val();
47		var start_date = 0;
48		var end_date = 0;
49		if (start_date_str !== '' || end_date_str !== '') {
50			start_date = new Date(start_date_str);
51			end_date = new Date(end_date_str);
52		}
53
54		var tour_days_arr = [];
55		var date_now = new Date();
56
57		if ($('input[name=tour_days]').length && $('input[name=tour_days]').val() != '') {
58			tour_days = JSON.parse($('input[name=tour_days]').val());
59			$.each(tour_days, function (i) {
60				tour_days_arr.push(i);
61			});
62		}
63		// console.log(tour_days_arr);
64
65		if (start_date !== 0 && end_date !== 0) {
66			var date_next = start_date;
67			while (date_next.getTime() <= end_date.getTime()) {
68				var date_next_str = ('0' + (date_next.getMonth() + 1)).slice(-2) + '/' + ('0' + date_next.getDate()).slice(-2) + '/' + date_next.getFullYear();
69				// console.log(date_next_str);
70				if (date_next.getTime() > date_now.getTime() || date_next.getTime() == date_now.getTime()) {
71					if (tour_days_arr.length > 0) {
72						if (tour_days_arr.indexOf(date_arr[date_next.getDay()]) != -1) {
73							date_validate.push(date_next_str);
74						}
75					} else {
76						date_validate.push(date_next_str);
77					}
78				}
79				date_next.setDate(date_next.getDate() + 1);
80			}
81		}
82
83		$('input[name=date_book]').datepicker({
84			dateFormat   : 'mm/dd/yy',
85			minDate      : date_now,
86			beforeShowDay: date_available,
87			onClose      : function (selectedDate) {
88				if (selectedDate) {
89					date_book = selectedDate;
90					$.fn.update_tour_total_price(date_book);
91				} else {
92					date_book = '';
93				}
94			}
95		});
96	};
97
98	function date_available(date) {
99		var dmy = ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2) + "/" + date.getFullYear();
100		if (date_validate.length !== 0) {
101			// console.log(dmy + ' : ' + ($.inArray(dmy, date_validate)));
102			if ($.inArray(dmy, date_validate) != -1) {
103				return [true, "date-available", "Available"];
104			} else {
105				return [false, "", "unAvailable"];
106			}
107		} else {
108			return [true, "date-available", "Available"];
109		}
110	}
111
112	$.fn.update_tour_total_price = function (date_book) {
113		var price = $('input[name=price]');
114		var qty = $('input[name=number_ticket]');
115		var currency_symbol = $('input[name=currency_symbol]');
116		var show_qty = $('.qty');
117		var show_price = $('.price_tour');
118		var show_total_price = $('.total_price');
119		var total_price = 0;
120		var input_number_children = $('input[name=number_children]');
121		var input_price_child = $('input[name=price_child]');
122		var input_price_child_set_on_tour = $('input[name=price_child_set_on_tour]');
123		var input_price_children_percent = $('input[name=price_children_percent]');
124		var qty_children = $('.qty_children');
125
126		$('.total_price_arrow').find('span.qty').text(qty.val());
127		if (typeof date_book != "undefined" && date_book != '') {
128			var date_book_split_str = date_book.split('/');
129			var date_book = new Date(date_book_split_str[2], date_book_split_str[0] - 1, date_book_split_str[1]);
130			var day_number = date_book.getDay();
131			var day_str = date_arr[day_number];
132			$('input[name=day_book]').val(day_str);
133
134			var price_day = 0;
135			var price_tmp = price.val();
136			var price_day_children = 0;
137			var price_tmp_day_children = 0;
138
139			if (typeof tour_days[day_str] != "undefined") {
140				if (typeof tour_days[day_str]['price'] != "undefined" && !isNaN(tour_days[day_str]['price'])) {
141					price_day = parseFloat(tour_days[day_str]['price']);
142				} else if (!isNaN(tour_days[day_str])) {
143					price_day = parseFloat(tour_days[day_str]);
144				}
145			}
146
147			if (price_day > 0) {
148				price_tmp = price_day;
149			}
150
151			if ($('.summary').find('ins').length > 0) {
152				$('.summary').find('ins').find('.amount').text(currency_symbol.val() + price_tmp);
153			} else {
154				$('.summary').find('.price').find('.amount').text(currency_symbol.val() + price_tmp);
155			}
156
157			if (input_number_children.length > 0) {
158				if (typeof tour_days[day_str] != "undefined" && !isNaN(tour_days[day_str]['price_children'])) {
159					price_day_children = parseFloat(tour_days[day_str]['price_children']);
160				}
161				// set price children by day
162				if (price_day_children > 0) {
163					price_tmp_day_children = price_day_children;
164				}
165
166				// set price children on Tour
167				if (price_tmp_day_children == 0) {
168					price_tmp_day_children = input_price_child_set_on_tour.val();
169					if (price_tmp_day_children == 0) {
170						price_tmp_day_children = price_tmp * input_price_children_percent.val() / 100;
171					}
172				}
173
174				var price_adults = parseFloat(qty.val() * price_tmp);
175				var price_child = parseFloat(price_tmp_day_children * input_number_children.val());
176				var total = price_child + price_adults;
177
178				$('.price_adults').text(price_tmp);
179				$('.price_children').text(price_tmp_day_children);
180				$('.total_price_adults').text(currency_symbol.val() + price_adults.toFixed(2));
181				$('.total_price_children').text(currency_symbol.val() + price_child.toFixed(2));
182				$('.total_price_adults_children').text(currency_symbol.val() + total.toFixed(2));
183			} else {
184				show_price.text(currency_symbol.val() + price_tmp);
185				show_total_price.text(currency_symbol.val() + (qty.val() * price_tmp).toFixed(2));
186			}
187		} else {
188			if (input_number_children.length > 0) {
189				var price_adults = parseFloat(qty.val() * price.val());
190				var price_child = parseFloat(input_price_child.val() * input_number_children.val());
191				var total = price_child + price_adults;
192
193				qty_children.text(input_number_children.val());
194				$('.total_price_adults').text(currency_symbol.val() + price_adults.toFixed(2));
195				$('.total_price_children').text(currency_symbol.val() + price_child.toFixed(2));
196				$('.total_price_adults_children').text(currency_symbol.val() + total.toFixed(2));
197			} else {
198				show_total_price.text(currency_symbol.val() + (qty.val() * price.val()).toFixed(2));
199			}
200		}
201	};
202
203	$.fn.tour_booking_submit = function () {
204		$('.btn-booking').on('click', function (e) {
205			e.preventDefault();
206			var input_first_name = $('input[name=first_name]');
207			var input_last_name = $('input[name=last_name]');
208			var input_email = $('input[name=email_tour]');
209			var input_phone = $('input[name=phone]');
210			var input_date_book = $('input[name=date_book]');
211			var input_qty = $('input[name=number_ticket]');
212			var qty_tour = parseInt(input_qty.val());
213			var input_number_children = $('input[name=number_children]');
214			var tb_phys_ajax_url = $('input[name=url_home]').val();
215			var tour_variation_enable = $('input[name=tour_variation_enable]').val();
216			var quantity_variations = $('input[name=quantity_variations]').val();
217
218			if (input_first_name.length > 0) {
219				if (input_first_name.val().length == 0) {
220					input_first_name.attr('placeholder', 'Enter first name.');
221					input_first_name.addClass('error');
222					return;
223				}
224			}
225
226			if (input_last_name.length > 0) {
227				if (input_last_name.val().length == 0) {
228					input_last_name.attr('placeholder', 'Enter last name.');
229					input_last_name.addClass('error');
230					return;
231				}
232			}
233
234			if (input_email.length > 0) {
235				if (!checkValidateEmail(input_email.val())) {
236					input_email.attr('placeholder', 'Email invalid.');
237					input_email.addClass('error');
238					input_email.val('');
239					return;
240				}
241			}
242
243			if (input_phone.length > 0) {
244				if (input_phone.val().length == 0) {
245					input_phone.attr('placeholder', 'Enter phone.');
246					input_phone.addClass('error');
247					return;
248				}
249			}
250
251			if (input_date_book.length > 0) {
252				if (input_date_book.val().length == 0) {
253					input_date_book.attr('placeholder', 'Enter date.');
254					input_date_book.addClass('error');
255					return;
256				}
257			}
258
259			if (isNaN(qty_tour) || qty_tour <= 0) {
260				input_qty.val(1);
261			}
262
263			if (input_number_children.length > 0) {
264				if (isNaN(input_number_children.val())) {
265					input_number_children.val(0);
266				}
267
268				if (parseInt(input_qty.val()) + parseInt(input_number_children.val()) > parseInt(input_qty.attr('max'))) {
269					$('.qty_error').remove();
270					input_number_children.after('<span class="qty_error error">Only ' + input_qty.attr('max') + ' tickets</span>');
271					return;
272				}
273			} else {
274				if (parseInt(input_qty.val()) > parseInt(input_qty.attr('max'))) {
275					$('.qty_error').remove();
276					input_qty.after('<span class="qty_error error">Only ' + input_qty.attr('max') + ' tickets</span>');
277					return;
278				}
279			}
280
281			function checkValidateEmail(email) {
282				var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
283				return regex.test(email);
284			}
285
286			// run ajax add to cart
287			$('.spinner').show();
288			if (!$(this).hasClass('disable')) {
289				var data = {
290					nonce       : $('input[name=nonce]').val(),
291					tour_id     : $('input[name=tour_id]').val(),
292					date_booking: input_date_book.val()
293				};
294
295				if (tour_variation_enable == 1) {
296					var data_variations_choose = {};
297					$('.tour-variations').find('.field_variation').each(function (i) {
298						var el_field_variation = $(this);
299						if (el_field_variation.is(':checked')) {
300							data_variations_choose[el_field_variation.attr('name')] = el_field_variation.val();
301						}
302					});
303
304					data.tour_variations = data_variations_choose;
305					data.quantity_variations = quantity_variations;
306				} else {
307					data.number_ticket = input_qty.val();
308				}
309
310				if (input_number_children.length > 0) {
311					if (isNaN(parseInt(input_number_children.val()))) {
312						data.number_children = 0;
313					} else {
314						data.number_children = input_number_children.val();
315					}
316				}
317
318				$.ajax({
319					url     : tb_phys_ajax_url + '?tb-ajax=add_tour_to_cart_phys',
320					type    : 'post',
321					data    : data,
322					dataType: 'json',
323					success : function (result) {
324						if (result.status == 'success') {
325							var user_info = {
326								first_name: input_first_name.val(),
327								last_name : input_last_name.val(),
328								email     : input_email.val(),
329								phone     : input_phone.val()
330							};
331
332							document.cookie = "info_user=" + JSON.stringify(user_info) + '; path=/';
333							window.location = $('input[name=checkout_url]').val();
334						} else {
335							alert('errors booking. Try again');
336						}
337					}
338				});
339				$(this).addClass('disable');
340			}
341		});
342	};
343
344	$.fn.tour_orderby = function () {
345		$('.tour-ordering').find('.orderby').on('change', function () {
346			$('.tour-ordering').submit();
347		});
348	};
349
350	$.fn.load_ajax_notify = function () {
351		load_notify = false;
352		var limit = $("input[name=notify_limit]").val();
353		var tb_phys_ajax_url = $('input[name=url_home]').val();
354
355		$.ajax({
356			url     : tb_phys_ajax_url + "?tb-ajax=notify_new_order",
357			type    : "post",
358			data    : "limit=" + limit,
359			dataType: "json",
360			success : function (result) {
361				if (result.status == "success") {
362					$(".list-order-tour").html(result.html);
363					load_notify = true;
364				}
365			}
366		});
367	};
368
369	$.fn.load_notify_products_of_order = function () {
370		var notify_available = $('input[name=notify_available]');
371		if (notify_available.length) {
372			load_notify = true;
373			var refresh = $("input[name=notify_refresh]").val();
374			if (refresh == "") {
375				refresh = 10000;
376			}
377
378			setInterval(function () {
379				if (load_notify) {
380					$.fn.load_ajax_notify();
381				}
382			}, refresh);
383		}
384	};
385
386	function getCookie(cname) {
387		var name = cname + "=";
388		var decodedCookie = decodeURIComponent(document.cookie);
389		var ca = decodedCookie.split(';');
390		for (var i = 0; i < ca.length; i++) {
391			var c = ca[i];
392			while (c.charAt(0) == ' ') {
393				c = c.substring(1);
394			}
395			if (c.indexOf(name) == 0) {
396				return c.substring(name.length, c.length);
397			}
398		}
399		return "";
400	}
401
402})(jQuery, 'tour-booking-phys');
403
404jQuery(function ($) {
405	'use strict';
406	$.fn.tour_booking_init();
407	$.fn.tour_booking_submit();
408	$.fn.tour_orderby();
409	$.fn.load_notify_products_of_order();
410});

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.