2022-03-31 12:07:52 +02:00
|
|
|
import { scrollTo, scrollToBottom } from '@utils';
|
2018-08-09 11:53:59 +02:00
|
|
|
|
2020-10-06 17:10:34 +02:00
|
|
|
function scrollMessagerie() {
|
2018-10-09 11:43:38 +02:00
|
|
|
const ul = document.querySelector('.messagerie ul');
|
2018-07-12 11:50:47 +02:00
|
|
|
|
2018-10-09 11:43:38 +02:00
|
|
|
if (ul) {
|
|
|
|
const elementToScroll = document.querySelector('.date.highlighted');
|
2018-07-12 11:50:47 +02:00
|
|
|
|
2018-10-09 11:43:38 +02:00
|
|
|
if (elementToScroll) {
|
2022-03-31 12:07:52 +02:00
|
|
|
scrollTo(ul, elementToScroll);
|
2018-07-12 11:50:47 +02:00
|
|
|
} else {
|
2018-10-09 11:43:38 +02:00
|
|
|
scrollToBottom(ul);
|
2018-07-12 11:50:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 11:11:01 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:22:37 +02:00
|
|
|
addEventListener('ds:page:update', scrollMessagerie);
|
2021-08-17 11:11:01 +02:00
|
|
|
addEventListener('ds:page:update', saveMessageContent);
|