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