From 538e85c0809ad0bb135d40c52e4f1fb9a6acfc1d Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 28 Apr 2017 16:22:56 +0200 Subject: [PATCH] Fix the context menu in the drive flowing off the screen if too long --- www/drive/main.js | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/www/drive/main.js b/www/drive/main.js index 11911e06d..429cecb03 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -639,6 +639,36 @@ define([ updateContextButton(); }; + var displayMenu = function (e, $menu) { + $menu.css({ display: "block" }); + var h = $menu.outerHeight(); + var w = $menu.outerWidth(); + var wH = window.innerHeight; + var wW = window.innerWidth; + if (e.pageY + h <= wH) { + $menu.css({ + top: e.pageY+'px', + bottom: '' + }); + } else { + $menu.css({ + bottom: '0px', + top: '' + }); + } + if (e.pageX + w <= wW) { + $menu.css({ + left: e.pageX+'px', + right: '' + }); + } else { + $menu.css({ + left: '', + right: '0px', + }); + } + }; + // Open the selected context menu on the closest "li" element var openContextMenu = function (e, $menu) { module.hideMenu(); @@ -663,11 +693,7 @@ define([ $a.parent('li').hide(); }); - $menu.css({ - display: "block", - left: e.pageX, - top: e.pageY - }); + displayMenu(e, $menu); if ($menu.find('li:visible').length === 0) { debug("No visible element in the context menu. Abort."); @@ -729,11 +755,7 @@ define([ } }); - $menu.css({ - display: "block", - left: e.pageX, - top: e.pageY - }); + displayMenu(e, $menu); if ($menu.find('li:visible').length === 0) { debug("No visible element in the context menu. Abort.");