| 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 |
* Action on click "Go Back" - show root menu |
| 165 |
* or some other section in right sidebar. |
| 166 |
* |
| 167 |
* @param string menu_to_show - menu slug. |
| 168 |
*/ |
| 169 |
function wpbc_admin_ui__sidebar_right__show_section( menu_to_show ) { |
| 170 |
jQuery( '.wpbc_ui_el__vert_right_bar__section' ).addClass( 'wpbc_ui__hide' ) |
| 171 |
jQuery( '.wpbc_ui_el__vert_right_bar__section_' + menu_to_show ).removeClass( 'wpbc_ui__hide' ); |
| 172 |
} |
| 173 |
|
| 174 |
// ===================================================================================================================== |
| 175 |
// == End Right Side Bar section == |
| 176 |
// ===================================================================================================================== |
| 177 |
|
| 178 |
/** |
| 179 |
* Get anchor(s) array from URL. |
| 180 |
* Doc: https://developer.mozilla.org/en-US/docs/Web/API/Location |
| 181 |
* |
| 182 |
* @returns {*[]} |
| 183 |
*/ |
| 184 |
function wpbc_url_get_anchors_arr() { |
| 185 |
var hashes = window.location.hash.replace( '%23', '#' ); |
| 186 |
var hashes_arr = hashes.split( '#' ); |
| 187 |
var result = []; |
| 188 |
var hashes_arr_length = hashes_arr.length; |
| 189 |
|
| 190 |
for ( var i = 0; i < hashes_arr_length; i++ ) { |
| 191 |
if ( hashes_arr[i].length > 0 ) { |
| 192 |
result.push( hashes_arr[i] ); |
| 193 |
} |
| 194 |
} |
| 195 |
return result; |
| 196 |
} |
| 197 |
|
| 198 |
/** |
| 199 |
* Auto Expand Settings section based on URL anchor, after page loaded. |
| 200 |
*/ |
| 201 |
jQuery( document ).ready( function () { wpbc_admin_ui__redirect_legacy_general_availability_url(); } ); |
| 202 |
jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 10 ); } ); |
| 203 |
jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 150 ); } ); |
| 204 |
|
| 205 |
/** |
| 206 |
* Redirect old Settings > Availability anchors to the dedicated General Availability page. |
| 207 |
*/ |
| 208 |
function wpbc_admin_ui__redirect_legacy_general_availability_url() { |
| 209 |
|
| 210 |
if ( |
| 211 |
( window.location.href.indexOf( 'page=wpbc-settings' ) > -1 ) |
| 212 |
&& ( |
| 213 |
( window.location.hash.indexOf( 'wpbc_general_settings_availability_metabox' ) > -1 ) |
| 214 |
|| ( window.location.hash.indexOf( 'wpbc_general_settings_availability_tab' ) > -1 ) |
| 215 |
) |
| 216 |
) { |
| 217 |
window.location.replace( window.location.href.split( '?' )[0] + '?page=wpbc-availability&tab=general_availability' ); |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Expand section in General Settings page and select Menu item. |
| 223 |
*/ |
| 224 |
function wpbc_admin_ui__do_expand_section() { |
| 225 |
|
| 226 |
// window.location.hash = #section_id / doc: https://developer.mozilla.org/en-US/docs/Web/API/Location . |
| 227 |
var anchors_arr = wpbc_url_get_anchors_arr(); |
| 228 |
var anchors_arr_length = anchors_arr.length; |
| 229 |
|
| 230 |
if ( anchors_arr_length > 0 ) { |
| 231 |
var one_anchor_prop_value = anchors_arr[0].split( 'do_expand__' ); |
| 232 |
if ( one_anchor_prop_value.length > 1 ) { |
| 233 |
|
| 234 |
// 'wpbc_general_settings_calendar_metabox' |
| 235 |
var section_to_show = one_anchor_prop_value[1]; |
| 236 |
var section_id_to_show = '#' + section_to_show; |
| 237 |
|
| 238 |
|
| 239 |
// -- Remove selected background in all left menu items --------------------------------------------------- |
| 240 |
jQuery( '.wpbc_ui_el__vert_nav_item ' ).removeClass( 'active' ); |
| 241 |
// Set left menu selected. |
| 242 |
jQuery( '.do_expand__' + section_to_show + '_link' ).addClass( 'active' ); |
| 243 |
var selected_title = jQuery( '.do_expand__' + section_to_show + '_link a .wpbc_ui_el__vert_nav_title ' ).text(); |
| 244 |
|
| 245 |
// Expand section, if it colapsed. |
| 246 |
if ( ! jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).hasClass( 'expanded' ) ) { |
| 247 |
jQuery( '.wpbc_ui_el__level__folder' ).removeClass( 'expanded' ); |
| 248 |
jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).addClass( 'expanded' ); |
| 249 |
} |
| 250 |
|
| 251 |
// -- Expand section --------------------------------------------------------------------------------------- |
| 252 |
var container_to_hide_class = '.postbox'; |
| 253 |
// Hide sections '.postbox' in admin page and show specific one. |
| 254 |
jQuery( '.wpbc_admin_page ' + container_to_hide_class ).hide(); |
| 255 |
jQuery( '.wpbc_container_always_hide__on_left_nav_click' ).hide(); |
| 256 |
jQuery( section_id_to_show ).show(); |
| 257 |
|
| 258 |
// Show all other sections, if provided in URL: ..?page=wpbc-settings#do_expand__wpbc_general_settings_capacity_metabox#wpbc_general_settings_capacity_upgrade_metabox . |
| 259 |
for ( let i = 1; i < anchors_arr_length; i++ ) { |
| 260 |
jQuery( '#' + anchors_arr[i] ).show(); |
| 261 |
} |
| 262 |
|
| 263 |
if ( false ) { |
| 264 |
var targetOffset = wpbc_scroll_to( section_id_to_show ); |
| 265 |
} |
| 266 |
|
| 267 |
// -- Set Value to Input about selected Nav element --------------------------------------------------------------- // FixIn: 9.8.6.1. |
| 268 |
var section_id_tab = section_id_to_show.substring( 0, section_id_to_show.length - 8 ) + '_tab'; |
| 269 |
if ( container_to_hide_class == section_id_to_show ) { |
| 270 |
section_id_tab = '#wpbc_general_settings_all_tab' |
| 271 |
} |
| 272 |
if ( '#wpbc_general_settings_capacity_metabox,#wpbc_general_settings_capacity_upgrade_metabox' == section_id_to_show ) { |
| 273 |
section_id_tab = '#wpbc_general_settings_capacity_tab' |
| 274 |
} |
| 275 |
jQuery( '#form_visible_section' ).val( section_id_tab ); |
| 276 |
} |
| 277 |
|
| 278 |
// Like blinking some elements. |
| 279 |
wpbc_admin_ui__do__anchor__another_actions(); |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
function wpbc_admin_ui__is_in_mobile_screen_size() { |
| 284 |
return wpbc_admin_ui__is_in_this_screen_size( 605 ); |
| 285 |
} |
| 286 |
|
| 287 |
function wpbc_admin_ui__is_in_this_screen_size(size) { |
| 288 |
return (window.screen.width <= size); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Open settings page | Expand section | Select Menu item. |
| 293 |
*/ |
| 294 |
function wpbc_admin_ui__do__open_url__expand_section(url, section_id) { |
| 295 |
|
| 296 |
// window.location.href = url + '&do_expand=' + section_id + '#do_expand__' + section_id; //. |
| 297 |
window.location.href = url + '#do_expand__' + section_id; |
| 298 |
|
| 299 |
if ( wpbc_admin_ui__is_in_mobile_screen_size() ) { |
| 300 |
wpbc_admin_ui__sidebar_left__do_min(); |
| 301 |
} |
| 302 |
|
| 303 |
wpbc_admin_ui__do_expand_section(); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
/** |
| 308 |
* Check for Other actions: Like blinking some elements in settings page. E.g. Days selection or change-over days. |
| 309 |
*/ |
| 310 |
function wpbc_admin_ui__do__anchor__another_actions() { |
| 311 |
|
| 312 |
var anchors_arr = wpbc_url_get_anchors_arr(); |
| 313 |
var anchors_arr_length = anchors_arr.length; |
| 314 |
|
| 315 |
// Other actions: Like blinking some elements. |
| 316 |
for ( var i = 0; i < anchors_arr_length; i++ ) { |
| 317 |
|
| 318 |
var this_anchor = anchors_arr[i]; |
| 319 |
|
| 320 |
var this_anchor_prop_value = this_anchor.split( 'do_other_actions__' ); |
| 321 |
|
| 322 |
if ( this_anchor_prop_value.length > 1 ) { |
| 323 |
|
| 324 |
var section_action = this_anchor_prop_value[1]; |
| 325 |
|
| 326 |
switch ( section_action ) { |
| 327 |
|
| 328 |
case 'blink_day_selections': |
| 329 |
// wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Days Selection' );. |
| 330 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_type_of_day_selections', 4, 350 ); |
| 331 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_type_of_day_selections' ); |
| 332 |
break; |
| 333 |
|
| 334 |
case 'blink_change_over_days': |
| 335 |
// wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Changeover Days' );. |
| 336 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_range_selection_time_is_active', 4, 350 ); |
| 337 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_range_selection_time_is_active' ); |
| 338 |
break; |
| 339 |
|
| 340 |
case 'blink_captcha': |
| 341 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_is_use_captcha', 4, 350 ); |
| 342 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_is_use_captcha' ); |
| 343 |
break; |
| 344 |
|
| 345 |
default: |
| 346 |
} |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
|