Skip to content

Document the use of the show event to set the title of a dynamic menu #331

Open
@cperthuis

Description

@cperthuis

Hi,

This is a suggestion to improve the documentation.

For menus using the 'build' function, the only way I found to set the menu title was to do it in the show event.

        $.contextMenu({
            selector: '.ui-timeline-key',
            className: 'ui-contextmenu-title-key',
            build: function ($trigger, e) {
                return {
                    callback: function (key, options) {
                        var m = "clicked: " + key;
                        window.console && console.log(m) || alert(m);
                    },
                    items: keyContextMenuItems
                };
            },
            events: {
                show: function (options) {
                    //this refers to the triggering element
                    //read a custom data of the triggering element
                    var keyName = this.attr('data-key'); 
                    //set a custom menu title using the javascript method
                    $('.ui-contextmenu-title-key').attr('data-menutitle', "key " + keyName);
                    return true;
                }
            }
        });

I thihk it would be nice to add it to the documentation, I almost gave up on the lib because this appeared to not be supported. Most of my usage cases require dynamic menus and having a dynamic title is a really nice feature.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions