Make the drag handler only call done if it actually dragged - thanks for the review Eric (closes #1118).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5097 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -16,7 +16,9 @@
|
|||||||
* when the drag begins, with each move, and when the drag is done. In
|
* 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
|
* addition, controls can have callbacks keyed to 'up' and 'out' if they
|
||||||
* care to differentiate between the types of events that correspond with
|
* 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.
|
* Create a new drag handler with the <OpenLayers.Handler.Drag> constructor.
|
||||||
*
|
*
|
||||||
@@ -207,13 +209,16 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
*/
|
*/
|
||||||
mouseup: function (evt) {
|
mouseup: function (evt) {
|
||||||
if (this.started) {
|
if (this.started) {
|
||||||
|
var dragged = (this.start != this.last);
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.dragging = false;
|
this.dragging = false;
|
||||||
// TBD replace with CSS classes
|
// TBD replace with CSS classes
|
||||||
this.map.div.style.cursor = "";
|
this.map.div.style.cursor = "";
|
||||||
this.up(evt);
|
this.up(evt);
|
||||||
this.callback("up", [evt.xy]);
|
this.callback("up", [evt.xy]);
|
||||||
this.callback("done", [evt.xy]);
|
if(dragged) {
|
||||||
|
this.callback("done", [evt.xy]);
|
||||||
|
}
|
||||||
document.onselectstart = this.oldOnselectstart;
|
document.onselectstart = this.oldOnselectstart;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -231,16 +236,19 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
*/
|
*/
|
||||||
mouseout: function (evt) {
|
mouseout: function (evt) {
|
||||||
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
|
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
|
||||||
|
var dragged = (this.start != this.last);
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.dragging = false;
|
this.dragging = false;
|
||||||
// TBD replace with CSS classes
|
// TBD replace with CSS classes
|
||||||
this.map.div.style.cursor = "";
|
this.map.div.style.cursor = "";
|
||||||
this.out(evt);
|
this.out(evt);
|
||||||
this.callback("out", []);
|
this.callback("out", []);
|
||||||
|
if(dragged) {
|
||||||
|
this.callback("done", [evt.xy]);
|
||||||
|
}
|
||||||
if(document.onselectstart) {
|
if(document.onselectstart) {
|
||||||
document.onselectstart = this.oldOnselectstart;
|
document.onselectstart = this.oldOnselectstart;
|
||||||
}
|
}
|
||||||
this.callback("done", [evt.xy]);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -87,7 +87,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_Handler_Drag_callbacks(t) {
|
function test_Handler_Drag_callbacks(t) {
|
||||||
t.plan(33);
|
t.plan(34);
|
||||||
|
|
||||||
var map = new OpenLayers.Map('map', {controls: []});
|
var map = new OpenLayers.Map('map', {controls: []});
|
||||||
|
|
||||||
@@ -187,6 +187,14 @@
|
|||||||
OpenLayers.Event.isLeftClick = oldIsLeftClick;
|
OpenLayers.Event.isLeftClick = oldIsLeftClick;
|
||||||
handler.checkModifiers = oldCheckModifiers;
|
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
|
// test mousemove
|
||||||
handler.started = false;
|
handler.started = false;
|
||||||
map.events.triggerEvent("mousemove", {xy: {x: null, y: null}});
|
map.events.triggerEvent("mousemove", {xy: {x: null, y: null}});
|
||||||
|
|||||||
Reference in New Issue
Block a user