diff --git a/lib/OpenLayers/Handler/Click.js b/lib/OpenLayers/Handler/Click.js index aa1b8f7867..37693e185e 100644 --- a/lib/OpenLayers/Handler/Click.js +++ b/lib/OpenLayers/Handler/Click.js @@ -96,6 +96,12 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { */ last: null, + /** + * Property: touch + * {Boolean} Are we on a touch enabled device? Default is false. + */ + touch: false, + /** * Property: rightclickTimerId * {Number} The id of the right mouse timeout waiting to clear the @@ -148,6 +154,7 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { * {Boolean} Continue propagating this event. */ touchstart: function(evt) { + this.touch = true; this.down = evt; this.last = null; return true; @@ -279,6 +286,10 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, { * {Boolean} Continue propagating this event. */ click: function(evt) { + // Sencha Touch emulates click events, see ticket 3079 for more info + if (this.touch === true && evt.type === "click") { + return !this.stopSingle; + } if(this.passesTolerance(evt)) { if(this.timerId != null) { // already received a click diff --git a/tests/Handler/Click.html b/tests/Handler/Click.html index 930add8c22..db33b5f656 100644 --- a/tests/Handler/Click.html +++ b/tests/Handler/Click.html @@ -329,6 +329,43 @@ }); } + function test_touch_ignoresimulatedclick(t) { + t.plan(2); + + // set up + + var log; + + var map = new OpenLayers.Map('map'); + var control = {map: map}; + + var callbacks = { + 'dblclick': function(e) { + log.dblclick = {x: e.xy.x, y: e.xy.y, + lastTouches: e.lastTouches}; + } + }; + + var handler = new OpenLayers.Handler.Click( + control, callbacks, + {'double': true, pixelTolerance: null}); + + // test + + log = {}; + handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]}); + handler.touchend({}); + handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]}); + handler.touchend({type: "click"}); + + t.eq(handler.touch, true, "Touch property should be true"); + + t.ok(log.dblclick == undefined, "dblclick callback not called with simulated click"); + + // tear down + map.destroy(); + } + function test_touch_dblclick(t) { t.plan(5);