Merge pull request #222 from camptocamp/access_keyboardcontrol
KeyboardDefaults control improvements
This commit is contained in:
@@ -34,6 +34,15 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
slideFactor: 75,
|
||||
|
||||
/**
|
||||
* APIProperty: observeElement
|
||||
* {DOMelement|String} The DOM element to handle keys for. You
|
||||
* can use the map div here, to have the navigation keys
|
||||
* work when the map div has the focus. If undefined the
|
||||
* document is used.
|
||||
*/
|
||||
observeElement: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.KeyboardDefaults
|
||||
*/
|
||||
@@ -43,8 +52,11 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Create handler.
|
||||
*/
|
||||
draw: function() {
|
||||
this.handler = new OpenLayers.Handler.Keyboard( this, {
|
||||
"keydown": this.defaultKeyPress });
|
||||
var observeElement = this.observeElement || document;
|
||||
this.handler = new OpenLayers.Handler.Keyboard( this,
|
||||
{"keydown": this.defaultKeyPress},
|
||||
{observeElement: observeElement}
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -62,7 +74,7 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
* evt - {Event}
|
||||
*/
|
||||
defaultKeyPress: function (evt) {
|
||||
var size;
|
||||
var size, handled = true;
|
||||
switch(evt.keyCode) {
|
||||
case OpenLayers.Event.KEY_LEFT:
|
||||
this.map.pan(-this.slideFactor, 0);
|
||||
@@ -106,7 +118,14 @@ OpenLayers.Control.KeyboardDefaults = OpenLayers.Class(OpenLayers.Control, {
|
||||
case 95: // -/_ (some ASCII)
|
||||
this.map.zoomOut();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
handled = false;
|
||||
}
|
||||
if (handled) {
|
||||
// prevent browser default not to move the page
|
||||
// when moving the page with the keyboard
|
||||
OpenLayers.Event.stop(evt);
|
||||
}
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.KeyboardDefaults"
|
||||
|
||||
@@ -33,6 +33,13 @@ OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
eventListener: null,
|
||||
|
||||
/**
|
||||
* Property: observeElement
|
||||
* {DOMElement|String} The DOM element on which we listen for
|
||||
* key events. Default to the document.
|
||||
*/
|
||||
observeElement: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.Keyboard
|
||||
* Returns a new keyboard handler.
|
||||
@@ -71,9 +78,10 @@ OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
activate: function() {
|
||||
if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
|
||||
this.observeElement = this.observeElement || document;
|
||||
for (var i=0, len=this.KEY_EVENTS.length; i<len; i++) {
|
||||
OpenLayers.Event.observe(
|
||||
document, this.KEY_EVENTS[i], this.eventListener);
|
||||
this.observeElement, this.KEY_EVENTS[i], this.eventListener);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
@@ -89,7 +97,7 @@ OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, {
|
||||
if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
|
||||
for (var i=0, len=this.KEY_EVENTS.length; i<len; i++) {
|
||||
OpenLayers.Event.stopObserving(
|
||||
document, this.KEY_EVENTS[i], this.eventListener);
|
||||
this.observeElement, this.KEY_EVENTS[i], this.eventListener);
|
||||
}
|
||||
deactivated = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user