From 312f22adb4963a74146f00553c28d89508c28ea1 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 28 Oct 2021 18:38:36 +0200 Subject: [PATCH 2/4] js: launch autosave on tab change (#58276) --- wcs/qommon/static/js/qommon.forms.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wcs/qommon/static/js/qommon.forms.js b/wcs/qommon/static/js/qommon.forms.js index dab59b486..5df9d9887 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -165,6 +165,20 @@ $(function() { } }); + $(window).on('pagehide', function () { + if (autosave_timeout_id !== null && ! $('body').hasClass('autosaving')) { + window.clearTimeout(autosave_timeout_id); + autosave(); + } + }); + + $(document).on('visibilitychange', function () { + if (document.visibilityState == 'hidden' && autosave_timeout_id !== null && ! $('body').hasClass('autosaving')) { + window.clearTimeout(autosave_timeout_id); + autosave(); + } + }); + install_autosave(); $('#tracking-code a').on('click', autosave); -- 2.34.1