Code: Select all
/* ================================================================================
showContextMenu() positions a menu widget at the current mouse position and
makes the menu visible.
*/
wob.showContextMenu = function(menuId, event)
{
var offsetX, offsetY; // define local variables
if (self.pageYOffset) // if scrolled, get page offset by browser
{
offsetX = self.pageXOffset;
offsetY = self.pageYOffset;
}
else if (document.documentElement
&& document.documentElement.scrollTop)
{
offsetX = document.documentElement.scrollLeft;
offsetY = document.documentElement.scrollTop;
}
else
{
offsetX = document.body.scrollLeft;
offsetY = document.body.scrollTop;
}
if (document.all) // add mouse offset to that, by browser
{
offsetX += event.clientX;
offsetY += event.clientY;
}
else
{
offsetX += event.pageX;
offsetY += event.pageY;
}
var bodyOffsets = document.body.getBoundingClientRect(); // if client rect. has been shifted...
offsetX -= bodyOffsets.left; // subtract client rect. shifted to right
offsetY -= bodyOffsets.top; // subtract client rect. shifted down
applyProperty(menuId, "left", (offsetX - 5) + "px"); // position the menu
applyProperty(menuId, "top", (offsetY - 5) + "px");
applyProperty(menuId, "z index", 100); // put menu on top of everything
applyProperty(menuId, "visibility", "visible"); // make menu visible
}