bb0fe906a51bb04782f3d65bee5c8e33ab87ddd1
larrym
  Fri Apr 20 13:51:30 2012 -0700
fix problem where context menu disappeared off the top of the screen (#7687)
diff --git src/hg/js/jquery.contextmenu.js src/hg/js/jquery.contextmenu.js
index ed861f4..3200071 100644
--- src/hg/js/jquery.contextmenu.js
+++ src/hg/js/jquery.contextmenu.js
@@ -222,43 +222,46 @@
 				cmenu.shown=true;
 				$(document).one('click',null,function(){cmenu.hide()}); // Handle a single click to the document to hide the menu
                                     $(document).one('keyup', null, function(event){
                                     // hide menu when user presses the escape key
                                     // XXXX This doesn't work on the Mac (we never get any keyup events).
                                     if (event.keyCode == 27) {
                                         cmenu.hide();
                                     }
 				});
 			}
 		},
 		
 		// Find the position where the menu should appear, given an x,y of the click event
 		getPosition: function(clickX,clickY,cmenu,e) {
 			var x = clickX+cmenu.offsetX;
-			var y = clickY+cmenu.offsetY
+		        var y = clickY+cmenu.offsetY;
 			var h = $(cmenu.menu).height();
 			var w = $(cmenu.menu).width();
 			var dir = cmenu.direction;
 			if (cmenu.constrainToScreen) {
 				var $w = $(window);
 				var wh = $w.height();
 				var ww = $w.width();
 				if (dir=="down" && (y+h-$w.scrollTop() > wh)) { dir = "up"; }
 				var maxRight = x+w-$w.scrollLeft();
 				if (maxRight > ww) { x -= (maxRight-ww); }
 			}
-			if (dir=="up") { y -= h; }
+			if (dir=="up") {
+                            // use scrollTop to make sure menu doesn't disappear off the top (#7687).
+                            y = Math.max(y - h, $w.scrollTop());
+                        }
 			return {'x':x,'y':y};
 		},
 		
 		// Hide the menu, of course
 		hide: function() {
 			var cmenu=this;
 			if (cmenu.shown) {
 				if (cmenu.iframe) { $(cmenu.iframe).hide(); }
 				if (cmenu.menu) { cmenu.menu[cmenu.hideTransition](cmenu.hideSpeed,((cmenu.hideCallback)?function(){cmenu.hideCallback.call(cmenu);}:null)); }
 				if (cmenu.shadow) { cmenu.shadowObj[cmenu.hideTransition](cmenu.hideSpeed); }
 			}
 			cmenu.shown = false;
 		}
 	};