Context.js icon indicating copy to clipboard operation
Context.js copied to clipboard

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

Open cwacek opened this issue 10 years ago • 2 comments

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 avatar May 09 '14 17:05 cwacek

:+1:

Misiu avatar Jun 26 '14 07:06 Misiu

https://github.com/cwacek/Context.js/commit/e79050b7a5a3fbc3f6b7de8590c558b80e477648 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);
        });
    })();
}

xyleen avatar Jul 08 '14 14:07 xyleen