Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ $('.context').contextmenu({
before: function(e,context) {
// execute code before context menu if shown
},
after: function(e,context) {
// execute code after context menu is hidden
},
onItem: function(context,e) {
// execute on menu item selection
}
Expand All @@ -46,7 +49,12 @@ $('.context').contextmenu({

`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).
- `e` - the original event. (You can do an `e.preventDefault()` to cancel the browser event).
- `context` - the DOM element where right click occured.

`after` - is a function that is called when the context menu is going to be closed. If this function returns false, the context menu will not be closed. 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,
Expand Down
8 changes: 8 additions & 0 deletions bootstrap-contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
this.$element = $(element);

this.before = options.before || this.before;
this.after = options.after || this.after;
this.onItem = options.onItem || this.onItem;
this.scopes = options.scopes || null;

Expand Down Expand Up @@ -87,6 +88,9 @@

$('html')
.off('click.context.data-api', $menu.selector);

if (!this.after.call(this,e,$(e.currentTarget))) return;

// Don't propagate click event so other currently
// opened menus won't close.
return false;
Expand All @@ -100,6 +104,10 @@
return true;
}

,after: function(e) {
return true;
}

,onItem: function(e) {
return true;
}
Expand Down