diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index e8310f1314e..1d114394832 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -2645,29 +2645,6 @@ options.registry.CookiesBar = options.registry.SnippetPopup.extend({ $content.empty().append($template); }, - /** - * @override - */ - onTargetShow: async function () { - // @see this.onTargetHide - this.$target.parent('#website_cookies_bar').show(); - this._super(...arguments); - - }, - /** - * @override - */ - onTargetHide: async function () { - // We hide the parent because contenteditable="true" would force the bar to stay visible in hidden mode. - this.$target.parent('#website_cookies_bar').hide(); - this._super(...arguments); - }, - /** - * @override - */ - cleanForSave: function () { - this.$target.parent('#website_cookies_bar').show(); - }, }); /** diff --git a/addons/website/static/src/snippets/s_popup/000.js b/addons/website/static/src/snippets/s_popup/000.js index a0f5a27b787..42ea5f6e419 100644 --- a/addons/website/static/src/snippets/s_popup/000.js +++ b/addons/website/static/src/snippets/s_popup/000.js @@ -5,6 +5,58 @@ const config = require('web.config'); const publicWidget = require('web.public.widget'); const {getCookie, setCookie} = require('web.utils.cookies'); +// TODO In master, export this class too or merge it with PopupWidget +const SharedPopupWidget = publicWidget.Widget.extend({ + selector: '.s_popup', + disabledInEditableMode: false, + events: { + // A popup element is composed of a `.s_popup` parent containing the + // actual `.modal` BS modal. Our internal logic and events are hiding + // and showing this inner `.modal` modal element without considering its + // `.s_popup` parent. It means that when the `.modal` is hidden, its + // `.s_popup` parent is not touched and kept visible. + // It might look like it's not an issue as it would just be an empty + // element (its only child is hidden) but it leads to some issues as for + // instance on chrome this div will have a forced `height` due to its + // `contenteditable=true` attribute in edit mode. It will result in a + // ugly white bar. + // tl;dr: this is keeping those 2 elements visibility synchronized. + 'show.bs.modal': '_onModalShow', + 'hidden.bs.modal': '_onModalHidden', + }, + + /** + * @override + */ + destroy() { + this._super(...arguments); + + // Popup are always closed when entering/leaving edit mode (see + // PopupWidget), this allows to make sure the class is sync on the + // .s_popup parent after that moment too. + this.el.classList.add('d-none'); + }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * @private + */ + _onModalShow() { + this.el.classList.remove('d-none'); + }, + /** + * @private + */ + _onModalHidden() { + this.el.classList.add('d-none'); + }, +}); + +publicWidget.registry.SharedPopup = SharedPopupWidget; + const PopupWidget = publicWidget.Widget.extend({ selector: '.s_popup', events: { diff --git a/addons/website/views/snippets/s_popup.xml b/addons/website/views/snippets/s_popup.xml index 21e56020167..61493434643 100644 --- a/addons/website/views/snippets/s_popup.xml +++ b/addons/website/views/snippets/s_popup.xml @@ -2,6 +2,10 @@