refactor: replace verbose JS with hyperscript for contact form timestamp

Removed 34 lines of JavaScript (IIFE, MutationObserver, DOMContentLoaded)
and replaced with 2 lines of hyperscript in the existing 'on show' handler.
This commit is contained in:
juanatsap
2025-12-02 15:52:33 +00:00
parent bd859c318f
commit 2dd0922a63
+4 -34
View File
@@ -15,7 +15,10 @@
remove .hidden from querySelector('.form-note') in form
set responseDiv to getElementById('contact-response')
if responseDiv set responseDiv.innerHTML to ''
end">
end
-- Set timestamp for bot protection
set tsField to getElementById('contact-form-loaded-at')
if tsField set tsField.value to Date.now()">
<div class="info-modal-content">
<button class="info-modal-close" commandfor="contact-modal" command="close" aria-label="{{.UI.ContactModal.Close}}">
<iconify-icon icon="mdi:close" width="24" height="24"></iconify-icon>
@@ -158,37 +161,4 @@
</div>
</dialog>
<!-- Initialize form timestamp on page load and modal open -->
<script>
(function() {
'use strict';
function resetContactFormTimestamp() {
const timestampField = document.getElementById('contact-form-loaded-at');
if (timestampField) {
timestampField.value = Date.now();
}
}
// Set initial timestamp on page load
document.addEventListener('DOMContentLoaded', resetContactFormTimestamp);
// Reset timestamp when modal opens (using MutationObserver to catch dialog open)
document.addEventListener('DOMContentLoaded', function() {
const contactModal = document.getElementById('contact-modal');
if (contactModal) {
// Observer watches for the 'open' attribute being added
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.attributeName === 'open' && contactModal.hasAttribute('open')) {
resetContactFormTimestamp();
}
});
});
observer.observe(contactModal, { attributes: true });
}
});
})();
</script>
{{end}}