Merge pull request #294 from fredj/stopped-map-events
can't listen to mousedown/touchstart on map div
This commit is contained in:
@@ -167,11 +167,7 @@ OpenLayers.Event = {
|
|||||||
stop: function(event, allowDefault) {
|
stop: function(event, allowDefault) {
|
||||||
|
|
||||||
if (!allowDefault) {
|
if (!allowDefault) {
|
||||||
if (event.preventDefault) {
|
OpenLayers.Event.preventDefault(event);
|
||||||
event.preventDefault();
|
|
||||||
} else {
|
|
||||||
event.returnValue = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.stopPropagation) {
|
if (event.stopPropagation) {
|
||||||
@@ -181,6 +177,22 @@ OpenLayers.Event = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: preventDefault
|
||||||
|
* Cancels the event if it is cancelable, without stopping further
|
||||||
|
* propagation of the event.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* event - {Event}
|
||||||
|
*/
|
||||||
|
preventDefault: function(event) {
|
||||||
|
if (event.preventDefault) {
|
||||||
|
event.preventDefault();
|
||||||
|
} else {
|
||||||
|
event.returnValue = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: findElement
|
* Method: findElement
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -172,7 +172,8 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.down(evt);
|
this.down(evt);
|
||||||
this.callback("down", [evt.xy]);
|
this.callback("down", [evt.xy]);
|
||||||
|
|
||||||
OpenLayers.Event.stop(evt);
|
// prevent document dragging
|
||||||
|
OpenLayers.Event.preventDefault(evt);
|
||||||
|
|
||||||
if(!this.oldOnselectstart) {
|
if(!this.oldOnselectstart) {
|
||||||
this.oldOnselectstart = document.onselectstart ?
|
this.oldOnselectstart = document.onselectstart ?
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.last = null;
|
this.last = null;
|
||||||
}
|
}
|
||||||
// prevent document dragging
|
// prevent document dragging
|
||||||
OpenLayers.Event.stop(evt);
|
OpenLayers.Event.preventDefault(evt);
|
||||||
return propagate;
|
return propagate;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
|
|||||||
node.setAttributeNS(null, "height", height);
|
node.setAttributeNS(null, "height", height);
|
||||||
node.setAttributeNS(this.xlinkns, "href", style.externalGraphic);
|
node.setAttributeNS(this.xlinkns, "href", style.externalGraphic);
|
||||||
node.setAttributeNS(null, "style", "opacity: "+opacity);
|
node.setAttributeNS(null, "style", "opacity: "+opacity);
|
||||||
node.onclick = OpenLayers.Renderer.SVG.preventDefault;
|
node.onclick = OpenLayers.Event.preventDefault;
|
||||||
} else if (this.isComplexSymbol(style.graphicName)) {
|
} else if (this.isComplexSymbol(style.graphicName)) {
|
||||||
// the symbol viewBox is three times as large as the symbol
|
// the symbol viewBox is three times as large as the symbol
|
||||||
var offset = style.pointRadius * 3;
|
var offset = style.pointRadius * 3;
|
||||||
@@ -1000,9 +1000,10 @@ OpenLayers.Renderer.SVG.LABEL_VFACTOR = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Function: OpenLayers.Renderer.SVG.preventDefault
|
* Function: OpenLayers.Renderer.SVG.preventDefault
|
||||||
|
* *Deprecated*. Use <OpenLayers.Event.preventDefault> method instead.
|
||||||
* Used to prevent default events (especially opening images in a new tab on
|
* Used to prevent default events (especially opening images in a new tab on
|
||||||
* ctrl-click) from being executed for externalGraphic symbols
|
* ctrl-click) from being executed for externalGraphic symbols
|
||||||
*/
|
*/
|
||||||
OpenLayers.Renderer.SVG.preventDefault = function(e) {
|
OpenLayers.Renderer.SVG.preventDefault = function(e) {
|
||||||
e.preventDefault && e.preventDefault();
|
OpenLayers.Event.preventDefault(e);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,7 +117,7 @@
|
|||||||
handler.activate();
|
handler.activate();
|
||||||
|
|
||||||
var oldIsLeftClick = OpenLayers.Event.isLeftClick;
|
var oldIsLeftClick = OpenLayers.Event.isLeftClick;
|
||||||
var oldStop = OpenLayers.Event.stop;
|
var oldPreventDefault = OpenLayers.Event.preventDefault;
|
||||||
var oldCheckModifiers = handler.checkModifiers;
|
var oldCheckModifiers = handler.checkModifiers;
|
||||||
|
|
||||||
// test mousedown with right click
|
// test mousedown with right click
|
||||||
@@ -163,15 +163,9 @@
|
|||||||
"mousedown calls isLeftClick with the proper event");
|
"mousedown calls isLeftClick with the proper event");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
OpenLayers.Event.stop = function(evt, allowDefault) {
|
OpenLayers.Event.preventDefault = function(evt) {
|
||||||
if(!allowDefault) {
|
t.ok(evt.xy.x == testEvents.down.xy.x && evt.xy.y == testEvents.down.xy.y,
|
||||||
t.ok(evt.xy.x == testEvents.down.xy.x &&
|
"mousedown default action is disabled");
|
||||||
evt.xy.y == testEvents.down.xy.y,
|
|
||||||
"mousedown default action is disabled");
|
|
||||||
} else {
|
|
||||||
t.fail(
|
|
||||||
"mousedown is prevented from falling to other elements");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
map.events.triggerEvent("mousedown", testEvents.down);
|
map.events.triggerEvent("mousedown", testEvents.down);
|
||||||
t.ok(handler.started, "mousedown sets the started flag to true");
|
t.ok(handler.started, "mousedown sets the started flag to true");
|
||||||
@@ -183,7 +177,7 @@
|
|||||||
handler.last.y == testEvents.down.xy.y,
|
handler.last.y == testEvents.down.xy.y,
|
||||||
"mouse down sets handler.last correctly");
|
"mouse down sets handler.last correctly");
|
||||||
|
|
||||||
OpenLayers.Event.stop = oldStop;
|
OpenLayers.Event.preventDefault = oldPreventDefault;
|
||||||
OpenLayers.Event.isLeftClick = oldIsLeftClick;
|
OpenLayers.Event.isLeftClick = oldIsLeftClick;
|
||||||
handler.checkModifiers = oldCheckModifiers;
|
handler.checkModifiers = oldCheckModifiers;
|
||||||
|
|
||||||
@@ -292,7 +286,7 @@
|
|||||||
function test_Handler_Drag_touch(t) {
|
function test_Handler_Drag_touch(t) {
|
||||||
// In this test we verify that "touchstart", "touchmove", and
|
// In this test we verify that "touchstart", "touchmove", and
|
||||||
// "touchend" events set expected states in the drag handler.
|
// "touchend" events set expected states in the drag handler.
|
||||||
// We also verify that we stop event bubbling as appropriate.
|
// We also verify that we prevent the default as appropriate.
|
||||||
|
|
||||||
t.plan(14);
|
t.plan(14);
|
||||||
|
|
||||||
@@ -308,8 +302,8 @@
|
|||||||
});
|
});
|
||||||
h.activate();
|
h.activate();
|
||||||
|
|
||||||
var _stop = OpenLayers.Event.stop;
|
var _preventDefault = OpenLayers.Event.preventDefault;
|
||||||
OpenLayers.Event.stop = function(e) {
|
OpenLayers.Event.preventDefault = function(e) {
|
||||||
log.push(e);
|
log.push(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -343,7 +337,7 @@
|
|||||||
|
|
||||||
// tear down
|
// tear down
|
||||||
|
|
||||||
OpenLayers.Event.stop = _stop;
|
OpenLayers.Event.preventDefault = _preventDefault;
|
||||||
m.destroy();
|
m.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
38
tests/manual/map-events.html
Normal file
38
tests/manual/map-events.html
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
|
<title>map.div Events Acceptance Test</title>
|
||||||
|
<link rel="stylesheet" href="../../theme/default/style.css" type="text/css">
|
||||||
|
<link rel="stylesheet" href="../../examples/style.css" type="text/css">
|
||||||
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
|
<script type="text/javascript">
|
||||||
|
var map, layer;
|
||||||
|
function init() {
|
||||||
|
map = new OpenLayers.Map('map');
|
||||||
|
layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.setCenter(
|
||||||
|
new OpenLayers.LonLat(-71.147, 42.472).transform(
|
||||||
|
new OpenLayers.Projection("EPSG:4326"),
|
||||||
|
map.getProjectionObject()
|
||||||
|
), 12
|
||||||
|
);
|
||||||
|
|
||||||
|
var element = document.getElementById('map');
|
||||||
|
element.addEventListener('mousedown', function(evt) {
|
||||||
|
alert('mousedown on map div');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body onload="init()">
|
||||||
|
<h1 id="title">map.div Events Acceptance Test</h1>
|
||||||
|
|
||||||
|
<div id="map" class="smallmap"></div>
|
||||||
|
|
||||||
|
<p><b>Test 1</b> : mousedown the map; an alert must be displayed.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user