Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

item.callback not triggered when item.disabled callback returns false. #2

Closed
dcoder2099 opened this issue Jul 22, 2011 · 4 comments
Closed

Comments

@dcoder2099
Copy link

If an item declares a callback function for its 'disabled' property, when that callback returns false, the subsequent item.callback is not called.

The Demo at http://medialize.github.com/jQuery-contextMenu/demo.html shows this behavior.

To reproduce, load the Demo page and in "menu 2" of the first demo, attempt to select the Golf menu item, which is not disabled. The item's callback (alert_click) is never fired.

@dcoder2099
Copy link
Author

(note, when I originally logged this issue, I mis-stated that the behavior occurs when item.disabled returns true. That was an error in describing the problem on my part. The issue does exist as is evident by the steps to reproduce I outline.

@dcoder2099
Copy link
Author

Looks like the issue is with line 528 of jquery.contextMenu.js... in the case when opt.items[key].disabled is not a simple property but rather a callback function, that second parameter to the if condition returns true (because it is true that .disabled is there -- it is a function declaration. If I get a chance, I'll work this up in a fork and submit a pull request.

@dcoder2099
Copy link
Author

In case I never get around to that:

diff --git a/jquery.contextMenu.js b/jquery.contextMenu.js
index 759bf68..48d0821 100755
--- a/jquery.contextMenu.js
+++ b/jquery.contextMenu.js
@@ -520,12 +520,13 @@ var // currently active contextMenu trigger
                itemClick: function(e) {
                        var $this = $(this),
                                data = $this.data(),
+                               disabled = $this.hasClass('disabled'),
                                opt = data.contextMenu,
                                root = data.contextMenuRoot,
                                key = data.contextMenuKey;

                        // abort if the key is unknown or disabled
-                       if (!opt.items[key] || opt.items[key].disabled) {
+                       if (!opt.items[key] || disabled) {
                                return;
                        }

@rodneyrehm
Copy link
Contributor

Thanks, missed this at the initial rewrite. Fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants