//Pop-it menu- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
//set the action to handle the contextmenu
function oncontextmenu(event)
{
event.cancelBubble = true;
event.returnValue = false;
this.action("contextmenu");
}
// assign the event handler to the cell template prototype
Active.Templates.Text.prototype.setEvent("oncontextmenu", oncontextmenu);
// create action handler for the right click context menu
grid.setAction("contextmenu", function(src){ showmenu(event,getMenuHeader()+menu);return false;});
obj.setEvent('click', function(){showmenu(event, menu);});
div.contextmenu {
background-color: #d0d0d0;
border: 2px solid;
border-color: #f0f0f0 #909090 #909090 #f0f0f0;
left: 0px;
padding: 0px 1px 1px 0px;
position: absolute;
top: 0px;
visibility: hidden;
z-index: 600;
}
div.contextmenu a.menuItem {
color: #000000;
cursor: default;
display: block;
padding: 3px 1em;
text-decoration: none;
white-space: nowrap;
}
div.contextmenu a.menuItem:hover, div.menu a.menuItemHighlight {
background-color: #000080;
color: #ffffff;
}
div.contextmenu div.menuItemSep {
border-top: 1px solid #909090;
border-bottom: 1px solid #f0f0f0;
margin: 4px 2px;
}
// set contextmenu action handler
var row = new Active.Templates.Row;
row.setEvent("oncontextmenu", function(){this.action("contextmenu")});
obj.setAction("contextmenu", function(src){
obj.setProperty("selection/index",src.getProperty("item/index"));
writeContextMenu(myData[src.getProperty("item/index")]['0']);
showContextMenu(event);
}
);
function initContextMenu() {
document.write('<div id="contextmenu" class="contextmenu"></div>');
}
function writeContextMenu(itemId) {
var contextMenu = document.getElementById("contextmenu");
contextMenu.innerHTML = '<a class="menuItem" href="?action=edit&id=' + itemId + '"><strong>Edit</strong></a>';
contextMenu.innerHTML += '<a class="menuItem" href="?action=clone&id=' + itemId + '">Clone</a>';
contextMenu.innerHTML += '<div class="menuItemSep"></div>';
contextMenu.innerHTML += '<a class="menuItem" href="?action=remove&id=' + itemId + '">Remove</a>';
}
function showContextMenu(e) {
document.getElementById("contextmenu").style.left = e.clientX + "px";
document.getElementById("contextmenu").style.top = e.clientY + "px";
document.getElementById("contextmenu").style.visibility = "visible";
}
function hideContextMenu() {
document.getElementById("contextmenu").style.visibility = "hidden";
}
initContextMenu();
document.onclick = hideContextMenu;
function showContextMenu(e) {
var contextMenu = document.getElementById("contextmenu");
if ((window.innerWidth - e.clientX) < contextMenu.offsetWidth) {
contextMenu.style.left = (window.pageXOffset + e.clientX - contextMenu.offsetWidth) + "px";
} else {
contextMenu.style.left = e.clientX + "px";
}
if ((window.innerHeight - e.clientY) < contextMenu.offsetHeight) {
contextMenu.style.top = (window.pageYOffset + e.clientY - menuobj.offsetHeight) + "px";
} else {
contextMenu.style.top = e.clientY + "px";
}
contextMenu.style.visibility = "visible";
}
<html>
<head>
<script src="/ActiveWidgets/runtime/lib/aw.js"></script>
<link href="/ActiveWidgets/runtime/styles/aqua/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>
#contextmenu {
background-color: #c0c0c0;
border: 2px solid;
border-color: #f0f0f0 #909090 #909090 #f0f0f0;
left: 0px;
padding: 3px 3px 3px 3px;
position: absolute;
top: 0px;
visibility: hidden;
z-index: 600;
}
#contextmenu a.menuItem {
color: #000000;
cursor: default;
display: block;
padding: 3px 1em;
text-decoration: none;
white-space: nowrap;
}
#contextmenu a.menuItem:hover, div.menu a.menuItemHighlight {
background-color: #000080;
color: #ffffff;
}
#contextmenu div.menuItemSep {
border-top: 1px solid #909090;
border-bottom: 1px solid #f0f0f0;
margin: 4px 2px;
}
</style>
<script>
var grid1 = new AW.UI.Grid;
grid1.setId("grid1");
grid1.setCellText("cell");
grid1.setHeaderText("header");
grid1.setColumnCount(5);
grid1.setRowCount(10);
function get_height() {
var y = 5;
if (self.innerHeight) // all except Explorer
y = self.innerHeight;
else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
y = document.documentElement.clientHeight;
else if (document.body) // other Explorers
y = document.body.clientHeight;
return y;
}
// assign html event handler to row template
grid1.getCellTemplate().setEvent("oncontextmenu", function () {
var col = this.$0;
var row = this.$1;
grid1.setSelectedRows([row]);
grid1.setCurrentRow(row);
this.raiseEvent("onCellContextMenu", event, row, col);
});
var contextmenu = new AW.HTML.DIV;
contextmenu.setId('contextmenu');
document.write(contextmenu);
grid1.onCellContextMenu = function(event, col, row){
var menu;
menu = 'Incident #: <strong>' + grid1.getCellValue(0,row) + '</strong>';
menu += '<div class="menuItemSep"></div>';
menu += '<a class="menuItem" href=\\'javascript: alert("AW Is Fun!");\\'>Active Widgets</a>';
contextmenu.element().innerHTML = menu;
var h = get_height();
var menu_size = '280';
contextmenu.setStyle('left', event.clientX + "px");
if (event.clientY > h - menu_size)
contextmenu.setStyle('top', (h - menu_size) + "px");
else
contextmenu.setStyle('top', event.clientY + "px");
contextmenu.setStyle("visibility", "visible");
}
document.onclick = function() {
contextmenu.setStyle("visibility", "hidden");
};
document.write(grid1);
</script>
</body>
</html>
grid1.getCellTemplate().setEvent("oncontextmenu", function () {
var col = this.$0;
var row = this.$1;
if (col != 0) { return false; } // <b>set this value to whatever column you want to display the menu</b>
grid1.setSelectedRows([row]);
grid1.setCurrentRow(row);
this.raiseEvent("onCellContextMenu", event, row, col);
});
This topic is archived.