diff --git a/README.md b/README.md index 314d6142..614345ea 100644 --- a/README.md +++ b/README.md @@ -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 } @@ -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, diff --git a/bootstrap-contextmenu.js b/bootstrap-contextmenu.js index dc1e38bc..de8850c8 100644 --- a/bootstrap-contextmenu.js +++ b/bootstrap-contextmenu.js @@ -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; @@ -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; @@ -100,6 +104,10 @@ return true; } + ,after: function(e) { + return true; + } + ,onItem: function(e) { return true; }