|
if (!class_exists('Expand_Sidebar_Panels_On_MouseEnter')) { |
|
class Expand_Sidebar_Panels_On_MouseEnter { |
|
public function __construct() { |
|
add_action('admin_footer', array($this, 'add_inline_script')); |
|
} |
|
|
|
public function add_inline_script() { |
|
if (!function_exists('\get_current_screen')) { |
|
return false; |
|
} |
|
$screen = \get_current_screen(); |
|
if (method_exists($screen, 'is_block_editor') && $screen->is_block_editor()) { |
|
?> |
|
<script type="text/javascript"> |
|
setTimeout(() => { |
|
|
|
(function () { |
|
function handleMouseEnter() { |
|
const panelBodies = document.querySelectorAll('div.components-panel__body:not(.is-opened)'); |
|
panelBodies.forEach((panelBody) => { |
|
const buttons = panelBody.querySelectorAll('button.components-button'); |
|
buttons.forEach((button) => button.click()); |
|
}); |
|
} |
|
|
|
function getRandomInt(min, max) { |
|
min = Math.ceil(min); |
|
max = Math.floor(max); |
|
return Math.floor(Math.random() * (max - min) + min); |
|
} |
|
|
|
const randSec = getRandomInt(60, 90) * 1000; |
|
|
|
function handleMouseEnterWithInterval() { |
|
const panelContainer = document.querySelector('div.components-panel'); |
|
if (panelContainer) { |
|
panelContainer.removeEventListener('mouseenter', handleMouseEnter); |
|
panelContainer.addEventListener('mouseenter', handleMouseEnter); |
|
console.log('Block Editor: Expand All Sidebar Panels on MouseEnter [SnipSnip.pro]', randSec); |
|
} |
|
|
|
setTimeout(handleMouseEnterWithInterval, randSec); |
|
} |
|
|
|
handleMouseEnterWithInterval(); |
|
})(); |
|
|
|
|
|
}, 7373); |
|
</script> |
|
<?php |
|
} |
|
} |
|
} |
|
|
|
new Expand_Sidebar_Panels_On_MouseEnter(); |
|
} |
UPDATE! There's (another) newer, better version!
When using WordPress Gutenberg / Block Editor / Full Site Editor / etc - I don't like having to always click on the different sections in the sidebar pane in order to expand them and get to the Advanced section (to enter anchor id) or other options. So this just auto opens them anytime your mouse enters the sidebar.