From 8c4a00a1aaa29b252b0aaeda35921455ca62a9af Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 28 Oct 2021 18:38:36 +0200 Subject: [PATCH 3/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 219c0d87..573f203f 100644 --- a/wcs/qommon/static/js/qommon.forms.js +++ b/wcs/qommon/static/js/qommon.forms.js @@ -167,6 +167,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