Move some touch logic to the handler base class.

This commit is contained in:
Xavier Mamano
2012-02-15 17:55:37 +01:00
parent cd41548c01
commit ee8e892bb4
9 changed files with 130 additions and 111 deletions

View File

@@ -85,6 +85,14 @@ OpenLayers.Handler = OpenLayers.Class({
* the OpenLayers code.
*/
evt: null,
/**
* Property: touch
* {Boolean} Indcates the support of touch events. When touch events are
* starded touch will be true and all mouse related listeners will do
* nothing.
*/
touch: false,
/**
* Constructor: OpenLayers.Handler
@@ -186,10 +194,38 @@ OpenLayers.Handler = OpenLayers.Class({
this.unregister(events[i], this[events[i]]);
}
}
this.touch = false;
this.active = false;
return true;
},
/**
* Method: startTouch
* Start touch events, this method must be called by subclasses in
* "touchstart" method. When touch events are starded <touch> will be
* true and all mouse related listeners will do nothing.
*
* Returns:
* {Boolean} The touch events are started.
*/
startTouch: function() {
if (this.touch) {
return false;
} else {
this.touch = true;
var events = [
"mousedown", "mouseup", "mousemove", "click", "dblclick",
"mouseout"
];
for (var i=0, len=events.length; i<len; i++) {
if (this[events[i]]) {
this.unregister(events[i], this[events[i]]);
}
}
return true;
}
},
/**
* Method: callback
* Trigger the control's named callback with the given arguments