Simplify autoscroll.
authorMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 6 Apr 2012 20:07:46 +0000 (13:07 -0700)
committerMichael Jumper <zhangmaike@users.sourceforge.net>
Fri, 6 Apr 2012 20:07:46 +0000 (13:07 -0700)
src/main/webapp/scripts/interface.js

index c5c4e65..092bcb8 100644 (file)
@@ -476,28 +476,18 @@ GuacamoleUI.attach = function(guac) {
             var view_width  = GuacamoleUI.viewport.offsetWidth;
             var view_height = GuacamoleUI.viewport.offsetHeight;
 
-            // Determine scroll amounts based on mouse position relative to document
-
-            var scroll_amount_x;
+            // Scroll horizontally if necessary
             if (mouse_view_x > view_width)
-                scroll_amount_x = mouse_view_x - view_width;
+                GuacamoleUI.viewport.scrollLeft += mouse_view_x - view_width;
             else if (mouse_view_x < 0)
-                scroll_amount_x = mouse_view_x;
-            else
-                scroll_amount_x = 0;
+                GuacamoleUI.viewport.scrollLeft += mouse_view_x;
 
-            var scroll_amount_y;
+            // Scroll vertically if necessary
             if (mouse_view_y > view_height)
-                scroll_amount_y = mouse_view_y - view_height;
+                GuacamoleUI.viewport.scrollTop += mouse_view_y - view_height;
             else if (mouse_view_y < 0)
-                scroll_amount_y = mouse_view_y;
-            else
-                scroll_amount_y = 0;
-
-            // Scroll (if necessary) to keep mouse on screen.
-            GuacamoleUI.viewport.scrollLeft += scroll_amount_x;
-            GuacamoleUI.viewport.scrollTop  += scroll_amount_y;
-       
+                GuacamoleUI.viewport.scrollTop += mouse_view_y;
+
             // Send mouse event
             guac.sendMouseState(mouseState);