Closed elgs closed 9 years ago
Like below?
<ANY context-menu="menuOptions" context-menu-before="beforeContextMenu(scopeValue)"></ANY>
$scope.beforeContextMenu = function (scopeValue) {
if (scopeValue == '') {
return false;
}
};
Very close to what I was thinking. May be like this:
<ANY context-menu="menuOptions" context-menu-before="beforeContextMenu"></ANY>
$scope.beforeContextMenu = function ($itemScope) {
// do whatever you like with the $itemScope, if you don't want the menu to show, return a false;
};
Couldn't I just make menuOptions optionally allow a function instead and you simply return an empty array for no context-menu?
<ANY context-menu="menuOptions" ></ANY>
$scope.menuOptions = function () {
// maybe return some custom menu options on click.
return [];
};
Well, I have two goals: 1, to have a chance to do something before the menu is shown, that's important to me; 2, to decide to show the menu or not based on which item is right click on, that's just nice to have to me;
Changing menuOptions
from array to function will perfectly satisfy my first goal, which is important to me. However, it doesn't help with the second goal. So I'm totally ok with changing menuOptions
to a function.
Uhh... you can definitely tell which one was clicked.
<ANY ng-repeat="item in items">
<ANY context-menu="menuOptions(item)" ></ANY>
</ANY>
$scope.menuOptions = function (item) {
if (item == 'foo') {
// maybe return some custom menu options on click.
}
return [];
};
Aha, awesome!
Yes, that will be perfect! Thank you.
This already works in the current version... I just never documented it.
I'll take a minute and document soon. Ha.
Oh wait, it doesn't handle 0 items. Fixing that now.
Okay, fixed. Question, should it show the default context menu or still prevent the context menu?
Example: http://jsfiddle.net/c6gba904/
This was added in v0.9.2
.
Thank you so much for adding/documenting this feature. This feature will help me to handle item selection when user right clicks on an item.
I actually have no idea whether to show or prevent the default context menu.
I've updated the docs with an example. Yea, I think just out right preventing always makes more sense since 99% of the time these will be used in list. Showing the default context menu would be very confusing.
Agreed. Thank you @Templarian. I appreciate your awesome project and fast response to my questions.
I'm hoping there will be an event hook callback just before the context menu is shown. If the event hook returns true (default), the context menu will be shown normally, otherwise, it will do nothing. What I need to do is to do some item selection things before the context menu is shown. So I think adding an event hook will be helpful.