Hi there,

Please save the life of those few hairs left on my skull. I've been
trying to understand why this doesn't work:

i'm using the jquery Context Menu
(http://abeautifulsite.net/notebook/80 ) to display a context menu
which options vary according to each item.

So i'm using a "data" custom attribute to store which options should
be active and the metadata plugin to retrieve the values. Works fine.

Now, i need to disable context menu options according to the fetched
data, but there, the functionality advertised on the plugin website
does not seem to work for me.
It is this part of the code which fails:

// THE PLUGIN CODE BIT
 // Disable context menu items on the fly
        disableContextMenuItems: function(o)
        {
            if (o == undefined)
            {
                // Disable all
                $(this).find('li').addClass('disabled');
                return ($(this));
            }
            $(this).each(function()
            {
                if (o != undefined)
                {
                    var d = o.split(',');
                    for (var i = 0; i < d.length; i++)
                    {

                        console.log('plugin is disabling option : ' +
d[i]); // RETURNS A VALID ANSWER
                        $(this).find('a[href="' + d[i] +
'"]').parent().addClass('disabled');  // THE SELECTOR RETURNS 0
ELEMENTS, ALTHOUGH THE MARKUP IS CORRECT.
                    }
                }
            });
            return ($(this));
        },


// MY SCRIPT
// it creates the contextMenu and disables for each file, the relevant options
$("a.folderLink").each(function()
    {
        var thisFolder = $(this);
        thisFolder.contextMenu({ menu: 'contextMenu' },
        function(action, el, pos)
        {
            var url = $(el).attr('href');
            var directoryItem = $(el).attr('id');
            alert('url : ' + $(el).attr('href') + '\nAction: ' +
action + '  \nElement ID: ' + directoryItem);

        });
        // disable non allowed options
        var menuOptions = thisFolder.metadata({ type: 'attr', name: 'data' });
        var optionsToDisable = [];
        for (var my_option in menuOptions)
        {
            if (menuOptions.my_option == '0' || menuOptions.my_option
== null || typeof menuOptions.my_option === 'undefined')
            {
                optionsToDisable.push('#' + my_option);
            }
        }
        if (optionsToDisable.length > 0)
        {
            optionsToDisable = optionsToDisable.join(',');
            //optionsToDisable = "'" + optionsToDisable + "'";
            console.log("optionsToDisable = " + optionsToDisable);
            thisFolder.disableContextMenuItems(optionsToDisable);
        }
        thisFolder.disableContextMenuItems();
    });


So that's it: the issue is with the find() call, which does not find
an element that is there in the markup.

Reply via email to