Fix jsdoc, add missing documentation.
[guacamole-common-js.git] / src / main / resources / keyboard.js
index 474c42b..8c08f39 100644 (file)
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Guacamole namespace
+/**
+ * Namespace for all Guacamole JavaScript objects.
+ * @namespace
+ */
 var Guacamole = Guacamole || {};
 
 /**
@@ -60,9 +63,6 @@ Guacamole.Keyboard = function(element) {
      * 
      * @event
      * @param {Number} keysym The keysym of the key being pressed.
-     * @returns {Boolean} true if the originating event of this keypress should
-     *                    be allowed through to the browser, false or undefined
-     *                    otherwise.
      */
     this.onkeydown = null;
 
@@ -72,9 +72,6 @@ Guacamole.Keyboard = function(element) {
      * 
      * @event
      * @param {Number} keysym The keysym of the key being released.
-     * @returns {Boolean} true if the originating event of this key release 
-     *                    should be allowed through to the browser, false or
-     *                    undefined otherwise.
      */
     this.onkeyup = null;
 
@@ -336,9 +333,7 @@ Guacamole.Keyboard = function(element) {
 
         // Send key event
         if (keysym != null && guac_keyboard.onkeydown)
-            return guac_keyboard.onkeydown(keysym) != false;
-        
-        return true;
+            guac_keyboard.onkeydown(keysym);
 
     }
 
@@ -350,9 +345,7 @@ Guacamole.Keyboard = function(element) {
 
         // Send key event
         if (keysym != null && guac_keyboard.onkeyup)
-            return guac_keyboard.onkeyup(keysym) != false;
-
-        return true;
+            guac_keyboard.onkeyup(keysym);
 
     }
 
@@ -418,7 +411,7 @@ Guacamole.Keyboard = function(element) {
     }
 
     // When key pressed
-    element.onkeydown = function(e) {
+    element.addEventListener("keydown", function(e) {
 
         // Only intercept if handler set
         if (!guac_keyboard.onkeydown) return;
@@ -428,7 +421,7 @@ Guacamole.Keyboard = function(element) {
         else if (e.which) keynum = e.which;
 
         // Ignore any unknown key events
-        if (keynum == 0) {
+        if (keynum == 0 && !e.keyIdentifier) {
             e.preventDefault();
             return;
         }
@@ -481,10 +474,10 @@ Guacamole.Keyboard = function(element) {
             handleKeyEvents();
         }
 
-    };
+    }, true);
 
     // When key pressed
-    element.onkeypress = function(e) {
+    element.addEventListener("keypress", function(e) {
 
         // Only intercept if handler set
         if (!guac_keyboard.onkeydown) return;
@@ -515,10 +508,10 @@ Guacamole.Keyboard = function(element) {
         // Handle event with all aggregated data
         handleKeyEvents();
 
-    };
+    }, true);
 
     // When key released
-    element.onkeyup = function(e) {
+    element.addEventListener("keyup", function(e) {
 
         // Only intercept if handler set
         if (!guac_keyboard.onkeyup) return;
@@ -545,13 +538,13 @@ Guacamole.Keyboard = function(element) {
         // Send release event
         sendKeyReleased(lastKeyDownChar);
 
-    };
+    }, true);
 
     // When focus is lost, clear modifiers.
-    element.onblur = function() {
+    element.addEventListener("blur", function() {
         guac_keyboard.modifiers.alt = false;
         guac_keyboard.modifiers.ctrl = false;
         guac_keyboard.modifiers.shift = false;
-    };
+    }, true);
 
 };