简体   繁体   中英

Disabling jQuery Contextmenu's items

First of all, thanks for all the helps on my previous questions. Well my question involves jQuery contextmenus. I have a context menu which is working perfectly showing all different options, however, I need to disable a few options (Lets say Item B in code below) and I am failing to do that. Here is how the code is,

I have an array called menuitems which holds all the elements of the contextmenu, eg,

function createMenuItems() {
    var menuitems = {};
    menuitems['Item A'] = {
        click: function() {
            // Some Code
        }
    };
    menuitems['Item B'] = {
        click: function() {
            // Some Code
        }
    };
    menuitems['Item C'] = {
        click: function() {
            // Some Code
        }
    };

    return menuitems;
}

This function is called in the following manner,

menuitems = createMenuItems();

Now the context menu is being created using the following command,

element.children("a").contextMenu("myMenu",menuitems,
    {
        disable_native_context_menu: true
    });

Any help will be highly appreciated, Thanks a lot and looking forward to your expert advices

Kind Regards

It looks that you are using http://code.google.com/p/youpivot/source/browse/trunk/chromeextension/include/jquery.contextmenu.js?r=46

As far as I can judge from the source code, there is no support for "disabled". You can try though and add it yourself, eg:

menuitems['Item B'] = {
    click: function() {
        // Some Code
    },
    disabled: true
};

And then in the plugin file add this:

if (item_options.disabled)
    menuItem.attr("disabled", "disabled");

after line 39 in the source provided by the link (I assume your file might differ from that so you can just find the similar place).

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM