From c3bff57df2142e8bc70f98f4281419dac7bf4bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Mon, 15 Nov 2021 10:51:25 +0000 Subject: [PATCH] [FIX] web_editor: avoid onbeforeunload pop-up issue Remove onbeforeunload pop-up if editor has no snippet. This fix pop-ups wrongly showing outside website editing. see: #79731 task-2666177 closes odoo/odoo#79781 X-original-commit: 2f587eea4eea947597f0c4f7e5473c08e2175bcd Signed-off-by: Antoine Guenet --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 187c483b610..361efb76682 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -206,16 +206,17 @@ const Wysiwyg = Widget.extend({ selectorEditableArea: '.o_editable', }, options)); await this._insertSnippetMenu(); + + window.addEventListener('beforeunload', (event) => { + if (this.isDirty()) { + event.returnValue = _t('This document is not saved!'); + } + }); } if (this.options.getContentEditableAreas) { $(this.options.getContentEditableAreas()).find('*').off('mousedown mouseup click'); } - window.onbeforeunload = (event) => { - if (this.isDirty()) { - return _t('This document is not saved!'); - } - }; // The toolbar must be configured after the snippetMenu is loaded // because if snippetMenu is loaded in an iframe, binding of the color // buttons must use the jquery loaded in that iframe. See