Release 0.1.6 — fix AJAX step-save listeners never attaching (hc-5yy)
The 0.1.5 auto-save never fired: the inline <script> is emitted before the
step cards in the markup, so document.querySelectorAll('form.att-hc-step-save')
ran at parse time against a DOM with no forms yet and attached no listeners —
changing status or blurring notes produced no request at all.
The pre-existing step-history loader had the identical latent defect (its
"Previous notes" expander was also dead on live for the same reason).
Fix: both inline scripts now defer their querySelectorAll wiring to
DOMContentLoaded, so it runs after the cards are parsed. No reordering of the
markup, so the <style> blocks stay put and there's no flash of unstyled UI.
Bumps header, ATT_HC_VERSION and updates.json so PUC offers it to the sites
already on the broken 0.1.5. Plugin-only; server untouched.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -387,6 +387,12 @@ function att_hc_print_step_history_assets(ATT_HC_Session $session): void {
|
||||
'</div>';
|
||||
}).join('');
|
||||
}
|
||||
// Emitted before the step cards, so defer wiring until the DOM exists.
|
||||
function ready(fn) {
|
||||
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', fn); }
|
||||
else { fn(); }
|
||||
}
|
||||
ready(function () {
|
||||
document.querySelectorAll('details.att-hc-history').forEach(function (det) {
|
||||
det.addEventListener('toggle', function () {
|
||||
if (!det.open || det.dataset.loaded === 'yes') return;
|
||||
@@ -414,6 +420,7 @@ function att_hc_print_step_history_assets(ATT_HC_Session $session): void {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
@@ -445,6 +452,14 @@ function att_hc_print_step_save_assets(ATT_HC_Session $session): void {
|
||||
var cfg = <?php echo wp_json_encode($cfg); ?>;
|
||||
function statusLabel(s) { return s.replace(/_/g, ' '); }
|
||||
|
||||
// These assets are emitted before the step cards in the markup, so the
|
||||
// forms don't exist yet when this inline script first runs. Wait for the
|
||||
// DOM before wiring listeners.
|
||||
function ready(fn) {
|
||||
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', fn); }
|
||||
else { fn(); }
|
||||
}
|
||||
ready(function () {
|
||||
document.querySelectorAll('form.att-hc-step-save').forEach(function (form) {
|
||||
var stepId = form.dataset.step;
|
||||
var select = form.querySelector('select[name="status"]');
|
||||
@@ -519,6 +534,7 @@ function att_hc_print_step_save_assets(ATT_HC_Session $session): void {
|
||||
save(notes);
|
||||
});
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user