Joshua Olds
Joshua Olds

Reputation: 177

Apply actual actions to right click context menu

I am trying to use this right-click context menu. It works visually as hoped, however I dont know where to begin to apply actual actions when menu items are clicked. Obviously right now all it says is Back menu item was clicked - target id...., Obiviously when someone clicked back it would actually take them back a page vice just stating what they clicked.

here is the jquery that generates the menu

<script>
    var callback = function(target,element){
        $(target).html('<span style="color:red">' +$(element).html() +'</span> menu is clicked, Target id: '+ $(target).attr('id'));
    };
    var menu = {};

    menu['back']            = {icon:'icon-arrow-left',text:'Back',click:callback};
    menu['forward']         = {icon:'icon-arrow-right',text:'Forward',click:callback};

    menu['view']            = {text:'View',click:callback};
    menu['sortby']          = {text:'Sort by',click:callback};
    menu['refresh']         = {icon:'icon-refresh',text:'Refresh',click:callback};
    menu['notepad']         = {text:'Notepad++',click:callback};

    menu['s1']          = '---';
    menu['copy']            = {text:'Copy',click:callback};
    menu['paste']           = {disabled:true,text:'Paste',click:callback};
    menu['paste_shortcut']          = {disabled:true,text:'Paste shortcut',click:callback};

    menu['s2']          = '---';
    menu['create_shortcut']         = {text:'Create shortcut',click:callback};
    menu['rename']          = {text:'Rename',click:callback};
    menu['del']         = {text:'Delete',click:callback};

    menu['s3']          = '---';
    menu['properties']      = {text:'Properties',click:callback};

    $('#id0').contextMenu(menu);





    $('body').contextMenu(menu);
    $('body').contextMenu('beforeDisplay',function(target){ console.log(target.html()) });
</script>   

Thanks for any help/guidance where to look or how to get started in advance!

Upvotes: 1

Views: 372

Answers (1)

Hogan
Hogan

Reputation: 70513

Replace

 function(target){ console.log(target.html()) }

with a function that performs your actions.

Upvotes: 1

Related Questions