b1f3f23c66a51ca39a3855ae62c2b1598f2f7908
[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                 window.location.href = "logout";
319                 GuacamoleUI.hideTouchMenu();
320             }
321             
322         };
323
324     // Timeouts for detecting if users wants menu to open or close
325     var detectMenuOpenTimeout = null;
326     var detectMenuCloseTimeout = null;
327
328     // Clear detection timeouts
329     GuacamoleUI.resetMenuDetect = function() {
330
331         if (detectMenuOpenTimeout != null) {
332             window.clearTimeout(detectMenuOpenTimeout);
333             detectMenuOpenTimeout = null;
334         }
335
336         if (detectMenuCloseTimeout != null) {
337             window.clearTimeout(detectMenuCloseTimeout);
338             detectMenuCloseTimeout = null;
339         }
340
341     };
342
343     // Initiate detection of menu open action. If not canceled through some
344     // user event, menu will open.
345     GuacamoleUI.startMenuOpenDetect = function() {
346
347         if (!detectMenuOpenTimeout) {
348
349             // Clear detection state
350             GuacamoleUI.resetMenuDetect();
351
352             // Wait and then show menu
353             detectMenuOpenTimeout = window.setTimeout(function() {
354
355                 // If menu opened via mouse, do not show native OSK
356                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_GUAC;
357
358                 GuacamoleUI.showMenu();
359                 detectMenuOpenTimeout = null;
360             }, GuacamoleUI.MENU_OPEN_DETECT_TIMEOUT);
361
362         }
363
364     };
365
366     // Initiate detection of menu close action. If not canceled through some
367     // user mouse event, menu will close.
368     GuacamoleUI.startMenuCloseDetect = function() {
369
370         if (!detectMenuCloseTimeout) {
371
372             // Clear detection state
373             GuacamoleUI.resetMenuDetect();
374
375             // Wait and then shade menu
376             detectMenuCloseTimeout = window.setTimeout(function() {
377                 GuacamoleUI.shadeMenu();
378                 detectMenuCloseTimeout = null;
379             }, GuacamoleUI.MENU_CLOSE_DETECT_TIMEOUT);
380
381         }
382
383     };
384
385     // Show menu if mouseover any part of menu
386     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.showMenu, true);
387
388     // Stop detecting menu state change intents if mouse is over menu
389     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.resetMenuDetect, true);
390
391     // When mouse hovers over top of screen, start detection of intent to open menu
392     GuacamoleUI.menuControl.addEventListener('mousemove', GuacamoleUI.startMenuOpenDetect, true);
393
394     var long_press_start_x = 0;
395     var long_press_start_y = 0;
396     var menuShowLongPressTimeout = null;
397
398     GuacamoleUI.startLongPressDetect = function() {
399
400         if (!menuShowLongPressTimeout) {
401
402             menuShowLongPressTimeout = window.setTimeout(function() {
403                 
404                 menuShowLongPressTimeout = null;
405
406                 // Assume native OSK if menu shown via long-press
407                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_NATIVE;
408                 GuacamoleUI.showTouchMenu();
409
410             }, GuacamoleUI.LONG_PRESS_DETECT_TIMEOUT);
411
412         }
413     };
414
415     GuacamoleUI.stopLongPressDetect = function() {
416         window.clearTimeout(menuShowLongPressTimeout);
417         menuShowLongPressTimeout = null;
418     };
419
420     // Detect long-press at bottom of screen
421     GuacamoleUI.display.addEventListener('touchstart', function(e) {
422         
423         // Close menu if shown
424         GuacamoleUI.shadeMenu();
425         GuacamoleUI.hideTouchMenu();
426         GuacamoleUI.hideTouchClipboard();
427         
428         // Record touch location
429         if (e.touches.length == 1) {
430             var touch = e.touches[0];
431             long_press_start_x = touch.screenX;
432             long_press_start_y = touch.screenY;
433         }
434         
435         // Start detection
436         GuacamoleUI.startLongPressDetect();
437         
438     }, true);
439
440     // Stop detection if touch moves significantly
441     GuacamoleUI.display.addEventListener('touchmove', function(e) {
442         
443         // If touch distance from start exceeds threshold, cancel long press
444         var touch = e.touches[0];
445         if (Math.abs(touch.screenX - long_press_start_x) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD
446             || Math.abs(touch.screenY - long_press_start_y) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD)
447             GuacamoleUI.stopLongPressDetect();
448         
449     }, true);
450
451     // Stop detection if press stops
452     GuacamoleUI.display.addEventListener('touchend', GuacamoleUI.stopLongPressDetect, true);
453
454     // Close menu on mouse movement
455     GuacamoleUI.display.addEventListener('mousemove', GuacamoleUI.startMenuCloseDetect, true);
456     GuacamoleUI.display.addEventListener('mousedown', GuacamoleUI.startMenuCloseDetect, true);
457
458     // Reconnect button
459     GuacamoleUI.buttons.reconnect.onclick = function() {
460         window.location.reload();
461     };
462
463     // On-screen keyboard
464     GuacamoleUI.keyboard = new Guacamole.OnScreenKeyboard("layouts/en-us-qwerty.xml");
465     GuacamoleUI.containers.keyboard.appendChild(GuacamoleUI.keyboard.getElement());
466
467     // Function for automatically updating keyboard size
468     var lastKeyboardWidth;
469     function updateKeyboardSize() {
470         var currentSize = GuacamoleUI.keyboard.getElement().offsetWidth;
471         if (lastKeyboardWidth != currentSize) {
472             GuacamoleUI.keyboard.resize(currentSize);
473             lastKeyboardWidth = currentSize;
474         }
475     };
476
477     // Turn off autocorrect and autocapitalization on eventTarget
478     GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
479     GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
480
481     // Automatically reposition event target on scroll
482     window.addEventListener("scroll", function() {
483         GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
484         GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
485     });
486
487 })();
488
489 // Tie UI events / behavior to a specific Guacamole client
490 GuacamoleUI.attach = function(guac) {
491
492     var title_prefix = null;
493     var connection_name = "Guacamole"; 
494     
495     var guac_display = guac.getDisplay();
496
497     // Set document title appropriately, based on prefix and connection name
498     function updateTitle() {
499
500         // Use title prefix if present
501         if (title_prefix) {
502             
503             document.title = title_prefix;
504
505             // Include connection name, if present
506             if (connection_name)
507                 document.title += " " + connection_name;
508
509         }
510
511         // Otherwise, just set to connection name
512         else if (connection_name)
513             document.title = connection_name;
514
515     }
516
517     // When mouse enters display, start detection of intent to close menu
518     guac_display.addEventListener('mouseover', GuacamoleUI.startMenuCloseDetect, true);
519
520     guac_display.onclick = function(e) {
521         e.preventDefault();
522         return false;
523     };
524
525     // Mouse
526     var mouse = new Guacamole.Mouse(guac_display);
527     mouse.onmousedown = mouse.onmouseup = mouse.onmousemove =
528         function(mouseState) {
529        
530             // Determine mouse position within view
531             var mouse_view_x = mouseState.x + guac_display.offsetLeft - window.pageXOffset;
532             var mouse_view_y = mouseState.y + guac_display.offsetTop  - window.pageYOffset;
533
534             // Determine viewport dimensioins
535             var view_width  = GuacamoleUI.viewport.offsetWidth;
536             var view_height = GuacamoleUI.viewport.offsetHeight;
537
538             // Determine scroll amounts based on mouse position relative to document
539
540             var scroll_amount_x;
541             if (mouse_view_x > view_width)
542                 scroll_amount_x = mouse_view_x - view_width;
543             else if (mouse_view_x < 0)
544                 scroll_amount_x = mouse_view_x;
545             else
546                 scroll_amount_x = 0;
547
548             var scroll_amount_y;
549             if (mouse_view_y > view_height)
550                 scroll_amount_y = mouse_view_y - view_height;
551             else if (mouse_view_y < 0)
552                 scroll_amount_y = mouse_view_y;
553             else
554                 scroll_amount_y = 0;
555
556             // Scroll (if necessary) to keep mouse on screen.
557             window.scrollBy(scroll_amount_x, scroll_amount_y);
558        
559             // Send mouse event
560             guac.sendMouseState(mouseState);
561             
562         };
563
564     // Keyboard
565     var keyboard = new Guacamole.Keyboard(document);
566
567     // Monitor whether the event target is focused
568     var eventTargetFocused = false;
569
570     // Save length for calculation of changed value
571     var currentLength = GuacamoleUI.eventTarget.value.length;
572
573     GuacamoleUI.eventTarget.onfocus = function() {
574         eventTargetFocused = true;
575         GuacamoleUI.eventTarget.value = "";
576         currentLength = 0;
577     };
578
579     GuacamoleUI.eventTarget.onblur = function() {
580         eventTargetFocused = false;
581     };
582
583     // If text is input directly into event target without typing (as with
584     // voice input, for example), type automatically.
585     GuacamoleUI.eventTarget.oninput = function(e) {
586
587         // Calculate current length and change in length
588         var oldLength = currentLength;
589         currentLength = GuacamoleUI.eventTarget.value.length;
590         
591         // If deleted or replaced text, ignore
592         if (currentLength <= oldLength)
593             return;
594
595         // Get changed text
596         var text = GuacamoleUI.eventTarget.value.substring(oldLength);
597
598         // Send each character
599         for (var i=0; i<text.length; i++) {
600
601             // Get char code
602             var charCode = text.charCodeAt(i);
603
604             // Convert to keysym
605             var keysym = 0x003F; // Default to a question mark
606             if (charCode >= 0x0000 && charCode <= 0x00FF)
607                 keysym = charCode;
608             else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
609                 keysym = 0x01000000 | charCode;
610
611             // Send keysym only if not already pressed
612             if (!keyboard.pressed[keysym]) {
613
614                 // Press and release key
615                 guac.sendKeyEvent(1, keysym);
616                 guac.sendKeyEvent(0, keysym);
617
618             }
619
620         }
621
622     }
623
624     function isTypableCharacter(keysym) {
625         return (keysym & 0xFFFF00) != 0xFF00;
626     }
627
628     function disableKeyboard() {
629         keyboard.onkeydown = null;
630         keyboard.onkeyup = null;
631     }
632
633     function enableKeyboard() {
634
635         keyboard.onkeydown = function (keysym) {
636             guac.sendKeyEvent(1, keysym);
637             return eventTargetFocused && isTypableCharacter(keysym);
638         };
639
640         keyboard.onkeyup = function (keysym) {
641             guac.sendKeyEvent(0, keysym);
642             return eventTargetFocused && isTypableCharacter(keysym);
643         };
644
645     }
646
647     // Enable keyboard by default
648     enableKeyboard();
649
650     // Handle client state change
651     guac.onstatechange = function(clientState) {
652
653         switch (clientState) {
654
655             // Idle
656             case 0:
657                 GuacamoleUI.showStatus("Idle.");
658                 title_prefix = "[Idle]";
659                 break;
660
661             // Connecting
662             case 1:
663                 GuacamoleUI.shadeMenu();
664                 GuacamoleUI.showStatus("Connecting...");
665                 title_prefix = "[Connecting...]";
666                 break;
667
668             // Connected + waiting
669             case 2:
670                 GuacamoleUI.showStatus("Connected, waiting for first update...");
671                 title_prefix = "[Waiting...]";
672                 break;
673
674             // Connected
675             case 3:
676                 GuacamoleUI.hideStatus();
677                 title_prefix = null;
678                 break;
679
680             // Disconnecting
681             case 4:
682                 GuacamoleUI.showStatus("Disconnecting...");
683                 title_prefix = "[Disconnecting...]";
684                 break;
685
686             // Disconnected
687             case 5:
688                 GuacamoleUI.showStatus("Disconnected.");
689                 title_prefix = "[Disconnected]";
690                 break;
691
692             // Unknown status code
693             default:
694                 GuacamoleUI.showStatus("[UNKNOWN STATUS]");
695
696         }
697
698         updateTitle();
699     };
700
701     // Name instruction handler
702     guac.onname = function(name) {
703         connection_name = name;
704         updateTitle();
705     };
706
707     // Error handler
708     guac.onerror = function(error) {
709
710         // Disconnect, if connected
711         guac.disconnect();
712
713         // Display error message
714         GuacamoleUI.showError(error);
715         
716     };
717
718     // Disconnect on close
719     window.onunload = function() {
720         guac.disconnect();
721     };
722
723     // Handle clipboard events
724     GuacamoleUI.clipboard.onchange = function() {
725
726         var text = GuacamoleUI.clipboard.value;
727         GuacamoleUI.touchClipboard.value = text;
728         guac.setClipboard(text);
729
730     };
731
732     GuacamoleUI.touchClipboard.onchange = function() {
733
734         var text = GuacamoleUI.touchClipboard.value;
735         GuacamoleUI.clipboard.value = text;
736         guac.setClipboard(text);
737
738     };
739
740     // Ignore keypresses when clipboard is focused
741     GuacamoleUI.clipboard.onfocus =
742     GuacamoleUI.touchClipboard.onfocus = function() {
743         disableKeyboard();
744     };
745
746     // Capture keypresses when clipboard is not focused
747     GuacamoleUI.clipboard.onblur =
748     GuacamoleUI.touchClipboard.onblur = function() {
749         enableKeyboard();
750     };
751
752     // Server copy handler
753     guac.onclipboard = function(data) {
754         GuacamoleUI.clipboard.value = data;
755         GuacamoleUI.touchClipboard.value = data;
756     };
757
758     GuacamoleUI.keyboard.onkeydown = function(keysym) {
759         guac.sendKeyEvent(1, keysym);
760     };
761
762     GuacamoleUI.keyboard.onkeyup = function(keysym) {
763         guac.sendKeyEvent(0, keysym);
764     };
765
766     // Send Ctrl-Alt-Delete
767     GuacamoleUI.buttons.ctrlAltDelete.onclick = function() {
768
769         var KEYSYM_CTRL   = 0xFFE3;
770         var KEYSYM_ALT    = 0xFFE9;
771         var KEYSYM_DELETE = 0xFFFF;
772
773         guac.sendKeyEvent(1, KEYSYM_CTRL);
774         guac.sendKeyEvent(1, KEYSYM_ALT);
775         guac.sendKeyEvent(1, KEYSYM_DELETE);
776         guac.sendKeyEvent(0, KEYSYM_DELETE);
777         guac.sendKeyEvent(0, KEYSYM_ALT);
778         guac.sendKeyEvent(0, KEYSYM_CTRL);
779     };
780
781 };