我的JS TreeView树(三)----ctxmenu on treeNode

/*实现drawNode.js的方法,加上右键功能*/
function mousedown(nodeCode){
   if (event.button == 2){
      setColor(nodeCode);
      showMenu(nodeCode);
      document.οncοntextmenu=function(){return false;}
   }else if (event.button == 1){
      clickNode(nodeCode);
      hiddenMenu();
   }
}
document.οnclick=function(){
   hiddenMenu();
}
----------------右键菜单contextMenu.js------------------------------------------------------------------
var tree_cxtmenu = document.createElement("div");
tree_cxtmenu.id="ctxmenu";
tree_cxtmenu.onmouseup = function() { event.cancelBubble=true;}
document.body.appendChild(tree_cxtmenu);

addItem(" 新增","addNode.jsf");
addItem(" 删除","updateNode.jsf");
addItem(" 修改","deleteNode.jsf");

function addItem(text,href) {
    var item = document.createElement("div");
    tree_cxtmenu.appendChild(item);
    item.innerHTML = text;
    item.onmouseup = function(){
        hiddenMenu();
        var folder = getFolderByCode(tree_cxtmenu.nodeCode);
        var url = href + "?nodeId="+folder.code+"&nodeName="+folder.desc;
        var feacture = "top=100,left=150,width=600,height=200,status=1";
        window.open(url, "newWin", feacture);
    }
    item.onmouseover = function() { mouseoverState(this)}
    item.onmouseout = function() { mouseoutState(this)}
    item.className="ctxmenu-item";
}

function mouseoverState(obj) {
    obj.className = "ctxmenu-over";
}
function mouseoutState(obj) {
    obj.className = "ctxmenu-item";
}
//addLine
function addLine() {
    line = document.createElement("div")
    line.className = "line";
    tree_cxtmenu.appendChild(line);
}

function showMenu() { //argument:nodeCode
    var bodyWidth = document.body.clientWidth+document.body.clientLeft;
    var bodyHeight = document.body.clientHeight+document.body.clientTop;
    with(tree_cxtmenu.style) {
        visibility="visible";
        if (event.clientX+tree_cxtmenu.offsetWidth > bodyWidth)
            pixelLeft = bodyWidth - tree_cxtmenu.offsetWidth-5;
        else
            pixelLeft = event.x;
        if (event.clientY+tree_cxtmenu.offsetHeight > bodyHeight)
            pixelTop = tree_cxtmenu.y-5 - tree_cxtmenu.offsetHeight;
        else
            pixelTop = event.y;
    }
    tree_cxtmenu.nodeCode = arguments[0];
}
function hiddenMenu() {
    with(tree_cxtmenu.style) {
        visibility="hidden";
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值