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

Open
#331 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
55/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, jquery
Domain
documentation

Research direction

Start with the documentation for menus created through the build function and review the existing guidance for show events and dynamic titles. Add the provided dynamic-menu example or equivalent explanation, then verify that users can find how to set a title from the triggering element.

Written by the indexing model from the issue text.

Description

Documentation

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!

Dominant language
JavaScript
Stars
2.2k
Forks
721
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from swisnl/jQuery-contextMenu

All issues in swisnl/jQuery-contextMenu

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.