From 35881555346da3df3030906d3feccc46e91c692e Mon Sep 17 00:00:00 2001 From: Younn Olivier Date: Thu, 7 Apr 2022 21:54:54 +0200 Subject: [PATCH] [IMP] website, web_editor: add mobile preview See merge commit for more information. task-2687506 --- .../static/src/js/editor/snippets.editor.js | 5 +- .../website_preview/website_preview.scss | 40 ++++++++- .../website_preview/website_preview.xml | 20 ++--- .../wysiwyg_adapter/wysiwyg_adapter.js | 8 ++ .../static/src/services/website_service.js | 1 + .../src/systray_items/mobile_preview.js | 81 ++++--------------- .../src/systray_items/mobile_preview.xml | 8 ++ addons/website/views/snippets/snippets.xml | 3 + 8 files changed, 84 insertions(+), 82 deletions(-) create mode 100644 addons/website/static/src/systray_items/mobile_preview.xml diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 9c5495f09da..a324b4be5f3 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -1349,6 +1349,7 @@ var SnippetsMenu = Widget.extend({ }, 50); this.$window.on('resize.snippets_menu', debouncedCoverUpdate); this.$body.on('content_changed.snippets_menu', debouncedCoverUpdate); + $(this.$body[0].ownerDocument.defaultView).on('resize.snippets_menu', debouncedCoverUpdate); // On keydown add a class on the active overlay to hide it and show it // again when the mouse moves @@ -3390,8 +3391,8 @@ var SnippetsMenu = Widget.extend({ /** * Preview on mobile. */ - _onMobilePreviewClick: async function () { - throw new Error('implement me'); + _onMobilePreviewClick: function () { + this.trigger_up('request_mobile_preview'); }, /** * Undo.. diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.scss b/addons/website/static/src/client_actions/website_preview/website_preview.scss index 9222defd3ab..386833a6a0e 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.scss +++ b/addons/website/static/src/client_actions/website_preview/website_preview.scss @@ -1,3 +1,14 @@ +@mixin o-iframe-position($height) { + // TODO review this, this should not be needed as we want the iframe to + // be centered and potentially respect its aspect ratio whatever the size. + $width: $height * (9 / 16); + height: $height; + width: $width; + left: 50%; + top: 50%; + transform: translate(-50%, -50%); +} + .o_website_preview { position: relative; height: 100%; @@ -7,11 +18,32 @@ margin-right: $o-we-sidebar-width !important; } - > iframe { - @include o-position-absolute(0, 0, 0, 0); - width: 100%; + .o_iframe_container { + position: relative; height: 100%; - border: none; + width: 100%; + + iframe { + position: absolute; + border: none; + width: 100%; + height: 100%; + } + + &.o_is_mobile { + @include media-breakpoint-up(md) { + @include o-iframe-position(720px); + + @media(max-height: calc(720px + #{$o-navbar-height})) { + @include o-iframe-position(520px); + } + + iframe { + border-radius: 25px; + box-shadow: 0 0 3px rgba(0, 0, 0, 0.1); + } + } + } } } diff --git a/addons/website/static/src/client_actions/website_preview/website_preview.xml b/addons/website/static/src/client_actions/website_preview/website_preview.xml index ad4e3254506..bdcf03c57f2 100644 --- a/addons/website/static/src/client_actions/website_preview/website_preview.xml +++ b/addons/website/static/src/client_actions/website_preview/website_preview.xml @@ -2,16 +2,18 @@
-