summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2020-10-23 10:24:49 +0000
committerqsm-odoo <qsm@odoo.com>2020-10-23 15:07:07 +0000
commit8a949019fd39c6c07ae5827462ee96e15f3190a1 (patch)
tree1bcde180a4bed48975b4effeeb9377d8eead8d33 /addons/web_editor/static/src
parentf486e61c36cb39b7b79faf018f5b8ac0448e284c (diff)
[FIX] web_editor: do not show overlay for invisible elements
When a snippet is out of the viewport or hidden, the overlay should not be visible. Two distinct cases we had: - When the page is scrolled, the header is sometimes hidden thanks to tranform: translate(0, -100%); for some kind of effect -> the header is thus still visible but out of the viewport, any selected snippet inside that header would still have this overlay enabled so we would see the move and delete button on the top of the screen. - When the page is scrolled, with the vertical header, some part of the header are hidden for the affixed version. If any snippet in those hidden elements was selected, the overlay is still visible floating. task-2312878 closes odoo/odoo#58383 Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com> Co-authored-by: Benjamin Vray <bvr@odoo.com> Co-authored-by: Thanh Dodeur <tso@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.editor.js35
1 files changed, 34 insertions, 1 deletions
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 ee1bf923902..ea9b0a8e64f 100644
--- a/addons/web_editor/static/src/js/editor/snippets.editor.js
+++ b/addons/web_editor/static/src/js/editor/snippets.editor.js
@@ -206,11 +206,38 @@ var SnippetEditor = Widget.extend({
* Makes the editor overlay cover the associated snippet.
*/
cover: function () {
- if (!this.isShown() || !this.$target.length || !this.$target.is(':visible')) {
+ if (!this.isShown() || !this.$target.length) {
return;
}
+
const $modal = this.$target.find('.modal');
const $target = $modal.length ? $modal : this.$target;
+ const targetEl = $target[0];
+
+ // Check first if the target is still visible, otherwise we have to
+ // hide it. When covering all element after scroll for instance it may
+ // have been hidden (part of an affixed header for example) or it may
+ // be outside of the viewport (the whole header during an effect for
+ // example).
+ const rect = targetEl.getBoundingClientRect();
+ const vpWidth = window.innerWidth || document.documentElement.clientWidth;
+ const vpHeight = window.innerHeight || document.documentElement.clientHeight;
+ const isInViewport = (
+ rect.bottom > -0.1 &&
+ rect.right > -0.1 &&
+ (vpHeight - rect.top) > -0.1 &&
+ (vpWidth - rect.left) > -0.1
+ );
+ const hasSize = ( // :visible not enough for images
+ Math.abs(rect.bottom - rect.top) > 0.01 &&
+ Math.abs(rect.right - rect.left) > 0.01
+ );
+ if (!isInViewport || !hasSize || !this.$target.is(`:visible`)) {
+ this.toggleOverlayVisibility(false);
+ return;
+ }
+
+ // Now cover the element
const offset = $target.offset();
var manipulatorOffset = this.$el.parent().offset();
offset.top -= manipulatorOffset.top;
@@ -1009,13 +1036,19 @@ var SnippetsMenu = Widget.extend({
// On keydown add a class on the active overlay to hide it and show it
// again when the mouse moves
this.$document.on('keydown.snippets_menu', () => {
+ this.__overlayKeyWasDown = true;
this.snippetEditors.forEach(editor => {
editor.toggleOverlayVisibility(false);
});
});
this.$document.on('mousemove.snippets_menu, mousedown.snippets_menu', _.throttle(() => {
+ if (!this.__overlayKeyWasDown) {
+ return;
+ }
+ this.__overlayKeyWasDown = false;
this.snippetEditors.forEach(editor => {
editor.toggleOverlayVisibility(true);
+ editor.cover();
});
}, 250));