JavaScript Right-click menu tree Code

Source: Internet
Author: User

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);
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.