关闭

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

标签: treefunctiondivurl
1059人阅读 评论(0) 收藏 举报
分类:

/*实现drawNode.js的方法,加上右键功能*/
function mousedown(nodeCode){
   if (event.button == 2){
      setColor(nodeCode);
      showMenu(nodeCode);
      document.oncontextmenu=function(){return false;}
   }else if (event.button == 1){
      clickNode(nodeCode);
      hiddenMenu();
   }
}
document.onclick=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";
    }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    最新评论
    理财参考