Modify drag handler for easier subclassing. Thanks for the team effort on this one (closes #827).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4096 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -76,6 +76,56 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
/**
|
||||
* The four methods below (down, move, up, and out) are used by subclasses
|
||||
* to do their own processing related to these mouse events.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Method: down
|
||||
* This method is called during the handling of the mouse down event.
|
||||
* Subclasses can do their own processing here.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse down event
|
||||
*/
|
||||
down: function(evt) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: move
|
||||
* This method is called during the handling of the mouse move event.
|
||||
* Subclasses can do their own processing here.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse move event
|
||||
*
|
||||
*/
|
||||
move: function(evt) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: up
|
||||
* This method is called during the handling of the mouse up event.
|
||||
* Subclasses can do their own processing here.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse up event
|
||||
*/
|
||||
up: function(evt) {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: out
|
||||
* This method is called during the handling of the mouse out event.
|
||||
* Subclasses can do their own processing here.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event} The mouse out event
|
||||
*/
|
||||
out: function(evt) {
|
||||
},
|
||||
|
||||
/**
|
||||
* The methods below are part of the magic of event handling. Because
|
||||
* they are named like browser events, they are registered as listeners
|
||||
@@ -100,6 +150,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
this.last = evt.xy;
|
||||
// TBD replace with CSS classes
|
||||
this.map.div.style.cursor = "move";
|
||||
this.down(evt);
|
||||
this.callback("down", [evt.xy]);
|
||||
OpenLayers.Event.stop(evt);
|
||||
return false;
|
||||
@@ -121,6 +172,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
if (this.started) {
|
||||
if(evt.xy.x != this.last.x || evt.xy.y != this.last.y) {
|
||||
this.dragging = true;
|
||||
this.move(evt);
|
||||
this.callback("move", [evt.xy]);
|
||||
if(!this.oldOnselectstart) {
|
||||
this.oldOnselectstart = document.onselectstart;
|
||||
@@ -148,6 +200,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
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]);
|
||||
document.onselectstart = this.oldOnselectstart;
|
||||
@@ -171,6 +224,7 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
this.dragging = false;
|
||||
// TBD replace with CSS classes
|
||||
this.map.div.style.cursor = "";
|
||||
this.out(evt);
|
||||
this.callback("out", []);
|
||||
if(document.onselectstart) {
|
||||
document.onselectstart = this.oldOnselectstart;
|
||||
@@ -210,12 +264,12 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* {Boolean} The handler was successfully activated.
|
||||
*/
|
||||
activate: function() {
|
||||
var activated = false;
|
||||
if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
this.dragging = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
activated = true;
|
||||
}
|
||||
return activated;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -226,12 +280,12 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* {Boolean} The handler was successfully deactivated.
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = false;
|
||||
if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
this.dragging = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
deactivated = true;
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Handler.Drag"
|
||||
|
||||
Reference in New Issue
Block a user