| @@ -2,9 +2,40 @@ | ||
| 2 | 2 | * Blockenberg Editor Scripts |
| 3 | 3 | * Common functionality for all blocks |
| 4 | 4 | */ |
| 5 | 5 | wp.domReady(function() { |
| 6 | - | |
| 6 | + | |
| 7 | + /* ============================================= | |
| 8 | + Color ToolsPanel → collapsible (PanelBody-style) | |
| 9 | + ============================================= */ | |
| 10 | + function initColorPanelToggles(root) { | |
| 11 | + var panels = (root || document).querySelectorAll( | |
| 12 | + '.block-editor-panel-color-gradient-settings:not([data-bkbg-collapse-init])' | |
| 13 | + ); | |
| 14 | + panels.forEach(function (panel) { | |
| 15 | + panel.setAttribute('data-bkbg-collapse-init', '1'); | |
| 16 | + // Start collapsed | |
| 17 | + panel.classList.add('bkbg-panel-collapsed'); | |
| 18 | + | |
| 19 | + var header = panel.querySelector('.components-tools-panel-header'); | |
| 20 | + if (!header) return; | |
| 21 | + | |
| 22 | + header.addEventListener('click', function (e) { | |
| 23 | + // Don't toggle when clicking a child interactive element (buttons, inputs) | |
| 24 | + if (e.target.closest('button, input, select, .components-dropdown-menu')) return; | |
| 25 | + panel.classList.toggle('bkbg-panel-collapsed'); | |
| 26 | + }); | |
| 27 | + }); | |
| 28 | + } | |
| 29 | + | |
| 30 | + // Re-run whenever the sidebar DOM changes (block selection, tab switch, etc.) | |
| 31 | + var colorPanelObserver = new MutationObserver(function () { | |
| 32 | + initColorPanelToggles(); | |
| 33 | + }); | |
| 34 | + colorPanelObserver.observe(document.body, { childList: true, subtree: true }); | |
| 35 | + // Initial pass | |
| 36 | + initColorPanelToggles(); | |
| 37 | + | |
| 7 | 38 | // Track global drag state for showing drop zones |
| 8 | 39 | var isDragging = false; |
| 9 | 40 | var currentDropTarget = null; |
| 10 | 41 | |