diff --git a/assets/js/odw-admin-fields.js b/assets/js/odw-admin-fields.js index 8809c36..6f89664 100644 --- a/assets/js/odw-admin-fields.js +++ b/assets/js/odw-admin-fields.js @@ -220,27 +220,42 @@ } // ------------------------------------------------------------------------- - // Auto-show distribution fields by clicking "Add Entry" on load + // Auto-show distribution fields when Tab 3 is activated // ------------------------------------------------------------------------- function autoShowDistributionFields() { - // Find the distributions complex field container - var distributionsContainer = document.querySelector( '[data-carbon-field="odw_distributions"]' ); - if ( ! distributionsContainer ) { - return; - } + // Only run once per page load + var ran = false; - // Check if there are any existing entries (groups) - var existingGroups = distributionsContainer.querySelectorAll( '.cf-complex__group' ); - if ( existingGroups.length > 0 ) { - // Entries already exist, no need to auto-add - return; - } + function tryClickAddEntry() { + if ( ran ) { + return; + } + + // The placeholder is only visible when there are no entries yet + var placeholder = document.querySelector( '.cf-complex__placeholder' ); + if ( ! placeholder ) { + return; + } - // No entries exist, click "Add Entry" to show empty form - var addButton = distributionsContainer.querySelector( '.cf-complex__actions button' ); - if ( addButton ) { - addButton.click(); + // Find the "Add Entry" inserter button next to or after the placeholder + var inserterButton = document.querySelector( '.cf-complex__inserter-button' ); + if ( ! inserterButton ) { + return; + } + + ran = true; + inserterButton.click(); } + + // Watch for Carbon Fields rendering the placeholder (lazy tab render) + var observer = new MutationObserver( function () { + tryClickAddEntry(); + } ); + + observer.observe( document.body, { childList: true, subtree: true } ); + + // Also try immediately in case tab is already active + tryClickAddEntry(); } // ------------------------------------------------------------------------- diff --git a/open-data-wizard.php b/open-data-wizard.php index a54f82c..b52dad7 100644 --- a/open-data-wizard.php +++ b/open-data-wizard.php @@ -3,7 +3,7 @@ * Plugin Name: Open Data Wizard * Plugin URI: https://github.com/daimpad/OpenDataWizard * Description: DCAT-AP 3.0 konforme Open Data Metadatenverwaltung für WordPress. Bereitstellung als maschinenlesbarer JSON-LD-Endpoint für offene Daten. - * Version: 2.1.1 + * Version: 2.1.2 * Requires at least: 6.4 * Requires PHP: 8.1 * Author: nozilla @@ -25,7 +25,7 @@ exit; } -define( 'ODW_VERSION', '2.1.1' ); +define( 'ODW_VERSION', '2.1.2' ); define( 'ODW_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); define( 'ODW_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'ODW_PLUGIN_FILE', __FILE__ );