From a08c90f8eab66f23c42b353c4237a650d2a30457 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 28 Oct 2021 18:38:36 +0200 Subject: [PATCH 4/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 c8f351b2..ad0088f0 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -172,6 +172,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.33.0