The Custom right-click menu (ContextMenu) and the suspended-layer tree are all the same in their implementations, adding nodes dynamically in the script, and then generating an absolute positioning layer, except that the right-click menu tree (ContextMenu) triggers a different event. Another right-click menu also needs to provide a dynamic Add menu item function to achieve right click different elements can display different right-click menu, I provide a "callback function", using the following code:
ContextMenu
var ContextMenu = new ContextMenu (..... {container:document.getElementById (' Treemenu ')});
Contextmenu.push (.....) {html: ' powered By:jonllen ', CSS Tutorial: ' Disabled '});
Contextmenu.push (.....) {html: ', CSS: ' line '};
Contextmenu.push (.....) {html: ' Refresh (<u>R</u>) ', href: ' JavaScript Tutorial: Location.reload (); '});
for (Var i=0;i<menu.length;i++) ... {
Contextmenu.push (.....) {
Id:menu[i].id,
Level:menu[i].level,
Parentid:menu[i].parentid,
Html:menu[i].name,
Href:menu[i].url
});
}
Contextmenu.render ();
Original callback function
var contextmenuonshow = contextmenu.onshow;
To set a new callback function
Contextmenu.onshow = function (target, _this) ... {
var item = Target.treemenu | | Target.parentNode.treemenu;
if (item) ... {
var html = ' Add ' +item.html+ ' "sub-node ' + (item.children.length+1) + '" ';
_this.push (.....) {
Html:html,
Click:function (e) ... {
Item.expand = false;
var newitem = ... {
Id:item.id + ' 0 ' + (item.children.length+1),
Level:item.level + 1,
ParentId:item.id,
html:item.html+ ' Sub-node ' + (item.children.length+1),
href: ' # ',
CSS: ' Item ',
Createexpand:true
};
Item.children.push (NewItem);
Treemenu.list.push (NewItem);
Treemenu.renderchild (item);
},
Clickclose:true,
Index:1,
Type: ' Dynamic '
});
_this.push (.....) {
HTML: ' Delete node ' ' +item.html+ ' ',
Click:function (e) ... {
if (Confirm (' Confirm Delete node ' +item.html+ ')? '))
Treemenu.remove (item);
},
Clickclose:true,
Index:2,
Type: ' Dynamic '
});
}
Contextmenuonshow (target, _this);
};