| 1 |
// Hide a given message |
| 2 |
function edit_flow_hide_message() { |
| 3 |
jQuery( '.edit-flow-message' ).fadeOut( function () { |
| 4 |
jQuery( this ).remove(); |
| 5 |
} ); |
| 6 |
} |
| 7 |
|
| 8 |
jQuery( document ).ready( function () { |
| 9 |
// Restore the Edit Flow submenu if there are no modules enabled |
| 10 |
// We need it down below for dynamically rebuilding the link list when on the settings page |
| 11 |
const ef_settings_submenu_html = |
| 12 |
'<div class="wp-submenu"><div class="wp-submenu-wrap"><div class="wp-submenu-head">Edit Flow</div><ul><li class="wp-first-item current"><a tabindex="1" class="wp-first-item current" href="admin.php?page=ef-settings">Edit Flow</a></li></ul></div></div>'; |
| 13 |
if ( jQuery( 'li#toplevel_page_ef-settings .wp-submenu' ).length == 0 ) { |
| 14 |
jQuery( 'li#toplevel_page_ef-settings' ).addClass( |
| 15 |
'wp-has-submenu wp-has-current-submenu wp-menu-open' |
| 16 |
); |
| 17 |
jQuery( 'li#toplevel_page_ef-settings' ).append( ef_settings_submenu_html ); |
| 18 |
jQuery( 'li#toplevel_page_ef-settings .wp-submenu' ).show(); |
| 19 |
} |
| 20 |
|
| 21 |
// Set auto-removal to 8 seconds |
| 22 |
if ( jQuery( '.edit-flow-message' ).length > 0 ) { |
| 23 |
setTimeout( edit_flow_hide_message, 8000 ); |
| 24 |
} |
| 25 |
|
| 26 |
jQuery( '.enable-disable-edit-flow-module' ).on( 'click', function () { |
| 27 |
if ( jQuery( this ).hasClass( 'button-primary' ) ) { |
| 28 |
var module_action = 'enable'; |
| 29 |
} else if ( jQuery( this ).hasClass( 'button-remove' ) ) { |
| 30 |
var module_action = 'disable'; |
| 31 |
} |
| 32 |
|
| 33 |
const slug = jQuery( this ).closest( '.edit-flow-module' ).attr( 'id' ); |
| 34 |
const change_module_nonce = jQuery( '#' + slug + ' #change-module-nonce-' + slug ).val(); |
| 35 |
const data = { |
| 36 |
action: 'change_edit_flow_module_state', |
| 37 |
module_action, |
| 38 |
slug, |
| 39 |
change_module_nonce, |
| 40 |
}; |
| 41 |
|
| 42 |
jQuery.post( ajaxurl, data, function ( response ) { |
| 43 |
if ( response == 1 ) { |
| 44 |
jQuery( '#' + slug + ' .enable-disable-edit-flow-module' ).hide(); |
| 45 |
if ( module_action == 'disable' ) { |
| 46 |
jQuery( '#' + slug ) |
| 47 |
.addClass( 'module-disabled' ) |
| 48 |
.removeClass( 'module-enabled' ); |
| 49 |
jQuery( '#' + slug + ' .enable-disable-edit-flow-module.button-primary' ).show(); |
| 50 |
jQuery( '#' + slug + ' a.configure-edit-flow-module' ) |
| 51 |
.hide() |
| 52 |
.addClass( 'hidden' ); |
| 53 |
// If there was a configuration URL in the module, let's hide it from the left nav too |
| 54 |
if ( jQuery( '#' + slug + ' a.configure-edit-flow-module' ).length > 0 ) { |
| 55 |
var configure_url = jQuery( '#' + slug + ' a.configure-edit-flow-module' ) |
| 56 |
.attr( 'href' ) |
| 57 |
.replace( ef_admin_url, '' ); |
| 58 |
var top_level_menu = jQuery( '#' + adminpage ); |
| 59 |
jQuery( '.wp-submenu-wrap li a', top_level_menu ).each( function () { |
| 60 |
if ( jQuery( this ).attr( 'href' ) == configure_url ) { |
| 61 |
jQuery( this ) |
| 62 |
.closest( 'li' ) |
| 63 |
.fadeOut( function () { |
| 64 |
jQuery( this ).remove(); |
| 65 |
} ); |
| 66 |
} |
| 67 |
} ); |
| 68 |
} |
| 69 |
} else if ( module_action == 'enable' ) { |
| 70 |
jQuery( '#' + slug ) |
| 71 |
.addClass( 'module-enabled' ) |
| 72 |
.removeClass( 'module-disabled' ); |
| 73 |
jQuery( '#' + slug + ' .enable-disable-edit-flow-module.button-remove' ).show(); |
| 74 |
jQuery( '#' + slug + ' a.configure-edit-flow-module' ) |
| 75 |
.show() |
| 76 |
.removeClass( 'hidden' ); |
| 77 |
// If there was a configuration URL in the module, let's go through the complex process of adding it again to the left nav |
| 78 |
if ( jQuery( '#' + slug + ' a.configure-edit-flow-module' ).length > 0 ) { |
| 79 |
// Identify the order it should be in |
| 80 |
let link_order = 0; |
| 81 |
let counter = 0; |
| 82 |
jQuery( '.edit-flow-module.has-configure-link' ).each( function ( key, item ) { |
| 83 |
if ( |
| 84 |
jQuery( this ).attr( 'id' ) == slug && |
| 85 |
! jQuery( 'a.configure-edit-flow-module', this ).hasClass( 'hidden' ) |
| 86 |
) { |
| 87 |
link_order = counter; |
| 88 |
} |
| 89 |
if ( ! jQuery( 'a.configure-edit-flow-module', this ).hasClass( 'hidden' ) ) { |
| 90 |
counter++; |
| 91 |
} |
| 92 |
} ); |
| 93 |
// Build the HTML for the new link |
| 94 |
var configure_url = jQuery( '#' + slug + ' a.configure-edit-flow-module' ) |
| 95 |
.attr( 'href' ) |
| 96 |
.replace( ef_admin_url, '' ); |
| 97 |
var top_level_menu = jQuery( '#' + adminpage ); |
| 98 |
const html_title = jQuery( '#' + slug + ' h4' ).html(); |
| 99 |
const html_insert = |
| 100 |
'<li><a class="ef-settings-fade-in" style="display:none;" href="' + |
| 101 |
configure_url + |
| 102 |
'" tabindex="1">' + |
| 103 |
html_title + |
| 104 |
'</a>'; |
| 105 |
jQuery( '.wp-submenu-wrap ul li', top_level_menu ).each( function ( key, item ) { |
| 106 |
if ( key == link_order ) { |
| 107 |
jQuery( this ).after( html_insert ); |
| 108 |
} |
| 109 |
} ); |
| 110 |
// Trick way to do a fade in: add a class of 'ef-settings-fade-in' and run it after the action |
| 111 |
jQuery( '.ef-settings-fade-in' ).fadeIn().removeClass( 'ef-settings-fade-in' ); |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
return false; |
| 116 |
} ); |
| 117 |
|
| 118 |
return false; |
| 119 |
} ); |
| 120 |
} ); |
| 121 |
|