| 1 |
"use strict"; |
| 2 |
// ===================================================================================================================== |
| 3 |
// == Left Bar - expand / colapse functions == |
| 4 |
// ===================================================================================================================== |
| 5 |
|
| 6 |
/** |
| 7 |
* Expand Vertical Left Bar. |
| 8 |
*/ |
| 9 |
function wpbc_admin_ui__sidebar_left__do_max() { |
| 10 |
jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' ); |
| 11 |
jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'max' ); |
| 12 |
jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).addClass( 'wpbc_ui__hide' ); |
| 13 |
jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' ); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Hide Vertical Left Bar. |
| 18 |
*/ |
| 19 |
function wpbc_admin_ui__sidebar_left__do_min() { |
| 20 |
jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' ); |
| 21 |
jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'min' ); |
| 22 |
jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' ); |
| 23 |
jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Colapse Vertical Left Bar. |
| 28 |
*/ |
| 29 |
function wpbc_admin_ui__sidebar_left__do_compact() { |
| 30 |
jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' ); |
| 31 |
jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'compact' ); |
| 32 |
jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' ); |
| 33 |
jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Completely Hide Vertical Left Bar. |
| 38 |
*/ |
| 39 |
function wpbc_admin_ui__sidebar_left__do_hide() { |
| 40 |
jQuery( '.wpbc_settings_page_wrapper' ).removeClass( 'min max compact none' ); |
| 41 |
jQuery( '.wpbc_settings_page_wrapper' ).addClass( 'none' ); |
| 42 |
jQuery( '.wpbc_ui__top_nav__btn_open_left_vertical_nav' ).removeClass( 'wpbc_ui__hide' ); |
| 43 |
jQuery( '.wpbc_ui__top_nav__btn_hide_left_vertical_nav' ).addClass( 'wpbc_ui__hide' ); |
| 44 |
// Hide top "Menu" button with divider. |
| 45 |
jQuery( '.wpbc_ui__top_nav__btn_show_left_vertical_nav,.wpbc_ui__top_nav__btn_show_left_vertical_nav_divider' ).addClass( 'wpbc_ui__hide' ); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Action on click "Go Back" - show root menu |
| 50 |
* or some other section in left sidebar. |
| 51 |
* |
| 52 |
* @param string menu_to_show - menu slug. |
| 53 |
*/ |
| 54 |
function wpbc_admin_ui__sidebar_left__show_section( menu_to_show ) { |
| 55 |
jQuery( '.wpbc_ui_el__vert_left_bar__section' ).addClass( 'wpbc_ui__hide' ) |
| 56 |
jQuery( '.wpbc_ui_el__vert_left_bar__section_' + menu_to_show ).removeClass( 'wpbc_ui__hide' ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
/** |
| 61 |
* Get anchor(s) array from URL. |
| 62 |
* Doc: https://developer.mozilla.org/en-US/docs/Web/API/Location |
| 63 |
* |
| 64 |
* @returns {*[]} |
| 65 |
*/ |
| 66 |
function wpbc_url_get_anchors_arr() { |
| 67 |
var hashes = window.location.hash.replace( '%23', '#' ); |
| 68 |
var hashes_arr = hashes.split( '#' ); |
| 69 |
var result = []; |
| 70 |
var hashes_arr_length = hashes_arr.length; |
| 71 |
|
| 72 |
for ( var i = 0; i < hashes_arr_length; i++ ) { |
| 73 |
if ( hashes_arr[i].length > 0 ) { |
| 74 |
result.push( hashes_arr[i] ); |
| 75 |
} |
| 76 |
} |
| 77 |
return result; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Auto Expand Settings section based on URL anchor, after page loaded. |
| 82 |
*/ |
| 83 |
jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 10 ); } ); |
| 84 |
jQuery( document ).ready( function () { wpbc_admin_ui__do_expand_section(); setTimeout( 'wpbc_admin_ui__do_expand_section', 150 ); } ); |
| 85 |
|
| 86 |
/** |
| 87 |
* Expand section in General Settings page and select Menu item. |
| 88 |
*/ |
| 89 |
function wpbc_admin_ui__do_expand_section() { |
| 90 |
|
| 91 |
// window.location.hash = #section_id / doc: https://developer.mozilla.org/en-US/docs/Web/API/Location . |
| 92 |
var anchors_arr = wpbc_url_get_anchors_arr(); |
| 93 |
var anchors_arr_length = anchors_arr.length; |
| 94 |
|
| 95 |
if ( anchors_arr_length > 0 ) { |
| 96 |
var one_anchor_prop_value = anchors_arr[0].split( 'do_expand__' ); |
| 97 |
if ( one_anchor_prop_value.length > 1 ) { |
| 98 |
|
| 99 |
// 'wpbc_general_settings_calendar_metabox' |
| 100 |
var section_to_show = one_anchor_prop_value[1]; |
| 101 |
var section_id_to_show = '#' + section_to_show; |
| 102 |
|
| 103 |
|
| 104 |
// -- Remove selected background in all left menu items --------------------------------------------------- |
| 105 |
jQuery( '.wpbc_ui_el__vert_nav_item ' ).removeClass( 'active' ); |
| 106 |
// Set left menu selected. |
| 107 |
jQuery( '.do_expand__' + section_to_show + '_link' ).addClass( 'active' ); |
| 108 |
var selected_title = jQuery( '.do_expand__' + section_to_show + '_link a .wpbc_ui_el__vert_nav_title ' ).text(); |
| 109 |
|
| 110 |
// Expand section, if it colapsed. |
| 111 |
if ( ! jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).hasClass( 'expanded' ) ) { |
| 112 |
jQuery( '.wpbc_ui_el__level__folder' ).removeClass( 'expanded' ); |
| 113 |
jQuery( '.do_expand__' + section_to_show + '_link' ).parents( '.wpbc_ui_el__level__folder' ).addClass( 'expanded' ); |
| 114 |
} |
| 115 |
|
| 116 |
// -- Expand section --------------------------------------------------------------------------------------- |
| 117 |
var container_to_hide_class = '.postbox'; |
| 118 |
// Hide sections '.postbox' in admin page and show specific one. |
| 119 |
jQuery( '.wpbc_admin_page ' + container_to_hide_class ).hide(); |
| 120 |
jQuery( '.wpbc_container_always_hide__on_left_nav_click' ).hide(); |
| 121 |
jQuery( section_id_to_show ).show(); |
| 122 |
|
| 123 |
// Show all other sections, if provided in URL: ..?page=wpbc-settings#do_expand__wpbc_general_settings_capacity_metabox#wpbc_general_settings_capacity_upgrade_metabox . |
| 124 |
for ( let i = 1; i < anchors_arr_length; i++ ) { |
| 125 |
jQuery( '#' + anchors_arr[i] ).show(); |
| 126 |
} |
| 127 |
|
| 128 |
if ( false ) { |
| 129 |
var targetOffset = wpbc_scroll_to( section_id_to_show ); |
| 130 |
} |
| 131 |
|
| 132 |
// -- Set Value to Input about selected Nav element --------------------------------------------------------------- // FixIn: 9.8.6.1. |
| 133 |
var section_id_tab = section_id_to_show.substring( 0, section_id_to_show.length - 8 ) + '_tab'; |
| 134 |
if ( container_to_hide_class == section_id_to_show ) { |
| 135 |
section_id_tab = '#wpbc_general_settings_all_tab' |
| 136 |
} |
| 137 |
if ( '#wpbc_general_settings_capacity_metabox,#wpbc_general_settings_capacity_upgrade_metabox' == section_id_to_show ) { |
| 138 |
section_id_tab = '#wpbc_general_settings_capacity_tab' |
| 139 |
} |
| 140 |
jQuery( '#form_visible_section' ).val( section_id_tab ); |
| 141 |
} |
| 142 |
|
| 143 |
// Like blinking some elements. |
| 144 |
wpbc_admin_ui__do__anchor__another_actions(); |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
/** |
| 149 |
* Open settings page | Expand section | Select Menu item. |
| 150 |
*/ |
| 151 |
function wpbc_admin_ui__do__open_url__expand_section(url, section_id) { |
| 152 |
|
| 153 |
// window.location.href = url + '&do_expand=' + section_id + '#do_expand__' + section_id; //. |
| 154 |
window.location.href = url + '#do_expand__' + section_id; |
| 155 |
|
| 156 |
wpbc_admin_ui__do_expand_section(); |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
/** |
| 161 |
* Check for Other actions: Like blinking some elements in settings page. E.g. Days selection or change-over days. |
| 162 |
*/ |
| 163 |
function wpbc_admin_ui__do__anchor__another_actions() { |
| 164 |
|
| 165 |
var anchors_arr = wpbc_url_get_anchors_arr(); |
| 166 |
var anchors_arr_length = anchors_arr.length; |
| 167 |
|
| 168 |
// Other actions: Like blinking some elements. |
| 169 |
for ( var i = 0; i < anchors_arr_length; i++ ) { |
| 170 |
|
| 171 |
var this_anchor = anchors_arr[i]; |
| 172 |
|
| 173 |
var this_anchor_prop_value = this_anchor.split( 'do_other_actions__' ); |
| 174 |
|
| 175 |
if ( this_anchor_prop_value.length > 1 ) { |
| 176 |
|
| 177 |
var section_action = this_anchor_prop_value[1]; |
| 178 |
|
| 179 |
switch ( section_action ) { |
| 180 |
|
| 181 |
case 'blink_day_selections': |
| 182 |
// wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Days Selection' );. |
| 183 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_type_of_day_selections', 4, 350 ); |
| 184 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_type_of_day_selections' ); |
| 185 |
break; |
| 186 |
|
| 187 |
case 'blink_change_over_days': |
| 188 |
// wpbc_ui_settings__panel__click( '#wpbc_general_settings_calendar_tab a', '#wpbc_general_settings_calendar_metabox', 'Changeover Days' );. |
| 189 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_range_selection_time_is_active', 4, 350 ); |
| 190 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_range_selection_time_is_active' ); |
| 191 |
break; |
| 192 |
|
| 193 |
case 'blink_captcha': |
| 194 |
wpbc_blink_element( '.wpbc_tr_set_gen_booking_is_use_captcha', 4, 350 ); |
| 195 |
wpbc_scroll_to( '.wpbc_tr_set_gen_booking_is_use_captcha' ); |
| 196 |
break; |
| 197 |
|
| 198 |
default: |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
} |