fix document dragging which was broken with r10871. Note that this could also have been fixed by creating the Events instance on the element returned by OpenLayers.Util.getViewportElement() instead of document. r=erilem (closes #2941)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10954 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-12-07 23:48:20 +00:00
parent 43dd65d357
commit ed7faebbcb

View File

@@ -94,8 +94,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
/**
* Property: documentEvents
* {<OpenLayers.Events>} Event instance for observing document events. Will
* be set on mouseout if documentDrag is set to true.
* {Boolean} Are we currently observing document events?
*/
documentEvents: null,
@@ -117,6 +116,19 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
*/
initialize: function(control, callbacks, options) {
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
if (this.documentDrag === true) {
var me = this;
this._docMove = function(evt) {
me.mousemove({
xy: {x: evt.clientX, y: evt.clientY},
element: document
});
};
this._docUp = function(evt) {
me.mouseup({xy: {x: evt.clientX, y: evt.clientY}});
};
}
},
/**
@@ -232,7 +244,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
// registered with the map
this.setEvent(evt);
} else {
this.destroyDocumentEvents();
this.removeDocumentEvents();
}
}
if (this.interval > 0) {
@@ -272,7 +284,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
if (this.started) {
if(this.documentDrag === true && this.documentEvents) {
this.adjustXY(evt);
this.destroyDocumentEvents();
this.removeDocumentEvents();
}
var dragged = (this.start != this.last);
this.started = false;
@@ -303,15 +315,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
mouseout: function (evt) {
if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) {
if(this.documentDrag === true) {
this.documentEvents = new OpenLayers.Events(this, document,
null, null, {includeXY: true});
this.documentEvents.on({
mousemove: this.mousemove,
mouseup: this.mouseup
});
OpenLayers.Element.addClass(
document.body, "olDragDown"
);
this.addDocumentEvents();
} else {
var dragged = (this.start != this.last);
this.started = false;
@@ -403,17 +407,27 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
},
/**
* Method: destroyDocumentEvents
* Destroys the events instance that gets added to the document body when
* documentDrag is true and the mouse cursor leaves the map viewport while
* dragging.
* Method: addDocumentEvents
* Start observing document events when documentDrag is true and the mouse
* cursor leaves the map viewport while dragging.
*/
destroyDocumentEvents: function() {
OpenLayers.Element.removeClass(
document.body, "olDragDown"
);
this.documentEvents.destroy();
this.documentEvents = null;
addDocumentEvents: function() {
OpenLayers.Element.addClass(document.body, "olDragDown");
this.documentEvents = true;
OpenLayers.Event.observe(document, "mousemove", this._docMove);
OpenLayers.Event.observe(document, "mouseup", this._docUp);
},
/**
* Method: removeDocumentEvents
* Stops observing document events when documentDrag is true and the mouse
* cursor re-enters the map viewport while dragging.
*/
removeDocumentEvents: function() {
OpenLayers.Element.removeClass(document.body, "olDragDown");
this.documentEvents = false;
OpenLayers.Event.stopObserving(document, "mousemove", this._docMove);
OpenLayers.Event.stopObserving(document, "mouseup", this._docUp);
},
CLASS_NAME: "OpenLayers.Handler.Drag"