From 6c1282af8ed06c3d12972d2f95b5e2a636ad40de Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 27 Jun 2018 16:46:16 +0200
Subject: [PATCH] when clicking close to right border menu doesn't exceed
 window

---
 frontend-js/src/main/js/gui/ContextMenu.js | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/frontend-js/src/main/js/gui/ContextMenu.js b/frontend-js/src/main/js/gui/ContextMenu.js
index fd810331d0..65573410e5 100644
--- a/frontend-js/src/main/js/gui/ContextMenu.js
+++ b/frontend-js/src/main/js/gui/ContextMenu.js
@@ -10,6 +10,8 @@ var Functions = require('../Functions');
 
 var logger = require('../logger');
 
+var MARGIN = 5;
+
 function ContextMenu(params) {
   AbstractGuiElement.call(this, params);
   var self = this;
@@ -79,9 +81,18 @@ ContextMenu.prototype.open = function (x, y, timestamp) {
   var self = this;
   self._handledTimeStamp = timestamp;
 
+  var left = x;
+  var right = "";
+
+  if ($(self.getElement()).width() + x + MARGIN > $(document).width()) {
+    left = Math.max(0, $(document).width() - $(self.getElement()).width() - MARGIN);
+    right = 0;
+  }
+
   $(self.getElement()).show().css({
     position: "absolute",
-    left: x,
+    left: left,
+    right: right,
     top: y
   }).off('click').on('click', 'a', function (e) {
     //close if this is not a submenu
-- 
GitLab