加入收藏
举报
02-15 10:41
#0
文件名称:
README.md
所在目录:
分布式与云计算(大三下) / Raft讲解 (分布式课程报告) / raftscope-raft动画前端文件 / bootstrap-contextmenu
文件大小:
3.28 KB
下载地址:
FeijiangHan/CSU-CS-review-materials
   
免责声明:本网站仅提供指向 GitHub 上的文件的链接,所有文件的版权归原作者所有,本网站不对文件内容的合法性、准确性或安全性承担任何责任。
文本预览:
Bootstrap Context Menu
======================
A context menu extension of Twitter Bootstrap made for everyone's convenience.
See a [demo page] [id].
[id]:http://sydcanem.github.io/bootstrap-contextmenu/
Installation
------------
`bower install bootstrap-contextmenu`
Note: Requires bootstrap.css
Usage
-----
### Via data attributes
Add `data-toggle="context"` to any element that needs a custom context menu and via CSS set `position: relative` to the element.
Point `data-target` attribute to your custom context menu.
`
`
### Via Javascript
Call the context menu via JavaScript:
$('.context').contextmenu({
target:'#context-menu',
before: function(e,context) {
// execute code before context menu if shown
},
onItem: function(context,e) {
// execute on menu item selection
}
})
### Options
`target` - is the equivalent of the `data-target` attribute. It identifies the html of the menu that will be displayed.
`before` - is a function that is called before the context menu is displayed. If this function returns false, the context menu will not be displayed. It is passed two parameters,
- `e` - the original event. (You can do an `e.preventDefault()` to cancel the browser event).
- `context` - the DOM element where right click occured.
`onItem` - is a function that is called when a menu item is clicked. Useful when you want to execute a specific function when an item is clicked. It is passed two parameters,
- `context` - the DOM element where right click occured.
- `e` - the click event of the menu item, $(e.target) is the item element.
`scopes` - DOM selector for dynamically added context elements. See [issue](https://github.com/sydcanem/bootstrap-contextmenu/issues/56).
### Events
All events are fired at the context's menu. Check out `dropdown` plugin for
a complete description of events.
- `show.bs.context` - This event fires immediately when the menu is opened.
- `shown.bs.context` - This event is fired when the dropdown has been made visible to the user.
- `hide.bs.context` - This event is fired immediately when the hide instance method has been called.
- `hidden.bs.context` - This event is fired when the dropdown has finished being hidden from the user (will wait for CSS transitions, to complete).

Sample
$('#myMenu').on('show.bs.context',function () {
// do something...
});
Example
-------
Activate and specify selector for context menu
$('#main').contextmenu({'target':'#context-menu'});
Activate within a div, but not on spans
$('#main').contextmenu({
target: '#context-menu2',
before: function (e, element, target) {
e.preventDefault();
if (e.target.tagName == 'SPAN') {
e.preventDefault();
this.closemenu();
return false;
}
return true;
}
});
Modify the menu dynamically
$('#main').contextmenu({
target: "#myMenu",
before: function(e) {
this.getMenu().find("li").eq(2).find('a').html("This was dynamically changed");
}
});
Show menu name on selection
$('#main').contextmenu({
onItem: function(context, e) {
alert($(e.target).text());
}
});
### License
MIT
点赞 回复
回帖
支持markdown部分语法 ?