From 6f09515c20ece82798a366dafab5e62f4a0fe96d Mon Sep 17 00:00:00 2001 From: Tobias Reich Date: Fri, 31 Jan 2014 22:27:58 +0100 Subject: [PATCH] ContextMenu should never leave the screen again --- assets/js/modules/contextMenu.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/assets/js/modules/contextMenu.js b/assets/js/modules/contextMenu.js index 443eeb8..3a28927 100644 --- a/assets/js/modules/contextMenu.js +++ b/assets/js/modules/contextMenu.js @@ -21,11 +21,21 @@ contextMenu = { if ((mouse_x+$(".contextmenu").outerWidth(true))>$("html").width()) orientation = "left"; if ((mouse_y+$(".contextmenu").outerHeight(true))>$("html").height()) mouse_y -= (mouse_y+$(".contextmenu").outerHeight(true)-$("html").height()) + if (mouse_x>$(document).width()) mouse_x = $(document).width(); + if (mouse_x<0) mouse_x = 0; + if (mouse_y>$(document).height()) mouse_y = $(document).height(); + if (mouse_y<0) mouse_y = 0; + if (orientation==="left") mouse_x -= $(".contextmenu").outerWidth(true); - if (!mouse_x||!mouse_y) { - mouse_x = "10px"; - mouse_y = "10px"; + if (mouse_x===null|| + mouse_x===undefined|| + mouse_x===NaN|| + mouse_y===null|| + mouse_y===undefined|| + mouse_y===NaN) { + mouse_x = "10px"; + mouse_y = "10px"; } $(".contextmenu").css({ @@ -95,7 +105,7 @@ contextMenu = { mouse_y = e.pageY - $(document).scrollTop(), items; - if (albumID==="0"||albumID==="f"||albumID==="s") return false; + if (albumID==="0"||albumID==="f"||albumID==="s") return false; contextMenu.fns = [ function() { album.setTitle(albumID) },