风上人的专栏

宠辱不惊,坐看庭前花开花落;去留无意,漫随天上云卷云舒。

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

/*实现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";
    }

阅读更多
文章标签: tree function div url
个人分类: WEB开发技巧
上一篇自己的一个线程同步通讯的实例
下一篇从DB2连接出错来认识WebServer的原理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭