Improve analog mouse wheel detection and normalize event.wheelDelta for Safari

This commit is contained in:
Gregers Gram Rygg
2012-05-29 13:26:27 +02:00
parent a1dff8ad9b
commit 50d24d7756
2 changed files with 24 additions and 8 deletions

View File

@@ -55,12 +55,19 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
*/
cumulative: true,
/**
* APIProperty: isAnalogScrollWheel
* {Boolean} Will switch to true when an event with analog scroll value
* is detected.
*/
isAnalogScrollWheel: false,
/**
* Property: analogWheelPrecision
* {Integer} Adjust to get analog scroll wheel to feel right
*/
analogWheelPrecision: 360,
/**
* Constructor: OpenLayers.Handler.MouseWheel
*
@@ -175,16 +182,24 @@ OpenLayers.Handler.MouseWheel = OpenLayers.Class(OpenLayers.Handler, {
if (!e) {
e = window.event;
}
if (e.wheelDelta) {
delta = e.wheelDelta;
if (delta % 120 === 0) {
delta = delta / 120;
} else {
delta = delta / this.analogWheelPrecision;
}
if (window.opera && window.opera.version() < 9.2) {
if (OpenLayers.BROWSER_NAME === "safari" && !this.isAnalogScrollWheel) {
delta = delta * 10;
} else if (window.opera && window.opera.version() < 9.2) {
delta = -delta;
}
this.isAnalogScrollWheel = (this.isAnalogScrollWheel ||
delta % 40 !== 0 || Math.abs(delta) < 120);
if (this.isAnalogScrollWheel) {
delta = delta / this.analogWheelPrecision;
} else {
delta = Math.round(delta / 120);
}
} else if (e.detail) {
delta = -e.detail / 3;
}

View File

@@ -108,7 +108,8 @@
var activated = handler.activate();
var delta = 120;
if (window.opera && window.opera.version() < 9.2) delta = -delta;
if (window.opera && window.opera.version() < 9.2) { delta = -delta; }
if (OpenLayers.BROWSER_NAME === "safari") delta = delta / 10;
handler.onWheelEvent({'target':map.layers[0].div, wheelDelta: delta});
handler.onWheelEvent({'target':map.layers[0].div, wheelDelta: delta});
t.delay_call(1, function() {