mirror of
https://github.com/indentlabs/notebook.git
synced 2025-10-26 11:19:22 +00:00
work around browser triggering onblur with remote form submissions (oof)
This commit is contained in:
parent
7cc3b07087
commit
bec2b4d52e
@ -1,4 +1,6 @@
|
||||
$(document).ready(function() {
|
||||
var recent_autosave = false;
|
||||
|
||||
$('.autosave-closest-form-on-change').change(function () {
|
||||
var content_form = $(this).closest('form');
|
||||
|
||||
@ -6,7 +8,10 @@ $(document).ready(function() {
|
||||
if (content_form) {
|
||||
// M.toast({ html: 'Saving changes...' });
|
||||
console.log('saving changes');
|
||||
content_form.submit();
|
||||
recent_autosave = true;
|
||||
content_form.trigger('submit');
|
||||
|
||||
setTimeout(() => recent_autosave = true, 1000);
|
||||
} else {
|
||||
console.log('error saving changes');
|
||||
// M.toast({ html: "There was an error saving your changes. Please back up any changes and refresh the page." });
|
||||
@ -23,6 +28,8 @@ $(document).ready(function() {
|
||||
// To ensure all fields get unblurred (and therefore autosaved) upon navigation,
|
||||
// we use this little ditty:
|
||||
window.onbeforeunload = function(e){
|
||||
$(document.activeElement).blur();
|
||||
if (!recent_autosave) {
|
||||
$(document.activeElement).blur();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user