bootstrap-contextmenu

Context menu plugin for Twitter's Bootstrap framework

  • 所有者: sydcanem/bootstrap-contextmenu
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Bootstrap Context Menu

#This project is unmaintained. Please use the alternative https://github.com/swisnl/jQuery-contextMenu.

I have an issue with the plugin but I would still like to use it.

-- Please fork the project and do your fixes.

Where can I get support if can't fix some issue?

-- You can check the issues page or pull request page if someone has a fix for your problem and merge it with your fork.

I still can't find fixes of my issues.

-- Get plenty of sleep. :)

A context menu extension of 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.

<div class="context" data-toggle="context" data-target="#context-menu"></div>

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.

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

Nice to have features:

  • Close and open animations
  • Keyboard shortcuts for menus

License

MIT

主要指標

概覽
名稱與所有者sydcanem/bootstrap-contextmenu
主編程語言HTML
編程語言JavaScript (語言數: 2)
平台
許可證
所有者活动
創建於2012-10-25 02:42:00
推送於2017-02-27 14:28:59
最后一次提交2016-02-09 07:57:25
發布數6
最新版本名稱0.3.4 (發布於 )
第一版名稱0.2.0 (發布於 )
用户参与
星數640
關注者數59
派生數191
提交數78
已啟用問題?
問題數70
打開的問題數18
拉請求數14
打開的拉請求數6
關閉的拉請求數20
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?