From 51b1aacdd3dee9e35208e397755d808bf202719f Mon Sep 17 00:00:00 2001 From: Lars SG Date: Sat, 14 Nov 2020 20:08:18 -0700 Subject: [PATCH 1/2] Fix Leave site? warning when not required Before: Leave site? warning was triggered by onbeforeunload when saving the mailing draft or submitting the mailing and otherwise leaving the mailing (after the user had edited the design of the mailing). After: Leave site? warning is only triggered when leaving the mailing while editing the mailing design in Mosaico and not in the CiviCRM parts of the mailing editor. This change just checks if the Mosaico iframe is shown on the mailing editing page before triggering the Leave site? warning and does not trigger the warning if the iframe is not currently shown. --- templates/CRM/Mosaico/Page/EditorIframe.tpl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/templates/CRM/Mosaico/Page/EditorIframe.tpl b/templates/CRM/Mosaico/Page/EditorIframe.tpl index 4757ee6049..ea591676f9 100644 --- a/templates/CRM/Mosaico/Page/EditorIframe.tpl +++ b/templates/CRM/Mosaico/Page/EditorIframe.tpl @@ -24,11 +24,13 @@ var plugins = []; var config = {/literal}{$mosaicoConfig}{literal}; - - window.onbeforeunload = function(e) { - e.preventDefault(); - e.returnValue = "{/literal}{ts}Exit email composer without saving?{/ts}{literal}"; - }; + + window.addEventListener('beforeunload', function(e) { + if(window.parent.document.getElementsByTagName('iframe')[0].style.display !== "none") { + e.preventDefault(); + e.returnValue = "{/literal}{ts}Exit email composer without saving?{/ts}{literal}"; + } + }); if (window.top.crmMosaicoIframe) { window.top.crmMosaicoIframe(window, Mosaico, config, plugins); From b0afd1db24ba8ee74052559d6bfe8d18885841de Mon Sep 17 00:00:00 2001 From: Lars SG Date: Tue, 1 Dec 2020 17:38:57 -0700 Subject: [PATCH 2/2] Update templates/CRM/Mosaico/Page/EditorIframe.tpl Co-authored-by: colemanw --- templates/CRM/Mosaico/Page/EditorIframe.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/CRM/Mosaico/Page/EditorIframe.tpl b/templates/CRM/Mosaico/Page/EditorIframe.tpl index ea591676f9..6e8fd6c758 100644 --- a/templates/CRM/Mosaico/Page/EditorIframe.tpl +++ b/templates/CRM/Mosaico/Page/EditorIframe.tpl @@ -26,7 +26,7 @@ var config = {/literal}{$mosaicoConfig}{literal}; window.addEventListener('beforeunload', function(e) { - if(window.parent.document.getElementsByTagName('iframe')[0].style.display !== "none") { + if(window.parent.document.getElementById('crm-mosaico').style.display !== "none") { e.preventDefault(); e.returnValue = "{/literal}{ts}Exit email composer without saving?{/ts}{literal}"; }