More migration to traditional JS events.
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Tue, 5 Jul 2011 17:16:03 +0000 (10:16 -0700)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Tue, 5 Jul 2011 17:16:03 +0000 (10:16 -0700)
src/main/resources/keyboard.js
src/main/resources/mouse.js

index e0f784d..edbe313 100644 (file)
@@ -19,6 +19,8 @@
 
 function GuacamoleKeyboard(element) {
 
+    var guac_keyboard = this;
+
     // Keymap
 
     var unshiftedKeySym = new Array();
@@ -64,11 +66,6 @@ function GuacamoleKeyboard(element) {
     var shiftedKeySym  = new Array();
     shiftedKeySym[18]  = 0xFFE7; // alt
 
-
-       /*****************************************/
-       /*** Keyboard Handler                  ***/
-       /*****************************************/
-
        // Single key state/modifier buffer
        var modShift = 0;
        var modCtrl = 0;
@@ -150,14 +147,14 @@ function GuacamoleKeyboard(element) {
 
        // Sends a single keystroke over the network
        function sendKeyPressed(keysym) {
-               if (keysym != null && keyPressedHandler)
-                       keyPressedHandler(keysym);
+               if (keysym != null && guac_keyboard.onkeydown)
+                       guac_keyboard.onkeydown(keysym);
        }
 
        // Sends a single keystroke over the network
        function sendKeyReleased(keysym) {
-               if (keysym != null)
-                       keyReleasedHandler(keysym);
+               if (keysym != null && guac_keyboard.onkeyup)
+                       guac_keyboard.onkeyup(keysym);
        }
 
 
@@ -171,7 +168,7 @@ function GuacamoleKeyboard(element) {
        element.onkeydown = function(e) {
 
         // Only intercept if handler set
-        if (!keyPressedHandler) return true;
+        if (!guac_keyboard.onkeydown) return true;
 
                var keynum;
                if (window.event) keynum = window.event.keyCode;
@@ -237,7 +234,7 @@ function GuacamoleKeyboard(element) {
     element.onkeypress = function(e) {
 
         // Only intercept if handler set
-        if (!keyPressedHandler) return true;
+        if (!guac_keyboard.onkeydown) return true;
 
         if (keySymSource != KEYPRESS) return false;
 
@@ -272,7 +269,7 @@ function GuacamoleKeyboard(element) {
        element.onkeyup = function(e) {
 
         // Only intercept if handler set
-        if (!keyReleasedHandler) return true;
+        if (!guac_keyboard.onkeyup) return true;
 
                var keynum;
                if (window.event) keynum = window.event.keyCode;
@@ -309,10 +306,7 @@ function GuacamoleKeyboard(element) {
                if (docOnblur != null) docOnblur();
        };
 
-       var keyPressedHandler = null;
-       var keyReleasedHandler = null;
-
-       this.setKeyPressedHandler = function(kh) { keyPressedHandler = kh; };
-       this.setKeyReleasedHandler = function(kh) { keyReleasedHandler = kh; };
+       guac_keyboard.onkeydown = null;
+       guac_keyboard.onkeyup = null;
 
 }
index fb86005..31d5185 100644 (file)
 
 function GuacamoleMouse(element) {
 
-       /*****************************************/
-       /*** Mouse Handler                     ***/
-       /*****************************************/
-
-
-    var mouseIndex = 0;
+    var guac_mouse = this;
 
     var mouseLeftButton   = 0;
     var mouseMiddleButton = 0;
@@ -69,7 +64,8 @@ function GuacamoleMouse(element) {
             parent = parent.offsetParent;
         }
 
-        movementHandler(getMouseState(0, 0));
+        if (guac_mouse.onmousemove)
+            guac_mouse.onmousemove(getMouseState(0, 0));
     };
 
 
@@ -89,7 +85,8 @@ function GuacamoleMouse(element) {
                 break;
         }
 
-        buttonPressedHandler(getMouseState(0, 0));
+        if (guac_mouse.onmousedown)
+            guac_mouse.onmousedown(getMouseState(0, 0));
     };
 
 
@@ -109,7 +106,8 @@ function GuacamoleMouse(element) {
                 break;
         }
 
-        buttonReleasedHandler(getMouseState(0, 0));
+        if (guac_mouse.onmouseup)
+            guac_mouse.onmouseup(getMouseState(0, 0));
     };
 
     element.onmouseout = function(e) {
@@ -122,7 +120,8 @@ function GuacamoleMouse(element) {
             mouseMiddleButton = 0;
             mouseRightButton = 0;
 
-            buttonReleasedHandler(getMouseState(0, 0));
+            if (guac_mouse.onmouseup)
+                guac_mouse.onmouseup(getMouseState(0, 0));
         }
 
     };
@@ -143,14 +142,20 @@ function GuacamoleMouse(element) {
 
         // Up
         if (delta < 0) {
-            buttonPressedHandler(getMouseState(1, 0));
-            buttonReleasedHandler(getMouseState(0, 0));
+            if (guac_mouse.onmousedown)
+                guac_mouse.onmousedown(getMouseState(1, 0));
+
+            if (guac_mouse.onmouseup)
+                guac_mouse.onmouseup(getMouseState(0, 0));
         }
 
         // Down
         if (delta > 0) {
-            buttonPressedHandler(getMouseState(0, 1));
-            buttonReleasedHandler(getMouseState(0, 0));
+            if (guac_mouse.onmousedown)
+                guac_mouse.onmousedown(getMouseState(0, 1));
+            
+            if (guac_mouse.onmouseup)
+                guac_mouse.onmouseup(getMouseState(0, 0));
         }
 
         if (e.preventDefault)
@@ -165,20 +170,15 @@ function GuacamoleMouse(element) {
         handleScroll(e);
     }
 
-       var buttonPressedHandler = null;
-       var buttonReleasedHandler = null;
-       var movementHandler = null;
-
-       this.setButtonPressedHandler  = function(mh) {buttonPressedHandler = mh;};
-       this.setButtonReleasedHandler = function(mh) {buttonReleasedHandler = mh;};
-       this.setMovementHandler = function(mh) {movementHandler = mh;};
-
+       guac_mouse.onmousedown = null;
+       guac_mouse.onmouseup = null;
+       guac_mouse.onmousemove = null;
 
-    this.getX = function() {return mouseX;};
-    this.getY = function() {return mouseY;};
-    this.getLeftButton = function() {return mouseLeftButton;};
-    this.getMiddleButton = function() {return mouseMiddleButton;};
-    this.getRightButton = function() {return mouseRightButton;};
+    guac_mouse.getX = function() {return mouseX;};
+    guac_mouse.getY = function() {return mouseY;};
+    guac_mouse.getLeftButton = function() {return mouseLeftButton;};
+    guac_mouse.getMiddleButton = function() {return mouseMiddleButton;};
+    guac_mouse.getRightButton = function() {return mouseRightButton;};
 
 }