mirror of
https://github.com/friendica/friendica
synced 2024-11-18 02:23:40 +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,33 +127,54 @@
|
||||||
// Set initial height
|
// Set initial height
|
||||||
textarea.style.height = "auto";
|
textarea.style.height = "auto";
|
||||||
textarea.style.height = (textarea.scrollHeight) + "px";
|
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";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function togglePermissions() {
|
// Auto-save content to localStorage every 5 seconds
|
||||||
var permissionsSection = document.getElementById('permissions-section');
|
setInterval(() => {
|
||||||
if (permissionsSection.style.display === 'none' || permissionsSection.style.display === '') {
|
var textareas = document.querySelectorAll(".expandable-textarea");
|
||||||
permissionsSection.style.display = 'block';
|
textareas.forEach(function(textarea) {
|
||||||
} else {
|
localStorage.setItem(`comment-edit-text-${textarea.id}`, textarea.value);
|
||||||
permissionsSection.style.display = 'none';
|
});
|
||||||
}
|
}, 5000);
|
||||||
}
|
|
||||||
|
|
||||||
// Warn the user before leaving the page
|
function togglePermissions() {
|
||||||
var formSubmitting = false;
|
var permissionsSection = document.getElementById('permissions-section');
|
||||||
|
if (permissionsSection.style.display === 'none' || permissionsSection.style.display === '') {
|
||||||
|
permissionsSection.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
permissionsSection.style.display = 'none';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setFormSubmitting() {
|
// Warn the user before leaving the page
|
||||||
formSubmitting = true;
|
var formSubmitting = false;
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener("beforeunload", function (event) {
|
function setFormSubmitting() {
|
||||||
if (!formSubmitting) {
|
formSubmitting = true;
|
||||||
var confirmationMessage = 'Are you sure you want to reload the page? All unsaved changes will be lost.';
|
// Remove saved content from localStorage when form is submitted
|
||||||
event.returnValue = confirmationMessage;
|
var textareas = document.querySelectorAll(".expandable-textarea");
|
||||||
return confirmationMessage;
|
textareas.forEach(function(textarea) {
|
||||||
}
|
localStorage.removeItem(`comment-edit-text-${textarea.id}`);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Set the formSubmitting flag when the form is submitted
|
window.addEventListener("beforeunload", function (event) {
|
||||||
document.getElementById('comment-edit-form-{{$id}}').addEventListener('submit', setFormSubmitting);
|
if (!formSubmitting) {
|
||||||
|
var confirmationMessage = 'Are you sure you want to reload the page? All unsaved changes will be lost.';
|
||||||
|
event.returnValue = confirmationMessage;
|
||||||
|
return confirmationMessage;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the formSubmitting flag when the form is submitted
|
||||||
|
document.getElementById('comment-edit-form-{{$id}}').addEventListener('submit', setFormSubmitting);
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue