jQuery-contextMenu icon indicating copy to clipboard operation
jQuery-contextMenu copied to clipboard

feature request[?]: Event information not available for callback functions

Open arashdalir opened this issue 9 years ago • 3 comments

Hi there! I'd like to ask for a feature, which might come handy to many: It would be great if the callback function could have a third parameter, which contains the triggered event. As event object is available as a global variable in the real browsers (Firefox doesn't count as one!), it's easy to determine if the callback event is triggered using control buttons or right click of the mouse, but as mentioned, because the lovely firefox lacks this global variable, it's not possible to determine event information in callback function. as an example, please refer to the following code

callback: function (key, options/*, event would be great as third parameter */)
{
	var $button = $(options.$trigger);
	var _this = defaults._findThis(options, key);
	if(typeof event !== 'undefined' && event.ctrlKey)
	{
		// start dancing around the browser
	}
	else
	{
		// do the normal thing
	}
}

arashdalir avatar Nov 07 '16 16:11 arashdalir

Thanks for your interest, i'll visit this in the next round of features. :)

bbrala avatar Nov 07 '16 18:11 bbrala

Hmm, was wandering through the code and saw this code;

callback.call(root.$trigger, key, root, e)

seems the fourth argument is event right now.

bbrala avatar Dec 15 '17 15:12 bbrala

It is indeed possible to get the event back from the callback. Additionally, x/y trigger coords are attached to the event passed back. However, after working with this plugin, i found the best way to get the most control is to run context menu via a manual trigger event, and run async/deferred. Check out https://pastebin.com/kxPpSNry for an example. I realize it's a big chunk of code to take in, so if it's too much, just checkout contextmenus documentation on asyncronous creation.

hybridwebdev avatar Dec 15 '17 19:12 hybridwebdev