forked from andyburke/autonomous.contact
feature: blurbs
refactor: style updates and fixes
This commit is contained in:
parent
591fd38088
commit
cbd58071b8
9 changed files with 101 additions and 52 deletions
|
|
@ -1,8 +1,7 @@
|
|||
function smarten_forms() {
|
||||
const forms = document.body.querySelectorAll("form[data-smart]:not([data-smartened])");
|
||||
const forms = document?.body?.querySelectorAll("form[data-smart]:not([data-smartened])") ?? [];
|
||||
for (const form of forms) {
|
||||
async function on_submit(event) {
|
||||
debugger;
|
||||
event.preventDefault();
|
||||
form.disabled = true;
|
||||
form.__submitted_at = new Date();
|
||||
|
|
|
|||
31
public/js/textareaenhancements.js
Normal file
31
public/js/textareaenhancements.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
function enhance_textareas() {
|
||||
const textareas = document.body.querySelectorAll("textarea:not([data-enhanced])");
|
||||
for (const textarea of textareas) {
|
||||
const max_length_attr = textarea.getAttribute("maxlength");
|
||||
if (/^\d+$/.test(max_length_attr)) {
|
||||
const max_length = parseInt(max_length_attr, 10);
|
||||
|
||||
function on_updated() {
|
||||
const counters = this.parentElement.querySelectorAll(
|
||||
`[data-limit-counter-for="${this.name}"]`,
|
||||
);
|
||||
for (const counter of counters) {
|
||||
counter.innerHTML = `${this.value.length} / ${max_length}`;
|
||||
}
|
||||
}
|
||||
|
||||
textarea.addEventListener("keyup", on_updated);
|
||||
textarea.addEventListener("paste", on_updated);
|
||||
textarea.addEventListener("blur", on_updated);
|
||||
on_updated.call(textarea);
|
||||
}
|
||||
|
||||
textarea.dataset.enhanced = true;
|
||||
}
|
||||
}
|
||||
|
||||
const textarea_enhancement_observer = new MutationObserver(enhance_textareas);
|
||||
textarea_enhancement_observer.observe(document, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue