Skip to content

Commit

Permalink
fix: add way to stop propagation when an item is clicked
Browse files Browse the repository at this point in the history
Closes #105
  • Loading branch information
josetaira committed Oct 1, 2017
1 parent bf7ec94 commit e441add
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,24 @@ angular.module('ui.bootstrap.contextMenu', [])
if($event.which == 1) {
$event.preventDefault();
$scope.$apply(function () {
$(event.currentTarget).removeClass('context');
removeAllContextMenus();

var cleanupFunction = function () {
$(event.currentTarget).removeClass('context');
removeAllContextMenus();
};
var clickFunction = angular.isFunction(item.click)
? item.click
: (angular.isFunction(item[1])
? item[1]
: null);

if (clickFunction) {
clickFunction.call($scope, $scope, event, modelValue, text, $li);
var res = clickFunction.call($scope, $scope, event, modelValue, text, $li);
if(res === undefined || res) {
cleanupFunction();
}
} else {
cleanupFunction();
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ angular.module('app', ['ui.bootstrap.contextMenu'])
alert('A new implementation based on objects');
}
},
{
text: 'Clicking this does not close the context menu',
click: function () {
// Returning false or any false-y value EXCEPT undefined will stop
// the context menu from closing.
return false;
}
},
{
text: 'Object-based with Submenu',
click: function() {
Expand Down

0 comments on commit e441add

Please sign in to comment.