Prompt when logging out from the button in the yellow bar (users may think this will...
[guacamole.git] / src / main / webapp / scripts / interface.js
index ee0f497..c250ff5 100644 (file)
@@ -2,6 +2,9 @@
 // UI Definition
 var GuacamoleUI = {
 
+    "LOGOUT_PROMPT" :   "Logging out will disconnect all of your active "
+                      + "Guacamole sessions. Are you sure you wish to log out?",
+
     /* Detection Constants */
     
     "LONG_PRESS_DETECT_TIMEOUT"     : 800, /* milliseconds */
@@ -142,7 +145,19 @@ var GuacamoleUI = {
     };
     
     GuacamoleUI.showTouchMenu = function() {
+        
+        GuacamoleUI.touchMenu.style.left =
+            ((GuacamoleUI.viewport.offsetWidth - GuacamoleUI.touchMenu.offsetWidth) / 2
+            + window.pageXOffset)
+            + "px";
+
+        GuacamoleUI.touchMenu.style.top =
+            ((GuacamoleUI.viewport.offsetHeight - GuacamoleUI.touchMenu.offsetHeight) / 2
+            + window.pageYOffset)
+            + "px";
+
         GuacamoleUI.touchMenu.style.visibility = "visible";
+        
     };
 
     GuacamoleUI.shadeMenu = function() {
@@ -264,19 +279,33 @@ var GuacamoleUI = {
     };
 
     // Touch-specific keyboard show
-    GuacamoleUI.buttons.touchShowKeyboard.ontouchstart = 
     GuacamoleUI.buttons.touchShowKeyboard.onclick = 
         function(e) {
+
+            // Center event target in case browser automatically centers
+            // input fields on focus.
+            GuacamoleUI.eventTarget.style.left =
+                (window.pageXOffset + GuacamoleUI.viewport.offsetWidth / 2) + "px";
+
+            GuacamoleUI.eventTarget.style.top =
+                (window.pageYOffset + GuacamoleUI.viewport.offsetHeight / 2) + "px";
+
             GuacamoleUI.eventTarget.focus();
             GuacamoleUI.hideTouchMenu();
-            e.preventDefault();
+
         };
 
     // Logout
     GuacamoleUI.buttons.logout.onclick =
     GuacamoleUI.buttons.touchLogout.onclick =
         function() {
-            window.location.href = "logout";
+
+            // Logout after warning user about session disconnect
+            if (confirm(GuacamoleUI.LOGOUT_PROMPT)) {
+                window.location.href = "logout";
+                GuacamoleUI.hideTouchMenu();
+            }
+            
         };
 
     // Timeouts for detecting if users wants menu to open or close
@@ -435,6 +464,12 @@ var GuacamoleUI = {
     GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
     GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
 
+    // Automatically reposition event target on scroll
+    window.addEventListener("scroll", function() {
+        GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
+        GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
+    });
+
 })();
 
 // Tie UI events / behavior to a specific Guacamole client
@@ -717,4 +752,4 @@ GuacamoleUI.attach = function(guac) {
         guac.sendKeyEvent(0, KEYSYM_CTRL);
     };
 
-};
\ No newline at end of file
+};