[OpenLayers-Commits] r5097 - in trunk/openlayers: lib/OpenLayers/Handler tests/Handler
commits at openlayers.org
commits at openlayers.org
Thu Nov 1 16:53:09 EDT 2007
Author: tschaub
Date: 2007-11-01 16:53:06 -0400 (Thu, 01 Nov 2007)
New Revision: 5097
Modified:
trunk/openlayers/lib/OpenLayers/Handler/Drag.js
trunk/openlayers/tests/Handler/test_Drag.html
Log:
Make the drag handler only call done if it actually dragged - thanks for the review Eric (closes #1118).
Modified: trunk/openlayers/lib/OpenLayers/Handler/Drag.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Drag.js 2007-11-01 20:51:39 UTC (rev 5096)
+++ trunk/openlayers/lib/OpenLayers/Handler/Drag.js 2007-11-01 20:53:06 UTC (rev 5097)
@@ -16,7 +16,9 @@
* when the drag begins, with each move, and when the drag is done. In
* addition, controls can have callbacks keyed to 'up' and 'out' if they
* care to differentiate between the types of events that correspond with
- * the end of a drag sequence.
+ * the end of a drag sequence. If no drag actually occurs (no mouse move)
+ * the 'down' and 'up' callbacks will be called, but not the 'done'
+ * callback.
*
* Create a new drag handler with the <OpenLayers.Handler.Drag> constructor.
*
@@ -207,13 +209,16 @@
*/
mouseup: function (evt) {
if (this.started) {
+ var dragged = (this.start != this.last);
this.started = false;
this.dragging = false;
// TBD replace with CSS classes
this.map.div.style.cursor = "";
this.up(evt);
this.callback("up", [evt.xy]);
- this.callback("done", [evt.xy]);
+ if(dragged) {
+ this.callback("done", [evt.xy]);
+ }
document.onselectstart = this.oldOnselectstart;
}
return true;
@@ -231,16 +236,19 @@
*/
mouseout: function (evt) {
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
+ var dragged = (this.start != this.last);
this.started = false;
this.dragging = false;
// TBD replace with CSS classes
this.map.div.style.cursor = "";
this.out(evt);
this.callback("out", []);
+ if(dragged) {
+ this.callback("done", [evt.xy]);
+ }
if(document.onselectstart) {
document.onselectstart = this.oldOnselectstart;
}
- this.callback("done", [evt.xy]);
}
return true;
},
Modified: trunk/openlayers/tests/Handler/test_Drag.html
===================================================================
--- trunk/openlayers/tests/Handler/test_Drag.html 2007-11-01 20:51:39 UTC (rev 5096)
+++ trunk/openlayers/tests/Handler/test_Drag.html 2007-11-01 20:53:06 UTC (rev 5097)
@@ -87,7 +87,7 @@
}
function test_Handler_Drag_callbacks(t) {
- t.plan(33);
+ t.plan(34);
var map = new OpenLayers.Map('map', {controls: []});
@@ -187,6 +187,14 @@
OpenLayers.Event.isLeftClick = oldIsLeftClick;
handler.checkModifiers = oldCheckModifiers;
+ // test mouseup before mousemove
+ var realUp = testEvents.up;
+ testEvents.up = testEvents.down;
+ // this will fail with notice about the done callback being called
+ // if done is called when it shouldn't be
+ map.events.triggerEvent("mouseup", testEvents.up);
+ testEvents.up = realUp;
+
// test mousemove
handler.started = false;
map.events.triggerEvent("mousemove", {xy: {x: null, y: null}});
More information about the Commits
mailing list