1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
6
* @requires OpenLayers/Handler.js
7
* @requires OpenLayers/Events.js
11
* Class: OpenLayers.handler.Keyboard
12
* A handler for keyboard events. Create a new instance with the
13
* <OpenLayers.Handler.Keyboard> constructor.
16
* - <OpenLayers.Handler>
18
OpenLayers.Handler.Keyboard = OpenLayers.Class(OpenLayers.Handler, {
20
/* http://www.quirksmode.org/js/keys.html explains key x-browser
21
key handling quirks in pretty nice detail */
24
* Constant: KEY_EVENTS
25
* keydown, keypress, keyup
27
KEY_EVENTS: ["keydown", "keyup"],
30
* Property: eventListener
36
* Constructor: OpenLayers.Handler.Keyboard
37
* Returns a new keyboard handler.
40
* control - {<OpenLayers.Control>} The control that is making use of
41
* this handler. If a handler is being used without a control, the
42
* handlers setMap method must be overridden to deal properly with
44
* callbacks - {Object} An object containing a single function to be
45
* called when the drag operation is finished. The callback should
46
* expect to recieve a single argument, the pixel location of the event.
47
* Callbacks for 'keydown', 'keypress', and 'keyup' are supported.
48
* options - {Object} Optional object whose properties will be set on the
51
initialize: function(control, callbacks, options) {
52
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
53
// cache the bound event listener method so it can be unobserved later
54
this.eventListener = OpenLayers.Function.bindAsEventListener(
55
this.handleKeyEvent, this
64
this.eventListener = null;
65
OpenLayers.Handler.prototype.destroy.apply(this, arguments);
71
activate: function() {
72
if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
73
for (var i=0, len=this.KEY_EVENTS.length; i<len; i++) {
74
OpenLayers.Event.observe(
75
document, this.KEY_EVENTS[i], this.eventListener);
86
deactivate: function() {
87
var deactivated = false;
88
if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
89
for (var i=0, len=this.KEY_EVENTS.length; i<len; i++) {
90
OpenLayers.Event.stopObserving(
91
document, this.KEY_EVENTS[i], this.eventListener);
99
* Method: handleKeyEvent
101
handleKeyEvent: function (evt) {
102
if (this.checkModifiers(evt)) {
103
this.callback(evt.type, [evt]);
107
CLASS_NAME: "OpenLayers.Handler.Keyboard"