PageSourceSearch

https://studio.katieaustin.tv/wp-content/plugins/booked/includes/a…//js/frontend-functions.js?ver=7.0.5

js katieaustin.tv collected 2026-10-01 16:13:13 UTC 6,633 bytes, 250 lines download raw bytes

1;(function($, window, document, undefined) {
2	var $win = $(window);
3	var $doc = $(document);
4	var $field_container;
5
6	$doc.ready(function() {
7
8		$(document).on("booked-on-new-app", function(event) {
9			$field_container = $('.field.field-paid-service');
10			booked_wc_products_field($field_container);
11		});
12
13		booked_wc_btn_edit_appointment_shortcode();
14		booked_wc_btn_edit_appointment_popup_app();
15		booked_wc_btn_pay_appointment_shortcode();
16
17		$(document).on("booked-before-loading-calendar-booking-options", function(event) {
18			booked_wc_change_calendar_loading_paramenters();
19		});
20
21		$(document).on("booked-before-loading-booking-form", function(event) {
22			booked_wc_change_booking_form_paramenters();
23		});
24
25		$(document).on("booked-on-requested-appointment", function(event,redirectObj) {
26			redirectObj.redirect = booked_wc_redirect_to_checkout_if_product_option();
27		});
28
29	});
30
31	function booked_wc_products_field(field_container) {
32
33		var $dropdown = $('select', field_container);
34
35		if ( $dropdown.find( 'option' ).length < 3 ){
36			$dropdown.find( 'option:first-child' ).remove();
37			var calendar_id = parseInt( $dropdown.data('calendar-id') ),
38				product_id = $dropdown.val(),
39				field_name = $dropdown.attr('name'),
40				$variations_container = $dropdown.parent().find('.paid-variations');
41				booked_wc_load_variations(product_id, field_name, calendar_id, $variations_container);
42		}
43
44		$dropdown.on('change', function() {
45			var $this = $(this),
46				calendar_id = parseInt( $this.data('calendar-id') ),
47				product_id = $this.val(),
48				field_name = $this.attr('name'),
49				$variations_container = $this.parent().find('.paid-variations');
50
51			booked_wc_load_variations(product_id, field_name, calendar_id, $variations_container);
52		});
53	}
54
55	function booked_wc_load_variations( product_id, field_name, calendar_id, variations_container ) {
56
57		if ( !product_id ) {
58			variations_container.html('');
59			return;
60		};
61
62		var data = {
63			'action': booked_wc_variables.prefix + 'load_variations',
64			'product_id': parseInt(product_id),
65			'calendar_id': calendar_id,
66			'field_name': field_name
67		};
68
69		$.post(
70			booked_wc_variables.ajaxurl,
71			data,
72			function(response) {
73				variations_container.html(response);
74				resize_booked_modal();
75			}
76		);
77	}
78
79	function booked_wc_btn_edit_appointment_shortcode() {
80		$('.booked-profile-appt-list .appt-block .edit').on('click', function(event) {
81
82			event.preventDefault();
83
84			var $button = $(this),
85				appt_id = $button.attr('data-appt-id'),
86				calendar_link = $button.attr('data-app-calendar');
87
88			if (booked_wc_variables.i18n_confirm_appt_edit){
89				confirm_edit = confirm(booked_wc_variables.i18n_confirm_appt_edit);
90			} else {
91				confirm_edit = true;
92			}
93
94			if ( confirm_edit === true ) {
95				window.location.href = calendar_link;
96			}
97
98			return false;
99		});
100	}
101
102	function booked_wc_btn_pay_appointment_shortcode() {
103		$('.booked-profile-appt-list .appt-block .pay').on('click', function(event) {
104
105			event.preventDefault();
106
107			var $button = $(this),
108				appt_id = $button.attr('data-appt-id');
109
110			confirm_edit = confirm(booked_wc_variables.i18n_pay);
111			if ( confirm_edit===true ){
112
113				var data = {
114					'action': booked_wc_variables.prefix + 'add_to_cart',
115					'app_id': appt_id
116				};
117
118				jQuery.post(booked_wc_variables.ajaxurl, data, function(response) {
119					if ( response.status === 'success' ) {
120						window.location.href = booked_wc_variables.checkout_page;
121					} else {
122						alert( response.messages[0] );
123					};
124				}, 'json');
125			}
126
127			return false;
128		});
129	}
130
131	function booked_wc_change_calendar_loading_paramenters() {
132
133		if ( !booked_load_calendar_date_booking_options ) {
134			return;
135		};
136
137		var current_url = window.location.href,
138			url_parameters = current_url.replace(/^[^?]+\??/gi, ''),
139			url_parameters_parts = url_parameters ? url_parameters.split('&') : false;
140
141		if (url_parameters_parts && current_url.match('booked_wc_extension')) {
142
143			// populate additional loading parameters
144			for (var i = 0; i < url_parameters_parts.length; i++) {
145				var data = url_parameters_parts[i].split('='),
146					name = data[0].replace(/_\d+$/, ''),
147					value = data[1];
148
149				booked_load_calendar_date_booking_options[name] = value;
150			}
151		};
152
153	}
154
155	function booked_wc_change_booking_form_paramenters() {
156		if ( !booked_appt_form_options ) {
157			return;
158		};
159
160		var current_url = window.location.href,
161			url_parameters = current_url.replace(/^[^?]+\??/gi, ''),
162			url_parameters_parts = url_parameters ? url_parameters.split('&') : false;
163
164		if (url_parameters_parts && current_url.match('booked_wc_extension')) {
165
166			// populate additional loading parameters
167			for (var i = 0; i < url_parameters_parts.length; i++) {
168				var data = url_parameters_parts[i].split('='),
169					name = data[0].replace(/_\d+$/, ''),
170					value = data[1];
171
172				booked_appt_form_options[name] = value;
173			}
174		};
175
176	}
177
178	function booked_wc_redirect_to_checkout_if_product_option() {
179
180		var redirect = false,
181			$form = $('form#newAppointmentForm');
182
183		$('.field-paid-service', $form).each(function() {
184			var $this = $(this);
185
186			$('select', $this).each(function() {
187				var $this_select = $(this);
188
189				if ( $this_select.val()!=='' ) {
190					redirect = true;
191				};
192			});
193		});
194
195		if ( redirect ) {
196			window.location = booked_wc_variables.checkout_page;
197			return true;
198		}
199
200		return false;
201
202	}
203
204	function booked_wc_btn_edit_appointment_popup_app() {
205
206		$doc.on('click', '.booked-form input#submit-edit-request-appointment', function(e){
207
208			var $thisButton = $(this);
209
210			$('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-circle-notch fa-spin"></i>&nbsp;&nbsp;&nbsp;' + booked_js_vars.i18n_please_wait);
211	        resize_booked_modal();
212
213			e.preventDefault();
214
215			$.ajax({
216				type	: 'post',
217				url 	: booked_js_vars.ajax_url,
218				data	: $('#newAppointmentForm').serialize(),
219				success	: function(data) {
220
221					data = data.split('###');
222					var data_result = data[0].substr(data[0].length - 5);
223
224					if (data_result == 'error'){
225
226						$thisButton.attr('disabled',false);
227						$thisButton.parents('form').find('button.cancel').show();
228
229						$('.booked-form input').each(function(){
230							thisDefault = $(this).attr('title');
231							thisVal = $(this).val();
232							if (!thisVal){ $(this).val(thisDefault); }
233						});
234
235						$('form#newAppointmentForm p.status').show().html('<i class="fa-solid fa-triangle-exclamation" style="color:#E35656"></i>&nbsp;&nbsp;&nbsp;' + data[1]);
236						resize_booked_modal();
237
238					} else {
239
240						window.location = booked_js_vars.profilePage
241
242					}
243
244				}
245			});
246		});
247
248	}
249
250})(jQuery, window, document);

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.