Context.js
Context.js copied to clipboard
Provide context to 'action' function. Clean up DOM on destroy
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.
:+1:
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);
});
})();
}