Skip to content

Provide context to 'action' function. Clean up DOM on destroy#6

Open
cwacek wants to merge 2 commits intojakiestfu:masterfrom
cwacek:master
Open

Provide context to 'action' function. Clean up DOM on destroy#6
cwacek wants to merge 2 commits intojakiestfu:masterfrom
cwacek:master

Conversation

@cwacek
Copy link
Copy Markdown

@cwacek cwacek commented May 9, 2014

This fixes #2 by providing 'action' functions with the DOM element that was right-clicked as their second argument.

It also fixes #1 by removing context menus from the DOM on destroy.

cwacek added 2 commits May 9, 2014 13:48
'action' functions will now receive the DOM element that was right-clicked
to create the context menu as their second argument.
@Misiu
Copy link
Copy Markdown

Misiu commented Jun 26, 2014

👍

@xyleen
Copy link
Copy Markdown

xyleen commented Jul 8, 2014

cwacek@e79050b doesn't work when you've got multiple menu items, as you're creating a function in a loop. A quick n' dirty workaround for this is to wrap it up in an IFFE, so it will bind the declared variables correctly.

Lines 73-83:

if (typeof data[i].action !== 'undefined') {
    (function () {
        var actiond = new Date(),
            actionID = 'event-' + actiond.getTime() * Math.floor(Math.random() * 100000),
            eventAction = data[i].action;
        $sub.find('a').attr('id', actionID);
        $('#' + actionID).addClass('context-event');

        $(document).on('click', '#' + actionID, function (event) {
            eventAction(event, $menu.context);
        });
    })();
}

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

Successfully merging this pull request may close these issues.

When an action is selected, there is nothing that communicates the context.

3 participants