Make generic
This commit is contained in:
parent
cf0b3b4f74
commit
2a84f14521
6 changed files with 50 additions and 23 deletions
|
@ -14,4 +14,45 @@ function scrollMessagerie() {
|
|||
}
|
||||
}
|
||||
|
||||
function saveMessageContent() {
|
||||
const commentaireForms = Array.from(
|
||||
document.querySelectorAll('form[data-persisted-content-id]')
|
||||
);
|
||||
|
||||
if (commentaireForms.length) {
|
||||
const commentaireInputs = Array.from(
|
||||
document.querySelectorAll('.persisted-input')
|
||||
);
|
||||
|
||||
const persistedContentIds = commentaireForms.map(
|
||||
(form) => form.dataset.persistedContentId
|
||||
);
|
||||
|
||||
const keys = persistedContentIds.map((key) => `persisted-value-${key}`);
|
||||
|
||||
const object = commentaireInputs.map((input, index) => {
|
||||
return {
|
||||
input: input,
|
||||
form: commentaireForms[index],
|
||||
key: keys[index]
|
||||
};
|
||||
});
|
||||
|
||||
for (const el of object) {
|
||||
if (localStorage.getItem(el.key)) {
|
||||
el.input.value = localStorage.getItem(el.key);
|
||||
}
|
||||
|
||||
el.input.addEventListener('change', (event) => {
|
||||
localStorage.setItem(el.key, event.target.value);
|
||||
});
|
||||
|
||||
el.form.addEventListener('submit', () => {
|
||||
localStorage.removeItem(el.key);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addEventListener('ds:page:update', scrollMessagerie);
|
||||
addEventListener('ds:page:update', saveMessageContent);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue