Right click functionality on some buttons - how to, and demo
To use at best the screen estate it is indicated sometimes to implement right-click handlers that trigger menus or other activities.
Recently I thought implementing such functionality on
http://my.sorescu.eu/. The functionality implemented was triggering a dialogue box; the complete functionality is still under development, but the right-click handler has been implemented.
I am using Google Chrome right now to test it, and I saw the following misbehaviour: if I right-click on the "MY Place" button after right-dragging, I get the event triggered multiple times.
I patched the
code by inserting a line after line 53:
$(this).mousedown( function(e) {
var evt = e;
$(this).unbind('mouseup');//added by dragos-matei@sorescu.eu to avoid double right click events, or ghost right clicks for right dragging events starting from this button
$(this).mouseup( function() {
$(this).unbind('mouseup');
if( evt.button == 2 ) {
handler.call( $(this), evt );
return false;
} else {
return true;
}
});
});
The issue seems to be in the original code that every time the
rightMouseDown occurs, a new
rightMouseUp handler is added.
What I did was to remove the rightMouseUp event also when rightMouseDown event.
N.B.: No guarantee that the script in discussion and the modification I did is useful, safe, good, or whatever else - just take it without any warranty, of any kind, under any circumstances.