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

How do I create the same menu for multiple items? #11

Open
rkostes opened this issue Feb 21, 2013 · 1 comment
Open

How do I create the same menu for multiple items? #11

rkostes opened this issue Feb 21, 2013 · 1 comment

Comments

@rkostes
Copy link

rkostes commented Feb 21, 2013

I am trying to create the same menu for all objects with a given name. I am using the menu from the readme just to get it to work. When I right click on an object I get the following error:

Message: Object doesn't support property or method 'forEach'
Line: 46
Char: 5
Code: 0
URI: http://localhost:8080/SWNOrderProcessingWeb/common/jquery.contextmenu.js

The obects with name='3' are all unordered list items.

$("[name^='3']").contextPopup({
    title: 'My Popup Menu',
    items: [
      {label:'Some Item',     icon:'icons/shopping-basket.png', action:function() { alert('clicked 1') } },
      {label:'Another Thing', icon:'icons/receipt-text.png',    action:function() { alert('clicked 2') } },
      null, /* null can be used to add a separator to the menu items */
      {label:'Blah Blah',     icon:'icons/book-open-list.png',  action:function() { alert('clicked 3') } },
    ]});
@Netas
Copy link

Netas commented Jul 16, 2013

Hello,
I made a little modifications and it worked for me:

jQuery(function() {
    function CustomMenu1(i) {
        var v = jQuery(i);
        v.contextPopup({
            items: [
                {label:'ID attribute',icon:'find.png',action:function() { alert(v.attr('id')); } },
                null,
                {label:'Rel attribute',icon:'truck.png',action:function() { alert(v.attr('rel')); } },
                {label:'Style attribute',icon:'paste.png',action:function() { alert(v.attr('style')); } },
                {label:'Inside text',icon:'edit.png',action:function() { alert(v.text()); } },
            ]
        });
    }
    jQuery('.boo').each(function(){
        CustomMenu1(this);
    });
});

<a class="boo" style="display:block;margin:10px 0px;" rel="vienas" id="1">sdf sdafdsf </a>
<a class="boo" style="display:block;margin:10px 0px;" rel="du" id="2">sdf sdfsd fds f</a>
<a class="boo" style="display:block;margin:10px 0px;" rel="trys" id="3">sdf sdfsd fsdf</a>
<a class="boo" style="display:block;margin:10px 0px;" rel="keturi" id="4">sdf sdfds fsdf sdf dsf sdf sdf</a>

This modification lets every binded element to have different identifiers so I can use menu for links related with each element personal identifiers.

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