1

Below is an example from https://github.com/medialize/jQuery-contextMenu.

What I need to do is to put a function in the "selector:" that will use a bunch of logic to make the decision on an element candidacy.

Any suggestions?

$(function(){
    $.contextMenu({
        selector: '.context-menu-one', 
        callback: function(key, options) {
            var m = "clicked: " + key;
            window.console && console.log(m) || alert(m); 
        },
        items: {
            "edit": {name: "Edit", icon: "edit"},
            "cut": {name: "Cut", icon: "cut"},
            "copy": {name: "Copy", icon: "copy"},
            "paste": {name: "Paste", icon: "paste"},
            "delete": {name: "Delete", icon: "delete"},
            "sep1": "---------",
            "quit": {name: "Quit", icon: "quit"}
        }
    });

    $('.context-menu-one').on('click', function(e){
        console.log('clicked', this);
    })
});
2
  • 2
    how about determining element cadadicy before running $.contextMenu(), add a class to those elements that are valid, then use the appropriate selector in $.contextMenu()? Commented Aug 9, 2013 at 21:47
  • Good idea Populus! thanks Commented Aug 9, 2013 at 21:52

1 Answer 1

2

try that:

setContextMenu: function () {
    $.contextMenu({
        selector: '.dataTable tbody tr',
        build: function ($trigger, e) {
            // this callback is executed every time the menu is to be shown
            // its results are destroyed every time the menu is hidden
            // e is the original contextmenu event, containing e.pageX and e.pageY (amongst other data)
            return {
                callback: function (key, options) {
                    var obj = eval("(" + $(this).attr("valor") + ")");

                    if (key == "Editar") {
                        console
                    }

                    if (key == "Visualizar") {

                    }
                },
                items: {
                    "sep1": "---------",
                    "Editar": { name: "Editar", style: "ui-icon-document" },
                    "sep2": "---------",
                    "Visualizar": { name: "Visualizar", style: "ui-icon-closethick" },
                    "sep3": "---------",
                }
            };
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.