mirror of
https://github.com/friendica/friendica
synced 2024-11-17 22:23:41 +00:00
Saving the post content using localstorage
If a post is created and the browser window crashes or the Composer window is hard-closed in some other way, all content is lost. Content is now saved temporarily so that it can be displayed again when the browser is restarted.
This commit is contained in:
parent
38ff423716
commit
9a224a8ca9
1 changed files with 43 additions and 22 deletions
|
@ -127,9 +127,25 @@
|
|||
// Set initial height
|
||||
textarea.style.height = "auto";
|
||||
textarea.style.height = (textarea.scrollHeight) + "px";
|
||||
|
||||
// Restore saved content
|
||||
const savedContent = localStorage.getItem(`comment-edit-text-${textarea.id}`);
|
||||
if (savedContent) {
|
||||
textarea.value = savedContent;
|
||||
textarea.style.height = "auto";
|
||||
textarea.style.height = (textarea.scrollHeight) + "px";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Auto-save content to localStorage every 5 seconds
|
||||
setInterval(() => {
|
||||
var textareas = document.querySelectorAll(".expandable-textarea");
|
||||
textareas.forEach(function(textarea) {
|
||||
localStorage.setItem(`comment-edit-text-${textarea.id}`, textarea.value);
|
||||
});
|
||||
}, 5000);
|
||||
|
||||
function togglePermissions() {
|
||||
var permissionsSection = document.getElementById('permissions-section');
|
||||
if (permissionsSection.style.display === 'none' || permissionsSection.style.display === '') {
|
||||
|
@ -144,6 +160,11 @@
|
|||
|
||||
function setFormSubmitting() {
|
||||
formSubmitting = true;
|
||||
// Remove saved content from localStorage when form is submitted
|
||||
var textareas = document.querySelectorAll(".expandable-textarea");
|
||||
textareas.forEach(function(textarea) {
|
||||
localStorage.removeItem(`comment-edit-text-${textarea.id}`);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", function (event) {
|
||||
|
|
Loading…
Reference in a new issue