PluginProbe
Booking Calendar / 11.6.1
Booking Calendar v11.6.1
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
booking / includes / __js / admin / settings / ui_sidebar_left__actions.js

ui_sidebar_left__actions.js in Booking Calendar 11.6.1, at includes/__js/admin/settings/ui_sidebar_left__actions.js

398 lines 15.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2 // =====================================================================================================================
3 // == Left Bar - expand / colapse functions ==
4 // =====================================================================================================================
5
6 /**
7 * Save user's preferred left sidebar mode.
8 *
9 * @param string mode
10 */
11 function wpbc_admin_ui__sidebar_left__save_mode( mode ) {
12 var allowed_modes = [ 'min', 'compact', 'max' ];
13
14 if ( allowed_modes.indexOf( mode ) === -1 ) {
15 return;
16 }
17
18 var $saver = jQuery( '#wpbc_left_sidebar_view_mode_saver' );
19
20 if ( ! $saver.length ) {
21 return;
22 }
23
24 if ( 'function' !== typeof wpbc_save_custom_user_data_from_element ) {
25 return;
26 }
27
28 $saver.data( 'wpbc-u-save-value', mode );
29 $saver.attr( 'data-wpbc-u-save-value', mode );
30
31 wpbc_save_custom_user_data_from_element( $saver.get( 0 ) );
32 }
33
34 /**
35 * Expand Vertical Left Bar.
36 *
37 * @param bool is_save_user_state Save this mode as user's preference.
38 */
39 function wpbc_admin_ui__sidebar_left__do_max( is_save_user_state ) {
40 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' );
41 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'max' );
42 jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).addClass( 'wpbc_ui__hide' );
43 jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
44
45 jQuery( '.wp-admin' ).removeClass( 'wpbc_page_wrapper_left_min wpbc_page_wrapper_left_max wpbc_page_wrapper_left_compact wpbc_page_wrapper_left_none' );
46 jQuery( '.wp-admin' ).addClass( 'wpbc_page_wrapper_left_max' );
47
48 if ( is_save_user_state ) {
49 wpbc_admin_ui__sidebar_left__save_mode( 'max' );
50 }
51 }
52
53 /**
54 * Hide Vertical Left Bar.
55 *
56 * @param bool is_save_user_state Save this mode as user's preference.
57 */
58 function wpbc_admin_ui__sidebar_left__do_min( is_save_user_state ) {
59 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' );
60 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'min' );
61 jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
62 jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' );
63
64 jQuery( '.wp-admin' ).removeClass( 'wpbc_page_wrapper_left_min wpbc_page_wrapper_left_max wpbc_page_wrapper_left_compact wpbc_page_wrapper_left_none' );
65 jQuery( '.wp-admin' ).addClass( 'wpbc_page_wrapper_left_min' );
66
67 if ( is_save_user_state ) {
68 wpbc_admin_ui__sidebar_left__save_mode( 'min' );
69 }
70 }
71
72 /**
73 * Colapse Vertical Left Bar.
74 *
75 * @param bool is_save_user_state Save this mode as user's preference.
76 */
77 function wpbc_admin_ui__sidebar_left__do_compact( is_save_user_state ) {
78 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' );
79 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'compact' );
80 jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
81 jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' );
82
83 jQuery( '.wp-admin' ).removeClass( 'wpbc_page_wrapper_left_min wpbc_page_wrapper_left_max wpbc_page_wrapper_left_compact wpbc_page_wrapper_left_none' );
84 jQuery( '.wp-admin' ).addClass( 'wpbc_page_wrapper_left_compact' );
85
86 if ( is_save_user_state ) {
87 wpbc_admin_ui__sidebar_left__save_mode( 'compact' );
88 }
89 }
90
91 /**
92 * Completely Hide Vertical Left Bar.
93 */
94 function wpbc_admin_ui__sidebar_left__do_hide() {
95 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' );
96 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'none' );
97 jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
98 jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' );
99 // Hide top "Menu" button with divider.
100 jQuery( '.wpbc_ui__top_nav__btn_show_left_vertical_nav,.wpbc_ui__top_nav__btn_show_left_vertical_nav_divider' ).addClass( 'wpbc_ui__hide' );
101
102 jQuery( '.wp-admin' ).removeClass( 'wpbc_page_wrapper_left_min wpbc_page_wrapper_left_max wpbc_page_wrapper_left_compact wpbc_page_wrapper_left_none' );
103 jQuery( '.wp-admin' ).addClass( 'wpbc_page_wrapper_left_none' );
104 }
105
106 /**
107 * Action on click "Go Back" - show root menu
108 * or some other section in left sidebar.
109 *
110 * @param string menu_to_show - menu slug.
111 */
112 function wpbc_admin_ui__sidebar_left__show_section( menu_to_show ) {
113 jQuery( '.wpbc_ui_el__vert_left_bar__section' ).addClass( 'wpbc_ui__hide' )
114 jQuery( '.wpbc_ui_el__vert_left_bar__section_' + menu_to_show ).removeClass( 'wpbc_ui__hide' );
115 }
116
117 // =====================================================================================================================
118 // == Right Side Bar - expand / colapse functions ==
119 // =====================================================================================================================
120
121 /**
122 * Expand Vertical Right Bar.
123 */
124 function wpbc_admin_ui__sidebar_right__do_max() {
125 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min_right max_right compact_right none_right' );
126 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'max_right' );
127 jQuery( '.wpbc_ui__top_nav__btn_open_right_vertical_nav' ).addClass( 'wpbc_ui__hide' );
128 jQuery( '.wpbc_ui__top_nav__btn_hide_right_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
129 }
130
131 /**
132 * Hide Vertical Right Bar.
133 */
134 function wpbc_admin_ui__sidebar_right__do_min() {
135 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min_right max_right compact_right none_right' );
136 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'min_right' );
137 jQuery( '.wpbc_ui__top_nav__btn_open_right_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
138 jQuery( '.wpbc_ui__top_nav__btn_hide_right_vertical_nav' ).addClass( 'wpbc_ui__hide' );
139 }
140
141 /**
142 * Colapse Vertical Right Bar.
143 */
144 function wpbc_admin_ui__sidebar_right__do_compact() {
145 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min_right max_right compact_right none_right' );
146 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'compact_right' );
147 jQuery( '.wpbc_ui__top_nav__btn_open_right_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
148 jQuery( '.wpbc_ui__top_nav__btn_hide_right_vertical_nav' ).addClass( 'wpbc_ui__hide' );
149 }
150
151 /**
152 * Completely Hide Vertical Right Bar.
153 */
154 function wpbc_admin_ui__sidebar_right__do_hide() {
155 jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min_right max_right compact_right none_right' );
156 jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'none_right' );
157 jQuery( '.wpbc_ui__top_nav__btn_open_right_vertical_nav' ).removeClass( 'wpbc_ui__hide' );
158 jQuery( '.wpbc_ui__top_nav__btn_hide_right_vertical_nav' ).addClass( 'wpbc_ui__hide' );
159 // Hide top "Menu" button with divider.
160 jQuery( '.wpbc_ui__top_nav__btn_show_right_vertical_nav,.wpbc_ui__top_nav__btn_show_right_vertical_nav_divider' ).addClass( 'wpbc_ui__hide' );
161 }
162
163 /**
164 * Collapse an expanded right sidebar after an opted-in page-content click.
165 *
166 * Pages enable this behavior through the page-structure
167 * right_vertical_sidebar__content_click_collapse_mode option. Interactive
168 * controls that open or retain sidebar content can opt out by placing the
169 * data-wpbc-right-sidebar-keep-open attribute on themselves or an ancestor.
170 *
171 * @param {jQuery.Event} event Content click event.
172 * @return {void}
173 */
174 function wpbc_admin_ui__sidebar_right__collapse_from_content_click( event ) {
175 var $content = jQuery( event.currentTarget );
176 var $wrapper = $content.closest( '.wpbc_settings_page_wrapper' );
177 var collapse_mode = String( $wrapper.attr( 'data-wpbc-right-sidebar-content-click-collapse-mode' ) || '' );
178 var before_collapse_event;
179
180 if ( ! $wrapper.hasClass( 'max_right' ) || [ 'min', 'compact', 'none' ].indexOf( collapse_mode ) === -1 ) {
181 return;
182 }
183 if ( jQuery( event.target ).closest( '[data-wpbc-right-sidebar-keep-open]' ).length ) {
184 return;
185 }
186
187 before_collapse_event = jQuery.Event( 'wpbc:right-sidebar-before-content-collapse' );
188 $wrapper.trigger( before_collapse_event, [ event ] );
189 if ( before_collapse_event.isDefaultPrevented() ) {
190 return;
191 }
192
193 if ( 'compact' === collapse_mode ) {
194 wpbc_admin_ui__sidebar_right__do_compact();
195 } else if ( 'none' === collapse_mode ) {
196 wpbc_admin_ui__sidebar_right__do_hide();
197 } else {
198 wpbc_admin_ui__sidebar_right__do_min();
199 }
200
201 jQuery( document ).trigger( 'wpbc_setup_wizard_layout_changed' );
202 }
203
204 jQuery( document ).on(
205 'click',
206 '.wpbc_settings_page_wrapper[data-wpbc-right-sidebar-content-click-collapse-mode] > .wpbc_settings_page_content',
207 wpbc_admin_ui__sidebar_right__collapse_from_content_click
208 );
209
210
211 /**
212 * Action on click "Go Back" - show root menu
213 * or some other section in right sidebar.
214 *
215 * @param string menu_to_show - menu slug.
216 */
217 function wpbc_admin_ui__sidebar_right__show_section( menu_to_show ) {
218 jQuery( '.wpbc_ui_el__vert_right_bar__section' ).addClass( 'wpbc_ui__hide' )
219 jQuery( '.wpbc_ui_el__vert_right_bar__section_' + menu_to_show ).removeClass( 'wpbc_ui__hide' );
220 }
221
222 // =====================================================================================================================
223 // == End Right Side Bar section ==
224 // =====================================================================================================================
225
226 /**
227 * Get anchor(s) array from URL.
228 * Doc: https://developer.mozilla.org/en-US/docs/Web/API/Location
229 *
230 * @returns {*[]}
231 */
232 function wpbc_url_get_anchors_arr() {
233 var hashes = window.location.hash.replace( '%23', '#' );
234 var hashes_arr = hashes.split( '#' );
235 var result = [];
236 var hashes_arr_length = hashes_arr.length;
237
238 for ( var i = 0; i < hashes_arr_length; i++ ) {
239 if ( hashes_arr[i].length > 0 ) {
240 result.push( hashes_arr[i] );
241 }
242 }
243 return result;
244 }
245
246 /**
247 * Auto Expand Settings section based on URL anchor, after page loaded.
248 */
249 jQuery( document ).ready( function () { wpbc_admin_ui__redirect_legacy_general_availability_url(); } );
250 jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 10 ); } );
251 jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 150 ); } );
252
253 /**
254 * Redirect old Settings > Availability anchors to the dedicated General Availability page.
255 */
256 function wpbc_admin_ui__redirect_legacy_general_availability_url() {
257
258 if (
259 ( window.location.href.indexOf( 'page=wpbc-settings' ) > -1 )
260 && (
261 ( window.location.hash.indexOf( 'wpbc_general_settings_availability_metabox' ) > -1 )
262 || ( window.location.hash.indexOf( 'wpbc_general_settings_availability_tab' ) > -1 )
263 )
264 ) {
265 window.location.replace( window.location.href.split( '?' )[0] + '?page=wpbc-availability&tab=general_availability' );
266 }
267 }
268
269 /**
270 * Expand section in General Settings page and select Menu item.
271 */
272 function wpbc_admin_ui__do_expand_section() {
273
274 // window.location.hash = #section_id / doc: https://developer.mozilla.org/en-US/docs/Web/API/Location .
275 var anchors_arr = wpbc_url_get_anchors_arr();
276 var anchors_arr_length = anchors_arr.length;
277
278 if ( anchors_arr_length > 0 ) {
279 var one_anchor_prop_value = anchors_arr[0].split( 'do_expand__' );
280 if ( one_anchor_prop_value.length > 1 ) {
281
282 // 'wpbc_general_settings_calendar_metabox'
283 var section_to_show = one_anchor_prop_value[1];
284 var section_id_to_show = '#' + section_to_show;
285
286
287 // -- Remove selected background in all left menu items ---------------------------------------------------
288 jQuery( '.wpbc_ui_el__vert_nav_item ' ).removeClass( 'active' );
289 // Set left menu selected.
290 jQuery( '.do_expand__' + section_to_show + '_link' ).addClass( 'active' );
291 var selected_title = jQuery( '.do_expand__' + section_to_show + '_link a .wpbc_ui_el__vert_nav_title ' ).text();
292
293 // Expand section, if it colapsed.
294 if ( ! jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).hasClass( 'expanded' ) ) {
295 jQuery( '.wpbc_ui_el__level__folder' ).removeClass( 'expanded' );
296 jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).addClass( 'expanded' );
297 }
298
299 // -- Expand section ---------------------------------------------------------------------------------------
300 var container_to_hide_class = '.postbox';
301 // Hide sections '.postbox' in admin page and show specific one.
302 jQuery( '.wpbc_admin_page ' + container_to_hide_class ).hide();
303 jQuery( '.wpbc_container_always_hide__on_left_nav_click' ).hide();
304 jQuery( section_id_to_show ).show();
305
306 // Show all other sections, if provided in URL: ..?page=wpbc-settings#do_expand__wpbc_general_settings_capacity_metabox#wpbc_general_settings_capacity_upgrade_metabox .
307 for ( let i = 1; i < anchors_arr_length; i++ ) {
308 jQuery( '#' + anchors_arr[i] ).show();
309 }
310
311 if ( false ) {
312 var targetOffset = wpbc_scroll_to( section_id_to_show );
313 }
314
315 // -- Set Value to Input about selected Nav element --------------------------------------------------------------- // FixIn: 9.8.6.1.
316 var section_id_tab = section_id_to_show.substring( 0, section_id_to_show.length - 8 ) + '_tab';
317 if ( container_to_hide_class == section_id_to_show ) {
318 section_id_tab = '#wpbc_general_settings_all_tab'
319 }
320 if ( '#wpbc_general_settings_capacity_metabox,#wpbc_general_settings_capacity_upgrade_metabox' == section_id_to_show ) {
321 section_id_tab = '#wpbc_general_settings_capacity_tab'
322 }
323 jQuery( '#form_visible_section' ).val( section_id_tab );
324 }
325
326 // Like blinking some elements.
327 wpbc_admin_ui__do__anchor__another_actions();
328 }
329 }
330
331 function wpbc_admin_ui__is_in_mobile_screen_size() {
332 return wpbc_admin_ui__is_in_this_screen_size( 605 );
333 }
334
335 function wpbc_admin_ui__is_in_this_screen_size(size) {
336 return (window.screen.width <= size);
337 }
338
339 /**
340 * Open settings page | Expand section | Select Menu item.
341 */
342 function wpbc_admin_ui__do__open_url__expand_section(url, section_id) {
343
344 // window.location.href = url + '&do_expand=' + section_id + '#do_expand__' + section_id; //.
345 window.location.href = url + '#do_expand__' + section_id;
346
347 if ( wpbc_admin_ui__is_in_mobile_screen_size() ) {
348 wpbc_admin_ui__sidebar_left__do_min();
349 }
350
351 wpbc_admin_ui__do_expand_section();
352 }
353
354
355 /**
356 * Check for Other actions: Like blinking some elements in settings page. E.g. Days selection or change-over days.
357 */
358 function wpbc_admin_ui__do__anchor__another_actions() {
359
360 var anchors_arr = wpbc_url_get_anchors_arr();
361 var anchors_arr_length = anchors_arr.length;
362
363 // Other actions: Like blinking some elements.
364 for ( var i = 0; i < anchors_arr_length; i++ ) {
365
366 var this_anchor = anchors_arr[i];
367
368 var this_anchor_prop_value = this_anchor.split( 'do_other_actions__' );
369
370 if ( this_anchor_prop_value.length > 1 ) {
371
372 var section_action = this_anchor_prop_value[1];
373
374 switch ( section_action ) {
375
376 case 'blink_day_selections':
377 // wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Days Selection' );.
378 wpbc_blink_element( '.wpbc_tr_set_gen_booking_type_of_day_selections', 4, 350 );
379 wpbc_scroll_to( '.wpbc_tr_set_gen_booking_type_of_day_selections' );
380 break;
381
382 case 'blink_change_over_days':
383 // wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Changeover Days' );.
384 wpbc_blink_element( '.wpbc_tr_set_gen_booking_range_selection_time_is_active', 4, 350 );
385 wpbc_scroll_to( '.wpbc_tr_set_gen_booking_range_selection_time_is_active' );
386 break;
387
388 case 'blink_captcha':
389 wpbc_blink_element( '.wpbc_tr_set_gen_booking_is_use_captcha', 4, 350 );
390 wpbc_scroll_to( '.wpbc_tr_set_gen_booking_is_use_captcha' );
391 break;
392
393 default:
394 }
395 }
396 }
397 }
398