PageSourceSearch

https://olimpijski.pl/wp-content/plugins/booking/js/wpbc_time-selector.js?ver=11.6.1

js olimpijski.pl collected 2026-09-24 19:43:11 UTC 5,294 bytes, 177 lines download raw bytes

1// FixIn: 8.7.11.10.
2(function ( $ ){
3
4	$.fn.extend( {
5
6		wpbc_timeselector: function (){
7
8			var times_options = [];
9
10			this.each( function (){
11
12				var el = $( this );
13
14				// On new days click we are searching for old time items,  and remove them from this booking form
15				if ( el.parent().find( '.wpbc_times_selector' ).length ) {
16					el.parent().find( '.wpbc_times_selector' ).remove();
17				}
18
19				el.find( 'option' ).each( function ( ind ){
20
21					times_options.push( {
22										  title   : jQuery( this ).text()
23										, value   : jQuery( this ).val()
24										, disabled: jQuery( this ).is( ':disabled' )
25										, selected: jQuery( this ).is( ':selected' )
26										} );
27
28				} );
29
30				var times_options_html = $.fn.wpbc_timeselector.format( times_options );
31
32				el.after( times_options_html );
33
34				el.next('.wpbc_times_selector').find('div').not('.wpbc_time_picker_disabled').on( "click", function() {
35
36					// Get data value of clicked DIV time-slot
37					var selected_value = jQuery( this ).attr( 'data-value' );
38
39					// Remove previos selected class
40					jQuery( this ).parent( '.wpbc_times_selector' ).find( '.wpbc_time_selected' ).removeClass( 'wpbc_time_selected' );
41					// Set  time item with  selected Class
42					jQuery( this ).addClass('wpbc_time_selected');
43
44					el.find( 'option' ).prop( 'selected', false );
45					// Find option in selectbox with this value
46					el.find( 'option[value="' + selected_value + '"]' ).prop( 'selected', true );
47
48					el.trigger( 'change' );
49				});
50
51				// Execute a function when the user presses a key (13 - Enter) on the keyboard. (FixIn: EAA)
52				el.next( '.wpbc_times_selector' ).find( 'div' ).not( '.wpbc_time_picker_disabled' ).on( "keypress", function (event) {
53					if ( 13 === event.which ) {
54						event.preventDefault();
55						console.log( jQuery( this ) );
56						jQuery( this ).trigger( 'click' );
57					}
58				} );
59
60				el.hide();
61
62				times_options = [];
63			} );
64
65			return this;				// Chain
66		}
67	} );
68
69
70	// Get HTML structure of times selection
71	$.fn.wpbc_timeselector.format = function ( el_arr ) {
72
73		var select_div = '';
74		var css_class='';
75
76		$.each( el_arr, function (index, el_item){
77
78			if ( !el_item.disabled ){
79
80				if (el_item.selected){
81					css_class = 'wpbc_time_selected';
82				} else {
83					css_class = '';
84				}
85
86				select_div += '<div '
87									+ ' data-value="' + el_item.value + '" '
88									+ ' class="' + css_class + '" '
89									+ ' tabindex="0" '
90					         + '>'
91									+ el_item.title
92							 + '</div>'
93			} else {
94				// Uncomment row bellow to Show booked time slots as unavailable RED slots		// FixIn: 9.9.0.2.
95				// select_div += '<div class="wpbc_time_picker_disabled">' + el_item.title + '</div>';
96			}
97
98		} );
99
100		if ( '' == select_div ){
101			select_div = '<span class="wpbc_no_time_pickers">'
102							+ 'No available times'
103					   + '</span>'
104		}
105		return '<div class="wpbc_times_selector">' + select_div + '</div>';
106	}
107
108
109})( jQuery );
110
111
112/**
113 * Initialize the visual time-slot selectors when the WPBC runtime is ready.
114 *
115 * The readiness check prevents a JavaScript error when a third-party optimizer
116 * delays wpbc_all.js, which creates window._wpbc, beyond document ready.
117 *
118 * @return {boolean} True when initialization is complete or not required;
119 *                   otherwise false when the WPBC runtime is not ready yet.
120 */
121function wpbc_hook__init_timeselector(){
122
123	if (
124		( 'object' !== typeof window._wpbc )
125		|| ( 'function' !== typeof window._wpbc.get_other_param )
126	) {
127		return false;
128	}
129
130	if ( true !== window._wpbc.get_other_param( 'is_enabled_booking_timeslot_picker' ) ) {
131		return true;
132	}
133
134	// Load after page loaded
135	jQuery( 'select[name^="rangetime"]' ).wpbc_timeselector();
136	jQuery( 'select[name^="starttime"]' ).wpbc_timeselector();
137	jQuery( 'select[name^="endtime"]' ).wpbc_timeselector();
138	jQuery( 'select[name^="durationtime"]' ).wpbc_timeselector();
139
140	// This hook loading after each day selection																// FixIn: 8.7.11.9.
141	jQuery( ".booking_form_div" ).on( 'wpbc_hook_timeslots_disabled', function ( event, bk_type, all_dates ){
142		jQuery( '#booking_form_div' + bk_type + ' select[name^="rangetime"]' ).wpbc_timeselector();
143		jQuery( '#booking_form_div' + bk_type + ' select[name^="starttime"]' ).wpbc_timeselector();
144		jQuery( '#booking_form_div' + bk_type + ' select[name^="endtime"]' ).wpbc_timeselector();
145		jQuery( '#booking_form_div' + bk_type + ' select[name^="durationtime"]' ).wpbc_timeselector();
146	} );
147
148	return true;
149}
150
151
152/**
153 * Initialize the time selector now or after the WPBC core signals readiness.
154 *
155 * @return {void}
156 */
157function wpbc_init_timeselector_when_wpbc_ready(){
158
159	if ( wpbc_hook__init_timeselector() ) {
160		return;
161	}
162
163	var wpbc_timeselector_ready_handler = function (){
164		if ( wpbc_hook__init_timeselector() ) {
165			document.removeEventListener( 'wpbc-ready', wpbc_timeselector_ready_handler );
166		}
167	};
168
169	document.addEventListener( 'wpbc-ready', wpbc_timeselector_ready_handler );
170}
171
172
173jQuery(document).ready(function(){
174//	 setTimeout( function ( ) {					// Need to  have some delay  for loading of all  times in Garbage
175	wpbc_init_timeselector_when_wpbc_ready();
176//	}, 1000 );
177});

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.