| 1 |
"use strict"; |
| 2 |
// ===================================================================================================================== |
| 3 |
// == Full Screen - support functions == |
| 4 |
// ===================================================================================================================== |
| 5 |
|
| 6 |
/** |
| 7 |
* Save Full Screen preference in a short browser cookie. |
| 8 |
* |
| 9 |
* This makes the next admin page load deterministic even if the async user-meta |
| 10 |
* AJAX request is interrupted by immediate navigation. |
| 11 |
* |
| 12 |
* @param string value 'On' or 'Off'. |
| 13 |
*/ |
| 14 |
function wpbc_admin_ui__full_screen__set_cookie( value ) { |
| 15 |
var max_age = 60 * 60 * 24 * 365; |
| 16 |
|
| 17 |
document.cookie = 'wpbc_admin_full_screen=' + encodeURIComponent( value ) + '; path=/; max-age=' + max_age + '; SameSite=Lax'; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Apply Full Screen mode from a user click. |
| 22 |
* |
| 23 |
* @param HTMLElement el Clicked control. |
| 24 |
* @param bool is_save_user_state Whether to save user preference. |
| 25 |
*/ |
| 26 |
function wpbc_admin_ui__full_screen__do_on( el, is_save_user_state ) { |
| 27 |
jQuery( 'body' ).addClass( 'wpbc_admin_full_screen' ); |
| 28 |
wpbc_check_full_screen_mode(); |
| 29 |
|
| 30 |
if ( is_save_user_state ) { |
| 31 |
wpbc_admin_ui__full_screen__set_cookie( 'On' ); |
| 32 |
|
| 33 |
if ( 'function' === typeof wpbc_save_custom_user_data_from_element ) { |
| 34 |
wpbc_save_custom_user_data_from_element( el ); |
| 35 |
} |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Exit Full Screen mode from a user click. |
| 41 |
* |
| 42 |
* @param HTMLElement el Clicked control. |
| 43 |
* @param bool is_save_user_state Whether to save user preference. |
| 44 |
*/ |
| 45 |
function wpbc_admin_ui__full_screen__do_off( el, is_save_user_state ) { |
| 46 |
jQuery( 'body' ).removeClass( 'wpbc_admin_full_screen' ); |
| 47 |
wpbc_check_full_screen_mode(); |
| 48 |
|
| 49 |
if ( is_save_user_state ) { |
| 50 |
wpbc_admin_ui__full_screen__set_cookie( 'Off' ); |
| 51 |
|
| 52 |
if ( 'function' === typeof wpbc_save_custom_user_data_from_element ) { |
| 53 |
wpbc_save_custom_user_data_from_element( el ); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Check Full screen mode, by removing top tab |
| 60 |
*/ |
| 61 |
function wpbc_check_full_screen_mode(){ |
| 62 |
if ( jQuery( 'body' ).hasClass( 'wpbc_admin_full_screen' ) ) { |
| 63 |
jQuery( 'html' ).removeClass( 'wp-toolbar' ); |
| 64 |
} else { |
| 65 |
jQuery( 'html' ).addClass( 'wp-toolbar' ); |
| 66 |
} |
| 67 |
wpbc_check_buttons_max_min_in_full_screen_mode(); |
| 68 |
} |
| 69 |
|
| 70 |
function wpbc_check_buttons_max_min_in_full_screen_mode() { |
| 71 |
if ( jQuery( 'body' ).hasClass( 'wpbc_admin_full_screen' ) ) { |
| 72 |
jQuery( '.wpbc_ui__top_nav__btn_full_screen' ).addClass( 'wpbc_ui__hide' ); |
| 73 |
jQuery( '.wpbc_ui__top_nav__btn_normal_screen' ).removeClass( 'wpbc_ui__hide' ); |
| 74 |
} else { |
| 75 |
jQuery( '.wpbc_ui__top_nav__btn_full_screen' ).removeClass( 'wpbc_ui__hide' ); |
| 76 |
jQuery( '.wpbc_ui__top_nav__btn_normal_screen' ).addClass( 'wpbc_ui__hide' ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
jQuery( document ).ready( function () { |
| 81 |
wpbc_check_full_screen_mode(); |
| 82 |
} ); |
| 83 |
|