Add support in OL for right-click capturing, including dbl-right-clicks (for zooming out in navigation control). Thanks to David Martin for this nice patch and the great 8 foot austrian for his review (Closes #1359)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7872 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-08-26 23:27:04 +00:00
parent 091d3cfbeb
commit 17160f49e0
4 changed files with 132 additions and 11 deletions

View File

@@ -89,6 +89,13 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
*/
down: null,
/**
* Property: rightclickTimerId
* {Number} The id of the right mouse timeout waiting to clear the
* <delayedEvent>.
*/
rightclickTimerId: null,
/**
* Constructor: OpenLayers.Handler.Click
* Create a new click handler.
@@ -125,6 +132,78 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean} Continue propagating this event.
*/
mousedown: null,
/**
* Method: mouseup
* Handle mouseup. Installed to support collection of right mouse events.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
mouseup: function (evt) {
var propagate = true;
// Collect right mouse clicks from the mouseup
// IE - ignores the second right click in mousedown so using
// mouseup instead
if (this.checkModifiers(evt) &&
this.control.handleRightClicks &&
OpenLayers.Event.isRightClick(evt)) {
propogate = this.rightclick(evt);
}
return propagate;
},
/**
* Method: rightclick
* Handle rightclick. For a dblrightclick, we get two clicks so we need
* to always register for dblrightclick to properly handle single
* clicks.
*
* Returns:
* {Boolean} Continue propagating this event.
*/
rightclick: function(evt) {
if(this.passesTolerance(evt)) {
if(this.rightclickTimerId != null) {
//Second click received before timeout this must be
// a double click
this.clearTimer();
this.callback('dblrightclick', [evt]);
return !this.stopDouble;
} else {
//Set the rightclickTimerId, send evt only if double is
// true else trigger single
var clickEvent = this['double'] ?
OpenLayers.Util.extend({}, evt) :
this.callback('rightclick', [evt]);
var delayedRightCall = OpenLayers.Function.bind(
this.delayedRightCall,
this,
clickEvent
);
this.rightclickTimerId = window.setTimeout(
delayedRightCall, this.delay
);
}
}
return !this.stopSingle;
},
/**
* Method: delayedRightCall
* Sets <rightclickTimerId> to null. And optionally triggers the
* rightclick callback if evt is set.
*/
delayedRightCall: function(evt) {
this.rightclickTimerId = null;
if (evt) {
this.callback('rightclick', [evt]);
}
return !this.stopSingle;
},
/**
* Method: dblclick