3
* @author <a href="mailto:keith.hughitt@nasa.gov">Keith Hughitt</a>
5
/*jslint browser: true, white: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true,
6
bitwise: true, regexp: true, strict: true, newcap: true, immed: true, maxlen: 120, sub: true */
7
/*globals document, $, Class */
9
var KeyboardManager = Class.extend(
10
/** @lends KeyboardManager.prototype */
15
init: function (controller) {
16
this.controller = controller;
17
this._initEventHandlers();
22
* @description Initialize keyboard-related event handlers.
24
* TODO: use events or public method instead of zoomControl's (private) method.
26
* TODO (2009/07/29): Webkit doesn't support keypress events for non alphanumeric
27
* keys (http://ejohn.org/blog/keypress-in-safari-31/).
29
* Instead of using keypress, it may be better to use keydown and a boolean to decide
30
* when vp is moving and when it should be stationary.
32
* Simple implementation:
33
* vp.movingUp (Boolean), vp.movingDown (Boolean), vp.movingLeft (Boolean), vp.movingRight (Boolean)
35
* From there it is also simple to add support for diagonal movement, etc.
37
_initEventHandlers: function () {
38
var onKeyPress, self = this;
41
* @description Sets up keyboard shortcuts
42
* @TODO 01/04/2010: Use something like js-hotkeys (http://code.google.com/p/js-hotkeys/)
43
* to allow for more advanced keyboard navigation such as "cntl + z" to undo, etc
44
* TODO 01/16/2009: Create buttons for mouse-coord and detail toggles
46
onKeyPress = function (e) {
47
var key, character, vp = self.controller.viewport;
49
// Letters use Event.which, while arrows, etc. use Event.keyCode
57
// Get character pressed (letters, etc)
58
character = String.fromCharCode(key);
61
if (key === 37 || key === 38 || key === 39 || key === 40) {
63
vp.moveCounter += 1; // Threshold
64
//if ((vp.moveCounter % vp.imageUpdateThrottle) !== 0)
66
vp.moveCounter = vp.moveCounter % vp.tileUpdateThrottle;
74
else if (key === 38) {
79
else if (key === 39) {
84
else if (key === 40) {
92
else if (character === "c") {
93
$("#center-button").click();
95
else if (character === "m") {
96
vp.toggleMouseCoords();
98
else if (character === "-" || character === "_") {
99
$("#zoomControlZoomOut").click();
101
else if (character === "=" || character === "+") {
102
$("#zoomControlZoomIn").click();
104
else if (character === "d") {
105
self.controller.eventLayers.toggleLabels();
107
else if (character === "f") {
108
$("#fullscreen-btn").click();
110
else if (character === ",") {
111
$("#timeBackBtn").click();
113
else if (character === ".") {
114
$("#timeForwardBtn").click();
119
$(document).keypress(function (e) {
120
if (e.target.tagName !== "INPUT") {