PluginProbe
Booking Calendar / 11.8.3
Booking Calendar v11.8.3
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
← All changes | js/wpbc_time-selector.js +54 -17 11.311.8.3 View file →
@@ -1,4 +1,4 @@
1 1 // FixIn: 8.7.11.10.
2 2 (function ( $ ){
3 3
4 4 $.fn.extend( {
@@ -108,17 +108,30 @@
108 108
109 109 })( jQuery );
110 110
111 111
112 -/**
113 - * Init time selector
114 - */
115 -function wpbc_hook__init_timeselector(){
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 + */
121 +function 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 + }
116 133
117 - if ( true !== _wpbc.get_other_param( 'is_enabled_booking_timeslot_picker' ) ) {
118 - return false;
119 - }
120 -
121 134 // Load after page loaded
122 135 jQuery( 'select[name^="rangetime"]' ).wpbc_timeselector();
123 136 jQuery( 'select[name^="starttime"]' ).wpbc_timeselector();
124 137 jQuery( 'select[name^="endtime"]' ).wpbc_timeselector();
@@ -128,13 +141,37 @@
128 141 jQuery( ".booking_form_div" ).on( 'wpbc_hook_timeslots_disabled', function ( event, bk_type, all_dates ){
129 142 jQuery( '#booking_form_div' + bk_type + ' select[name^="rangetime"]' ).wpbc_timeselector();
130 143 jQuery( '#booking_form_div' + bk_type + ' select[name^="starttime"]' ).wpbc_timeselector();
131 144 jQuery( '#booking_form_div' + bk_type + ' select[name^="endtime"]' ).wpbc_timeselector();
132 - jQuery( '#booking_form_div' + bk_type + ' select[name^="durationtime"]' ).wpbc_timeselector();
133 - } );
134 -}
135 -
136 -jQuery(document).ready(function(){
137 -// setTimeout( function ( ) { // Need to have some delay for loading of all times in Garbage
138 - wpbc_hook__init_timeselector();
139 -// }, 1000 );
140 -});
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 + */
157 +function 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 +
173 +jQuery(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 +});