From 7a544b862db2114becdb050f7785ef2b055bac92 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Thu, 4 Jan 2018 22:55:54 +0100 Subject: [PATCH] editor: context menu: unfocus non-submenu item on mouseout --- src/browser/js/app/editor/context-menu.js | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/browser/js/app/editor/context-menu.js b/src/browser/js/app/editor/context-menu.js index 4fefec06..56461df9 100644 --- a/src/browser/js/app/editor/context-menu.js +++ b/src/browser/js/app/editor/context-menu.js @@ -12,14 +12,6 @@ class ContextMenu { var menu = $('
') - if (!parent) { - this.menu = menu - menu.css({ - top: e.pageY + 'px', - left: e.pageX + 'px' - }) - } - for (let label in actions) { if (typeof actions[label] == 'object') { @@ -41,22 +33,32 @@ class ContextMenu { } - menu.appendTo(parent || this.root) + if (parent) menu.appendTo(parent) if (!parent) { + this.menu = menu + + menu.appendTo(this.root) + menu.find('.item').hover(function(){ $(this).siblings().removeClass('focus').find('.focus').removeClass('focus') $(this).addClass('focus') + }, function(){ + if (!$(this).hasClass('has-sub')) $(this).removeClass('focus') + }) + + menu.css({ + top: e.pageY + 'px', + left: e.pageX + 'px' }) this.correctPosition(menu) + menu.find('.context-menu').each((i, m)=>{ this.correctPosition($(m), $(m).parent()) }) - - } @@ -78,8 +80,8 @@ class ContextMenu { var pos = menu.offset(), width = menu.outerWidth(), height = menu.outerHeight(), - totalWidth = $('body').outerWidth(), - totalHeight = $('body').outerHeight(), + totalWidth = $(this.root).outerWidth(), + totalHeight = $(this.root).outerHeight(), leftAdjust = !parent ? 0 : parent.outerWidth() - 2 if (width + pos.left > totalWidth) {