Allow logout button to work where no Java app used
[guacamole.git] / src / main / webapp / scripts / interface.js
1
2 // UI Definition
3 var GuacamoleUI = {
4
5     "LOGOUT_PROMPT" :   "Logging out will disconnect all of your active "
6                       + "Guacamole sessions. Are you sure you wish to log out?",
7
8     /* Detection Constants */
9     
10     "LONG_PRESS_DETECT_TIMEOUT"     : 800, /* milliseconds */
11     "LONG_PRESS_MOVEMENT_THRESHOLD" : 10,  /* pixels */
12     "MENU_CLOSE_DETECT_TIMEOUT"     : 500, /* milliseconds */
13     "MENU_OPEN_DETECT_TIMEOUT"      : 325, /* milliseconds */
14     "KEYBOARD_AUTO_RESIZE_INTERVAL" : 30,  /* milliseconds */
15
16     /* Animation Constants */
17
18     "MENU_SHADE_STEPS"    : 10, /* frames */
19     "MENU_SHADE_INTERVAL" : 30, /* milliseconds */
20     "MENU_SHOW_STEPS"     : 5,  /* frames */
21     "MENU_SHOW_INTERVAL"  : 30, /* milliseconds */
22
23     /* OSK Mode Constants */
24     "OSK_MODE_NATIVE" : 1, /* "Show Keyboard" will show the platform's native OSK */
25     "OSK_MODE_GUAC"   : 2, /* "Show Keyboard" will show Guac's built-in OSK */
26
27     /* UI Elements */
28
29     "viewport"    : document.getElementById("viewportClone"),
30     "display"     : document.getElementById("display"),
31     "menu"        : document.getElementById("menu"),
32     "menuControl" : document.getElementById("menuControl"),
33     "touchMenu"   : document.getElementById("touchMenu"),
34     "logo"        : document.getElementById("status-logo"),
35     "eventTarget" : document.getElementById("eventTarget"),
36
37     "buttons": {
38
39         "showClipboard": document.getElementById("showClipboard"),
40         "showKeyboard" : document.getElementById("showKeyboard"),
41         "ctrlAltDelete": document.getElementById("ctrlAltDelete"),
42         "reconnect"    : document.getElementById("reconnect"),
43         "logout"       : document.getElementById("logout"),
44
45         "touchShowClipboard" : document.getElementById("touchShowClipboard"),
46         "touchShowKeyboard"  : document.getElementById("touchShowKeyboard"),
47         "touchLogout"        : document.getElementById("touchLogout")
48
49     },
50
51     "containers": {
52         "state"         : document.getElementById("statusDialog"),
53         "clipboard"     : document.getElementById("clipboardDiv"),
54         "touchClipboard": document.getElementById("touchClipboardDiv"),
55         "keyboard"      : document.getElementById("keyboardContainer")
56     },
57     
58     "state"          : document.getElementById("statusText"),
59     "clipboard"      : document.getElementById("clipboard"),
60     "touchClipboard" : document.getElementById("touchClipboard")
61
62 };
63
64 // Constant UI initialization and behavior
65 (function() {
66
67     var menu_shaded = false;
68
69     var shade_interval = null;
70     var show_interval = null;
71
72     // Cache error image (might not be available when error occurs)
73     var guacErrorImage = new Image();
74     guacErrorImage.src = "images/noguacamole-logo-24.png";
75
76     // Function for adding a class to an element
77     var addClass;
78
79     // Function for removing a class from an element
80     var removeClass;
81
82     // If Node.classList is supported, implement addClass/removeClass using that
83     if (Node.classList) {
84
85         addClass = function(element, classname) {
86             element.classList.add(classname);
87         };
88         
89         removeClass = function(element, classname) {
90             element.classList.remove(classname);
91         };
92         
93     }
94
95     // Otherwise, implement own
96     else {
97
98         addClass = function(element, classname) {
99
100             // Simply add new class
101             element.className += " " + classname;
102
103         };
104         
105         removeClass = function(element, classname) {
106
107             // Filter out classes with given name
108             element.className = element.className.replace(/([^ ]+)[ ]*/g,
109                 function(match, testClassname, spaces, offset, string) {
110
111                     // If same class, remove
112                     if (testClassname == classname)
113                         return "";
114
115                     // Otherwise, allow
116                     return match;
117                     
118                 }
119             );
120
121         };
122         
123     }
124
125
126     GuacamoleUI.hideStatus = function() {
127         removeClass(document.body, "guac-error");
128         GuacamoleUI.containers.state.style.visibility = "hidden";
129         GuacamoleUI.display.style.opacity = "1";
130     };
131     
132     GuacamoleUI.showStatus = function(text) {
133         removeClass(document.body, "guac-error");
134         GuacamoleUI.containers.state.style.visibility = "visible";
135         GuacamoleUI.state.textContent = text;
136         GuacamoleUI.display.style.opacity = "1";
137     };
138     
139     GuacamoleUI.showError = function(error) {
140         addClass(document.body, "guac-error");
141         GuacamoleUI.state.textContent = error;
142         GuacamoleUI.display.style.opacity = "0.1";
143     };
144
145     GuacamoleUI.hideTouchMenu = function() {
146         GuacamoleUI.touchMenu.style.visibility = "hidden";
147     };
148
149     function positionCentered(element) {
150         element.style.left =
151             ((GuacamoleUI.viewport.offsetWidth - element.offsetWidth) / 2
152             + window.pageXOffset)
153             + "px";
154
155         element.style.top =
156             ((GuacamoleUI.viewport.offsetHeight - element.offsetHeight) / 2
157             + window.pageYOffset)
158             + "px";
159     }
160
161     GuacamoleUI.showTouchMenu = function() {
162         positionCentered(GuacamoleUI.touchMenu);
163         GuacamoleUI.touchMenu.style.visibility = "visible";
164     };
165
166     GuacamoleUI.hideTouchClipboard = function() {
167         GuacamoleUI.touchClipboard.blur();
168         GuacamoleUI.containers.touchClipboard.style.visibility = "hidden";
169     };
170
171     GuacamoleUI.showTouchClipboard = function() {
172         positionCentered(GuacamoleUI.containers.touchClipboard);
173         GuacamoleUI.containers.touchClipboard.style.visibility = "visible";
174     };
175
176     GuacamoleUI.shadeMenu = function() {
177
178         if (!menu_shaded) {
179
180             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHADE_STEPS) + 1;
181             var offset = 0;
182             menu_shaded = true;
183
184             window.clearInterval(show_interval);
185             shade_interval = window.setInterval(function() {
186
187                 offset -= step;
188
189                 GuacamoleUI.menu.style.transform =
190                 GuacamoleUI.menu.style.WebkitTransform =
191                 GuacamoleUI.menu.style.MozTransform =
192                 GuacamoleUI.menu.style.OTransform =
193                 GuacamoleUI.menu.style.msTransform =
194
195                     "translateY(" + offset + "px)";
196
197                 if (offset <= -GuacamoleUI.menu.offsetHeight) {
198                     window.clearInterval(shade_interval);
199                     GuacamoleUI.menu.style.visiblity = "hidden";
200                 }
201
202             }, GuacamoleUI.MENU_SHADE_INTERVAL);
203         }
204
205     };
206
207     GuacamoleUI.showMenu = function() {
208
209         if (menu_shaded) {
210
211             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHOW_STEPS) + 1;
212             var offset = -GuacamoleUI.menu.offsetHeight;
213             menu_shaded = false;
214             GuacamoleUI.menu.style.visiblity = "";
215
216             window.clearInterval(shade_interval);
217             show_interval = window.setInterval(function() {
218
219                 offset += step;
220
221                 if (offset >= 0) {
222                     offset = 0;
223                     window.clearInterval(show_interval);
224                 }
225
226                 GuacamoleUI.menu.style.transform =
227                 GuacamoleUI.menu.style.WebkitTransform =
228                 GuacamoleUI.menu.style.MozTransform =
229                 GuacamoleUI.menu.style.OTransform =
230                 GuacamoleUI.menu.style.msTransform =
231
232                     "translateY(" + offset + "px)";
233
234             }, GuacamoleUI.MENU_SHOW_INTERVAL);
235         }
236
237     };
238
239     // Show/Hide clipboard
240     GuacamoleUI.buttons.showClipboard.onclick = function() {
241
242         var displayed = GuacamoleUI.containers.clipboard.style.display;
243         if (displayed != "block") {
244             GuacamoleUI.containers.clipboard.style.display = "block";
245             GuacamoleUI.buttons.showClipboard.innerHTML = "Hide Clipboard";
246         }
247         else {
248             GuacamoleUI.containers.clipboard.style.display = "none";
249             GuacamoleUI.buttons.showClipboard.innerHTML = "Show Clipboard";
250             GuacamoleUI.clipboard.onchange();
251         }
252
253     };
254
255     GuacamoleUI.buttons.touchShowClipboard.onclick = function() {
256         GuacamoleUI.hideTouchMenu();
257         GuacamoleUI.showTouchClipboard();
258     };
259
260     // Show/Hide keyboard
261     var keyboardResizeInterval = null;
262     GuacamoleUI.buttons.showKeyboard.onclick = function() {
263
264         // If Guac OSK shown, hide it.
265         var displayed = GuacamoleUI.containers.keyboard.style.display;
266         if (displayed == "block") {
267             GuacamoleUI.containers.keyboard.style.display = "none";
268             GuacamoleUI.buttons.showKeyboard.textContent = "Show Keyboard";
269
270             window.onresize = null;
271             window.clearInterval(keyboardResizeInterval);
272         }
273
274         // Otherwise, show it
275         else {
276
277             // Ensure event target is NOT focused if we are using the Guac OSK.
278             GuacamoleUI.eventTarget.blur();
279
280             GuacamoleUI.containers.keyboard.style.display = "block";
281             GuacamoleUI.buttons.showKeyboard.textContent = "Hide Keyboard";
282
283             // Automatically update size
284             window.onresize = updateKeyboardSize;
285             keyboardResizeInterval = window.setInterval(updateKeyboardSize,
286                 GuacamoleUI.KEYBOARD_AUTO_RESIZE_INTERVAL);
287
288             updateKeyboardSize();
289
290         }
291
292     };
293
294     // Touch-specific keyboard show
295     GuacamoleUI.buttons.touchShowKeyboard.onclick = 
296         function(e) {
297
298             // Center event target in case browser automatically centers
299             // input fields on focus.
300             GuacamoleUI.eventTarget.style.left =
301                 (window.pageXOffset + GuacamoleUI.viewport.offsetWidth / 2) + "px";
302
303             GuacamoleUI.eventTarget.style.top =
304                 (window.pageYOffset + GuacamoleUI.viewport.offsetHeight / 2) + "px";
305
306             GuacamoleUI.eventTarget.focus();
307             GuacamoleUI.hideTouchMenu();
308
309         };
310
311     // Logout
312     GuacamoleUI.buttons.logout.onclick =
313     GuacamoleUI.buttons.touchLogout.onclick =
314         function() {
315
316             // Logout after warning user about session disconnect
317             if (confirm(GuacamoleUI.LOGOUT_PROMPT)) {
318                 if(1 == window.SELF_CLOSE){
319                     window.close();
320                 }else{
321                     window.location.href = "logout";
322                     GuacamoleUI.hideTouchMenu();
323                 }
324             }
325             
326         };
327
328     // Timeouts for detecting if users wants menu to open or close
329     var detectMenuOpenTimeout = null;
330     var detectMenuCloseTimeout = null;
331
332     // Clear detection timeouts
333     GuacamoleUI.resetMenuDetect = function() {
334
335         if (detectMenuOpenTimeout != null) {
336             window.clearTimeout(detectMenuOpenTimeout);
337             detectMenuOpenTimeout = null;
338         }
339
340         if (detectMenuCloseTimeout != null) {
341             window.clearTimeout(detectMenuCloseTimeout);
342             detectMenuCloseTimeout = null;
343         }
344
345     };
346
347     // Initiate detection of menu open action. If not canceled through some
348     // user event, menu will open.
349     GuacamoleUI.startMenuOpenDetect = function() {
350
351         if (!detectMenuOpenTimeout) {
352
353             // Clear detection state
354             GuacamoleUI.resetMenuDetect();
355
356             // Wait and then show menu
357             detectMenuOpenTimeout = window.setTimeout(function() {
358
359                 // If menu opened via mouse, do not show native OSK
360                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_GUAC;
361
362                 GuacamoleUI.showMenu();
363                 detectMenuOpenTimeout = null;
364             }, GuacamoleUI.MENU_OPEN_DETECT_TIMEOUT);
365
366         }
367
368     };
369
370     // Initiate detection of menu close action. If not canceled through some
371     // user mouse event, menu will close.
372     GuacamoleUI.startMenuCloseDetect = function() {
373
374         if (!detectMenuCloseTimeout) {
375
376             // Clear detection state
377             GuacamoleUI.resetMenuDetect();
378
379             // Wait and then shade menu
380             detectMenuCloseTimeout = window.setTimeout(function() {
381                 GuacamoleUI.shadeMenu();
382                 detectMenuCloseTimeout = null;
383             }, GuacamoleUI.MENU_CLOSE_DETECT_TIMEOUT);
384
385         }
386
387     };
388
389     // Show menu if mouseover any part of menu
390     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.showMenu, true);
391
392     // Stop detecting menu state change intents if mouse is over menu
393     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.resetMenuDetect, true);
394
395     // When mouse hovers over top of screen, start detection of intent to open menu
396     GuacamoleUI.menuControl.addEventListener('mousemove', GuacamoleUI.startMenuOpenDetect, true);
397
398     var long_press_start_x = 0;
399     var long_press_start_y = 0;
400     var menuShowLongPressTimeout = null;
401
402     GuacamoleUI.startLongPressDetect = function() {
403
404         if (!menuShowLongPressTimeout) {
405
406             menuShowLongPressTimeout = window.setTimeout(function() {
407                 
408                 menuShowLongPressTimeout = null;
409
410                 // Assume native OSK if menu shown via long-press
411                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_NATIVE;
412                 GuacamoleUI.showTouchMenu();
413
414             }, GuacamoleUI.LONG_PRESS_DETECT_TIMEOUT);
415
416         }
417     };
418
419     GuacamoleUI.stopLongPressDetect = function() {
420         window.clearTimeout(menuShowLongPressTimeout);
421         menuShowLongPressTimeout = null;
422     };
423
424     // Detect long-press at bottom of screen
425     GuacamoleUI.display.addEventListener('touchstart', function(e) {
426         
427         // Close menu if shown
428         GuacamoleUI.shadeMenu();
429         GuacamoleUI.hideTouchMenu();
430         GuacamoleUI.hideTouchClipboard();
431         
432         // Record touch location
433         if (e.touches.length == 1) {
434             var touch = e.touches[0];
435             long_press_start_x = touch.screenX;
436             long_press_start_y = touch.screenY;
437         }
438         
439         // Start detection
440         GuacamoleUI.startLongPressDetect();
441         
442     }, true);
443
444     // Stop detection if touch moves significantly
445     GuacamoleUI.display.addEventListener('touchmove', function(e) {
446         
447         // If touch distance from start exceeds threshold, cancel long press
448         var touch = e.touches[0];
449         if (Math.abs(touch.screenX - long_press_start_x) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD
450             || Math.abs(touch.screenY - long_press_start_y) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD)
451             GuacamoleUI.stopLongPressDetect();
452         
453     }, true);
454
455     // Stop detection if press stops
456     GuacamoleUI.display.addEventListener('touchend', GuacamoleUI.stopLongPressDetect, true);
457
458     // Close menu on mouse movement
459     GuacamoleUI.display.addEventListener('mousemove', GuacamoleUI.startMenuCloseDetect, true);
460     GuacamoleUI.display.addEventListener('mousedown', GuacamoleUI.startMenuCloseDetect, true);
461
462     // Reconnect button
463     GuacamoleUI.buttons.reconnect.onclick = function() {
464         window.location.reload();
465     };
466
467     // On-screen keyboard
468     GuacamoleUI.keyboard = new Guacamole.OnScreenKeyboard("layouts/en-us-qwerty.xml");
469     GuacamoleUI.containers.keyboard.appendChild(GuacamoleUI.keyboard.getElement());
470
471     // Function for automatically updating keyboard size
472     var lastKeyboardWidth;
473     function updateKeyboardSize() {
474         var currentSize = GuacamoleUI.keyboard.getElement().offsetWidth;
475         if (lastKeyboardWidth != currentSize) {
476             GuacamoleUI.keyboard.resize(currentSize);
477             lastKeyboardWidth = currentSize;
478         }
479     };
480
481     // Turn off autocorrect and autocapitalization on eventTarget
482     GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
483     GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
484
485     // Automatically reposition event target on scroll
486     window.addEventListener("scroll", function() {
487         GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
488         GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
489     });
490
491 })();
492
493 // Tie UI events / behavior to a specific Guacamole client
494 GuacamoleUI.attach = function(guac) {
495
496     var title_prefix = null;
497     var connection_name = "Guacamole"; 
498     
499     var guac_display = guac.getDisplay();
500
501     // Set document title appropriately, based on prefix and connection name
502     function updateTitle() {
503
504         // Use title prefix if present
505         if (title_prefix) {
506             
507             document.title = title_prefix;
508
509             // Include connection name, if present
510             if (connection_name)
511                 document.title += " " + connection_name;
512
513         }
514
515         // Otherwise, just set to connection name
516         else if (connection_name)
517             document.title = connection_name;
518
519     }
520
521     // When mouse enters display, start detection of intent to close menu
522     guac_display.addEventListener('mouseover', GuacamoleUI.startMenuCloseDetect, true);
523
524     guac_display.onclick = function(e) {
525         e.preventDefault();
526         return false;
527     };
528
529     // Mouse
530     var mouse = new Guacamole.Mouse(guac_display);
531     var touch = new Guacamole.Mouse.Touchpad(guac_display);
532     touch.onmousedown = touch.onmouseup = touch.onmousemove =
533     mouse.onmousedown = mouse.onmouseup = mouse.onmousemove =
534         function(mouseState) {
535        
536             // Determine mouse position within view
537             var mouse_view_x = mouseState.x + guac_display.offsetLeft - window.pageXOffset;
538             var mouse_view_y = mouseState.y + guac_display.offsetTop  - window.pageYOffset;
539
540             // Determine viewport dimensioins
541             var view_width  = GuacamoleUI.viewport.offsetWidth;
542             var view_height = GuacamoleUI.viewport.offsetHeight;
543
544             // Determine scroll amounts based on mouse position relative to document
545
546             var scroll_amount_x;
547             if (mouse_view_x > view_width)
548                 scroll_amount_x = mouse_view_x - view_width;
549             else if (mouse_view_x < 0)
550                 scroll_amount_x = mouse_view_x;
551             else
552                 scroll_amount_x = 0;
553
554             var scroll_amount_y;
555             if (mouse_view_y > view_height)
556                 scroll_amount_y = mouse_view_y - view_height;
557             else if (mouse_view_y < 0)
558                 scroll_amount_y = mouse_view_y;
559             else
560                 scroll_amount_y = 0;
561
562             // Scroll (if necessary) to keep mouse on screen.
563             window.scrollBy(scroll_amount_x, scroll_amount_y);
564        
565             // Send mouse event
566             guac.sendMouseState(mouseState);
567             
568         };
569
570     // Keyboard
571     var keyboard = new Guacamole.Keyboard(document);
572
573     // Monitor whether the event target is focused
574     var eventTargetFocused = false;
575
576     // Save length for calculation of changed value
577     var currentLength = GuacamoleUI.eventTarget.value.length;
578
579     GuacamoleUI.eventTarget.onfocus = function() {
580         eventTargetFocused = true;
581         GuacamoleUI.eventTarget.value = "";
582         currentLength = 0;
583     };
584
585     GuacamoleUI.eventTarget.onblur = function() {
586         eventTargetFocused = false;
587     };
588
589     // If text is input directly into event target without typing (as with
590     // voice input, for example), type automatically.
591     GuacamoleUI.eventTarget.oninput = function(e) {
592
593         // Calculate current length and change in length
594         var oldLength = currentLength;
595         currentLength = GuacamoleUI.eventTarget.value.length;
596         
597         // If deleted or replaced text, ignore
598         if (currentLength <= oldLength)
599             return;
600
601         // Get changed text
602         var text = GuacamoleUI.eventTarget.value.substring(oldLength);
603
604         // Send each character
605         for (var i=0; i<text.length; i++) {
606
607             // Get char code
608             var charCode = text.charCodeAt(i);
609
610             // Convert to keysym
611             var keysym = 0x003F; // Default to a question mark
612             if (charCode >= 0x0000 && charCode <= 0x00FF)
613                 keysym = charCode;
614             else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
615                 keysym = 0x01000000 | charCode;
616
617             // Send keysym only if not already pressed
618             if (!keyboard.pressed[keysym]) {
619
620                 // Press and release key
621                 guac.sendKeyEvent(1, keysym);
622                 guac.sendKeyEvent(0, keysym);
623
624             }
625
626         }
627
628     }
629
630     function isTypableCharacter(keysym) {
631         return (keysym & 0xFFFF00) != 0xFF00;
632     }
633
634     function disableKeyboard() {
635         keyboard.onkeydown = null;
636         keyboard.onkeyup = null;
637     }
638
639     function enableKeyboard() {
640
641         keyboard.onkeydown = function (keysym) {
642             guac.sendKeyEvent(1, keysym);
643             return eventTargetFocused && isTypableCharacter(keysym);
644         };
645
646         keyboard.onkeyup = function (keysym) {
647             guac.sendKeyEvent(0, keysym);
648             return eventTargetFocused && isTypableCharacter(keysym);
649         };
650
651     }
652
653     // Enable keyboard by default
654     enableKeyboard();
655
656     // Handle client state change
657     guac.onstatechange = function(clientState) {
658
659         switch (clientState) {
660
661             // Idle
662             case 0:
663                 GuacamoleUI.showStatus("Idle.");
664                 title_prefix = "[Idle]";
665                 break;
666
667             // Connecting
668             case 1:
669                 GuacamoleUI.shadeMenu();
670                 GuacamoleUI.showStatus("Connecting...");
671                 title_prefix = "[Connecting...]";
672                 break;
673
674             // Connected + waiting
675             case 2:
676                 GuacamoleUI.showStatus("Connected, waiting for first update...");
677                 title_prefix = "[Waiting...]";
678                 break;
679
680             // Connected
681             case 3:
682                 GuacamoleUI.hideStatus();
683                 title_prefix = null;
684                 break;
685
686             // Disconnecting
687             case 4:
688                 GuacamoleUI.showStatus("Disconnecting...");
689                 title_prefix = "[Disconnecting...]";
690                 break;
691
692             // Disconnected
693             case 5:
694                 GuacamoleUI.showStatus("Disconnected.");
695                 title_prefix = "[Disconnected]";
696                 break;
697
698             // Unknown status code
699             default:
700                 GuacamoleUI.showStatus("[UNKNOWN STATUS]");
701
702         }
703
704         updateTitle();
705     };
706
707     // Name instruction handler
708     guac.onname = function(name) {
709         connection_name = name;
710         updateTitle();
711     };
712
713     // Error handler
714     guac.onerror = function(error) {
715
716         // Disconnect, if connected
717         guac.disconnect();
718
719         // Display error message
720         GuacamoleUI.showError(error);
721         
722     };
723
724     // Disconnect on close
725     window.onunload = function() {
726         guac.disconnect();
727     };
728
729     // Handle clipboard events
730     GuacamoleUI.clipboard.onchange = function() {
731
732         var text = GuacamoleUI.clipboard.value;
733         GuacamoleUI.touchClipboard.value = text;
734         guac.setClipboard(text);
735
736     };
737
738     GuacamoleUI.touchClipboard.onchange = function() {
739
740         var text = GuacamoleUI.touchClipboard.value;
741         GuacamoleUI.clipboard.value = text;
742         guac.setClipboard(text);
743
744     };
745
746     // Ignore keypresses when clipboard is focused
747     GuacamoleUI.clipboard.onfocus =
748     GuacamoleUI.touchClipboard.onfocus = function() {
749         disableKeyboard();
750     };
751
752     // Capture keypresses when clipboard is not focused
753     GuacamoleUI.clipboard.onblur =
754     GuacamoleUI.touchClipboard.onblur = function() {
755         enableKeyboard();
756     };
757
758     // Server copy handler
759     guac.onclipboard = function(data) {
760         GuacamoleUI.clipboard.value = data;
761         GuacamoleUI.touchClipboard.value = data;
762     };
763
764     GuacamoleUI.keyboard.onkeydown = function(keysym) {
765         guac.sendKeyEvent(1, keysym);
766     };
767
768     GuacamoleUI.keyboard.onkeyup = function(keysym) {
769         guac.sendKeyEvent(0, keysym);
770     };
771
772     // Send Ctrl-Alt-Delete
773     GuacamoleUI.buttons.ctrlAltDelete.onclick = function() {
774
775         var KEYSYM_CTRL   = 0xFFE3;
776         var KEYSYM_ALT    = 0xFFE9;
777         var KEYSYM_DELETE = 0xFFFF;
778
779         guac.sendKeyEvent(1, KEYSYM_CTRL);
780         guac.sendKeyEvent(1, KEYSYM_ALT);
781         guac.sendKeyEvent(1, KEYSYM_DELETE);
782         guac.sendKeyEvent(0, KEYSYM_DELETE);
783         guac.sendKeyEvent(0, KEYSYM_ALT);
784         guac.sendKeyEvent(0, KEYSYM_CTRL);
785     };
786
787 };