Clipboard which can be activated/used from within the touch menu.
[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.containers.touchClipboard.style.visibility = "hidden";
168     };
169
170     GuacamoleUI.showTouchClipboard = function() {
171         positionCentered(GuacamoleUI.containers.touchClipboard);
172         GuacamoleUI.containers.touchClipboard.style.visibility = "visible";
173     };
174
175     GuacamoleUI.shadeMenu = function() {
176
177         if (!menu_shaded) {
178
179             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHADE_STEPS) + 1;
180             var offset = 0;
181             menu_shaded = true;
182
183             window.clearInterval(show_interval);
184             shade_interval = window.setInterval(function() {
185
186                 offset -= step;
187
188                 GuacamoleUI.menu.style.transform =
189                 GuacamoleUI.menu.style.WebkitTransform =
190                 GuacamoleUI.menu.style.MozTransform =
191                 GuacamoleUI.menu.style.OTransform =
192                 GuacamoleUI.menu.style.msTransform =
193
194                     "translateY(" + offset + "px)";
195
196                 if (offset <= -GuacamoleUI.menu.offsetHeight) {
197                     window.clearInterval(shade_interval);
198                     GuacamoleUI.menu.style.visiblity = "hidden";
199                 }
200
201             }, GuacamoleUI.MENU_SHADE_INTERVAL);
202         }
203
204     };
205
206     GuacamoleUI.showMenu = function() {
207
208         if (menu_shaded) {
209
210             var step = Math.floor(GuacamoleUI.menu.offsetHeight / GuacamoleUI.MENU_SHOW_STEPS) + 1;
211             var offset = -GuacamoleUI.menu.offsetHeight;
212             menu_shaded = false;
213             GuacamoleUI.menu.style.visiblity = "";
214
215             window.clearInterval(shade_interval);
216             show_interval = window.setInterval(function() {
217
218                 offset += step;
219
220                 if (offset >= 0) {
221                     offset = 0;
222                     window.clearInterval(show_interval);
223                 }
224
225                 GuacamoleUI.menu.style.transform =
226                 GuacamoleUI.menu.style.WebkitTransform =
227                 GuacamoleUI.menu.style.MozTransform =
228                 GuacamoleUI.menu.style.OTransform =
229                 GuacamoleUI.menu.style.msTransform =
230
231                     "translateY(" + offset + "px)";
232
233             }, GuacamoleUI.MENU_SHOW_INTERVAL);
234         }
235
236     };
237
238     // Show/Hide clipboard
239     GuacamoleUI.buttons.showClipboard.onclick = function() {
240
241         var displayed = GuacamoleUI.containers.clipboard.style.display;
242         if (displayed != "block") {
243             GuacamoleUI.containers.clipboard.style.display = "block";
244             GuacamoleUI.buttons.showClipboard.innerHTML = "Hide Clipboard";
245         }
246         else {
247             GuacamoleUI.containers.clipboard.style.display = "none";
248             GuacamoleUI.buttons.showClipboard.innerHTML = "Show Clipboard";
249             GuacamoleUI.clipboard.onchange();
250         }
251
252     };
253
254     GuacamoleUI.buttons.touchShowClipboard.onclick = function() {
255         GuacamoleUI.hideTouchMenu();
256         GuacamoleUI.showTouchClipboard();
257     };
258
259     // Show/Hide keyboard
260     var keyboardResizeInterval = null;
261     GuacamoleUI.buttons.showKeyboard.onclick = function() {
262
263         // If Guac OSK shown, hide it.
264         var displayed = GuacamoleUI.containers.keyboard.style.display;
265         if (displayed == "block") {
266             GuacamoleUI.containers.keyboard.style.display = "none";
267             GuacamoleUI.buttons.showKeyboard.textContent = "Show Keyboard";
268
269             window.onresize = null;
270             window.clearInterval(keyboardResizeInterval);
271         }
272
273         // Otherwise, show it
274         else {
275
276             // Ensure event target is NOT focused if we are using the Guac OSK.
277             GuacamoleUI.eventTarget.blur();
278
279             GuacamoleUI.containers.keyboard.style.display = "block";
280             GuacamoleUI.buttons.showKeyboard.textContent = "Hide Keyboard";
281
282             // Automatically update size
283             window.onresize = updateKeyboardSize;
284             keyboardResizeInterval = window.setInterval(updateKeyboardSize,
285                 GuacamoleUI.KEYBOARD_AUTO_RESIZE_INTERVAL);
286
287             updateKeyboardSize();
288
289         }
290
291     };
292
293     // Touch-specific keyboard show
294     GuacamoleUI.buttons.touchShowKeyboard.onclick = 
295         function(e) {
296
297             // Center event target in case browser automatically centers
298             // input fields on focus.
299             GuacamoleUI.eventTarget.style.left =
300                 (window.pageXOffset + GuacamoleUI.viewport.offsetWidth / 2) + "px";
301
302             GuacamoleUI.eventTarget.style.top =
303                 (window.pageYOffset + GuacamoleUI.viewport.offsetHeight / 2) + "px";
304
305             GuacamoleUI.eventTarget.focus();
306             GuacamoleUI.hideTouchMenu();
307
308         };
309
310     // Logout
311     GuacamoleUI.buttons.logout.onclick =
312     GuacamoleUI.buttons.touchLogout.onclick =
313         function() {
314
315             // Logout after warning user about session disconnect
316             if (confirm(GuacamoleUI.LOGOUT_PROMPT)) {
317                 window.location.href = "logout";
318                 GuacamoleUI.hideTouchMenu();
319             }
320             
321         };
322
323     // Timeouts for detecting if users wants menu to open or close
324     var detectMenuOpenTimeout = null;
325     var detectMenuCloseTimeout = null;
326
327     // Clear detection timeouts
328     GuacamoleUI.resetMenuDetect = function() {
329
330         if (detectMenuOpenTimeout != null) {
331             window.clearTimeout(detectMenuOpenTimeout);
332             detectMenuOpenTimeout = null;
333         }
334
335         if (detectMenuCloseTimeout != null) {
336             window.clearTimeout(detectMenuCloseTimeout);
337             detectMenuCloseTimeout = null;
338         }
339
340     };
341
342     // Initiate detection of menu open action. If not canceled through some
343     // user event, menu will open.
344     GuacamoleUI.startMenuOpenDetect = function() {
345
346         if (!detectMenuOpenTimeout) {
347
348             // Clear detection state
349             GuacamoleUI.resetMenuDetect();
350
351             // Wait and then show menu
352             detectMenuOpenTimeout = window.setTimeout(function() {
353
354                 // If menu opened via mouse, do not show native OSK
355                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_GUAC;
356
357                 GuacamoleUI.showMenu();
358                 detectMenuOpenTimeout = null;
359             }, GuacamoleUI.MENU_OPEN_DETECT_TIMEOUT);
360
361         }
362
363     };
364
365     // Initiate detection of menu close action. If not canceled through some
366     // user mouse event, menu will close.
367     GuacamoleUI.startMenuCloseDetect = function() {
368
369         if (!detectMenuCloseTimeout) {
370
371             // Clear detection state
372             GuacamoleUI.resetMenuDetect();
373
374             // Wait and then shade menu
375             detectMenuCloseTimeout = window.setTimeout(function() {
376                 GuacamoleUI.shadeMenu();
377                 detectMenuCloseTimeout = null;
378             }, GuacamoleUI.MENU_CLOSE_DETECT_TIMEOUT);
379
380         }
381
382     };
383
384     // Show menu if mouseover any part of menu
385     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.showMenu, true);
386
387     // Stop detecting menu state change intents if mouse is over menu
388     GuacamoleUI.menu.addEventListener('mouseover', GuacamoleUI.resetMenuDetect, true);
389
390     // When mouse hovers over top of screen, start detection of intent to open menu
391     GuacamoleUI.menuControl.addEventListener('mousemove', GuacamoleUI.startMenuOpenDetect, true);
392
393     var long_press_start_x = 0;
394     var long_press_start_y = 0;
395     var menuShowLongPressTimeout = null;
396
397     GuacamoleUI.startLongPressDetect = function() {
398
399         if (!menuShowLongPressTimeout) {
400
401             menuShowLongPressTimeout = window.setTimeout(function() {
402                 
403                 menuShowLongPressTimeout = null;
404
405                 // Assume native OSK if menu shown via long-press
406                 GuacamoleUI.oskMode = GuacamoleUI.OSK_MODE_NATIVE;
407                 GuacamoleUI.showTouchMenu();
408
409             }, GuacamoleUI.LONG_PRESS_DETECT_TIMEOUT);
410
411         }
412     };
413
414     GuacamoleUI.stopLongPressDetect = function() {
415         window.clearTimeout(menuShowLongPressTimeout);
416         menuShowLongPressTimeout = null;
417     };
418
419     // Detect long-press at bottom of screen
420     GuacamoleUI.display.addEventListener('touchstart', function(e) {
421         
422         // Close menu if shown
423         GuacamoleUI.shadeMenu();
424         GuacamoleUI.hideTouchMenu();
425         GuacamoleUI.hideTouchClipboard();
426         
427         // Record touch location
428         if (e.touches.length == 1) {
429             var touch = e.touches[0];
430             long_press_start_x = touch.screenX;
431             long_press_start_y = touch.screenY;
432         }
433         
434         // Start detection
435         GuacamoleUI.startLongPressDetect();
436         
437     }, true);
438
439     // Stop detection if touch moves significantly
440     GuacamoleUI.display.addEventListener('touchmove', function(e) {
441         
442         // If touch distance from start exceeds threshold, cancel long press
443         var touch = e.touches[0];
444         if (Math.abs(touch.screenX - long_press_start_x) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD
445             || Math.abs(touch.screenY - long_press_start_y) >= GuacamoleUI.LONG_PRESS_MOVEMENT_THRESHOLD)
446             GuacamoleUI.stopLongPressDetect();
447         
448     }, true);
449
450     // Stop detection if press stops
451     GuacamoleUI.display.addEventListener('touchend', GuacamoleUI.stopLongPressDetect, true);
452
453     // Close menu on mouse movement
454     GuacamoleUI.display.addEventListener('mousemove', GuacamoleUI.startMenuCloseDetect, true);
455     GuacamoleUI.display.addEventListener('mousedown', GuacamoleUI.startMenuCloseDetect, true);
456
457     // Reconnect button
458     GuacamoleUI.buttons.reconnect.onclick = function() {
459         window.location.reload();
460     };
461
462     // On-screen keyboard
463     GuacamoleUI.keyboard = new Guacamole.OnScreenKeyboard("layouts/en-us-qwerty-mobile.xml");
464     GuacamoleUI.containers.keyboard.appendChild(GuacamoleUI.keyboard.getElement());
465
466     // Function for automatically updating keyboard size
467     var lastKeyboardWidth;
468     function updateKeyboardSize() {
469         var currentSize = GuacamoleUI.keyboard.getElement().offsetWidth;
470         if (lastKeyboardWidth != currentSize) {
471             GuacamoleUI.keyboard.resize(currentSize);
472             lastKeyboardWidth = currentSize;
473         }
474     };
475
476     // Turn off autocorrect and autocapitalization on eventTarget
477     GuacamoleUI.eventTarget.setAttribute("autocorrect", "off");
478     GuacamoleUI.eventTarget.setAttribute("autocapitalize", "off");
479
480     // Automatically reposition event target on scroll
481     window.addEventListener("scroll", function() {
482         GuacamoleUI.eventTarget.style.left = window.pageXOffset + "px";
483         GuacamoleUI.eventTarget.style.top = window.pageYOffset + "px";
484     });
485
486 })();
487
488 // Tie UI events / behavior to a specific Guacamole client
489 GuacamoleUI.attach = function(guac) {
490
491     var title_prefix = null;
492     var connection_name = "Guacamole"; 
493     
494     var guac_display = guac.getDisplay();
495
496     // Set document title appropriately, based on prefix and connection name
497     function updateTitle() {
498
499         // Use title prefix if present
500         if (title_prefix) {
501             
502             document.title = title_prefix;
503
504             // Include connection name, if present
505             if (connection_name)
506                 document.title += " " + connection_name;
507
508         }
509
510         // Otherwise, just set to connection name
511         else if (connection_name)
512             document.title = connection_name;
513
514     }
515
516     // When mouse enters display, start detection of intent to close menu
517     guac_display.addEventListener('mouseover', GuacamoleUI.startMenuCloseDetect, true);
518
519     guac_display.onclick = function(e) {
520         e.preventDefault();
521         return false;
522     };
523
524     // Mouse
525     var mouse = new Guacamole.Mouse(guac_display);
526     mouse.onmousedown = mouse.onmouseup = mouse.onmousemove =
527         function(mouseState) {
528        
529             // Determine mouse position within view
530             var mouse_view_x = mouseState.x + guac_display.offsetLeft - window.pageXOffset;
531             var mouse_view_y = mouseState.y + guac_display.offsetTop  - window.pageYOffset;
532
533             // Determine viewport dimensioins
534             var view_width  = GuacamoleUI.viewport.offsetWidth;
535             var view_height = GuacamoleUI.viewport.offsetHeight;
536
537             // Determine scroll amounts based on mouse position relative to document
538
539             var scroll_amount_x;
540             if (mouse_view_x > view_width)
541                 scroll_amount_x = mouse_view_x - view_width;
542             else if (mouse_view_x < 0)
543                 scroll_amount_x = mouse_view_x;
544             else
545                 scroll_amount_x = 0;
546
547             var scroll_amount_y;
548             if (mouse_view_y > view_height)
549                 scroll_amount_y = mouse_view_y - view_height;
550             else if (mouse_view_y < 0)
551                 scroll_amount_y = mouse_view_y;
552             else
553                 scroll_amount_y = 0;
554
555             // Scroll (if necessary) to keep mouse on screen.
556             window.scrollBy(scroll_amount_x, scroll_amount_y);
557        
558             // Send mouse event
559             guac.sendMouseState(mouseState);
560             
561         };
562
563     // Keyboard
564     var keyboard = new Guacamole.Keyboard(document);
565
566     // Monitor whether the event target is focused
567     var eventTargetFocused = false;
568
569     // Save length for calculation of changed value
570     var currentLength = GuacamoleUI.eventTarget.value.length;
571
572     GuacamoleUI.eventTarget.onfocus = function() {
573         eventTargetFocused = true;
574         GuacamoleUI.eventTarget.value = "";
575         currentLength = 0;
576     };
577
578     GuacamoleUI.eventTarget.onblur = function() {
579         eventTargetFocused = false;
580     };
581
582     // If text is input directly into event target without typing (as with
583     // voice input, for example), type automatically.
584     GuacamoleUI.eventTarget.oninput = function(e) {
585
586         // Calculate current length and change in length
587         var oldLength = currentLength;
588         currentLength = GuacamoleUI.eventTarget.value.length;
589         
590         // If deleted or replaced text, ignore
591         if (currentLength <= oldLength)
592             return;
593
594         // Get changed text
595         var text = GuacamoleUI.eventTarget.value.substring(oldLength);
596
597         // Send each character
598         for (var i=0; i<text.length; i++) {
599
600             // Get char code
601             var charCode = text.charCodeAt(i);
602
603             // Convert to keysym
604             var keysym = 0x003F; // Default to a question mark
605             if (charCode >= 0x0000 && charCode <= 0x00FF)
606                 keysym = charCode;
607             else if (charCode >= 0x0100 && charCode <= 0x10FFFF)
608                 keysym = 0x01000000 | charCode;
609
610             // Send keysym only if not already pressed
611             if (!keyboard.pressed[keysym]) {
612
613                 // Press and release key
614                 guac.sendKeyEvent(1, keysym);
615                 guac.sendKeyEvent(0, keysym);
616
617             }
618
619         }
620
621     }
622
623     function isTypableCharacter(keysym) {
624         return (keysym & 0xFFFF00) != 0xFF00;
625     }
626
627     function disableKeyboard() {
628         keyboard.onkeydown = null;
629         keyboard.onkeyup = null;
630     }
631
632     function enableKeyboard() {
633
634         keyboard.onkeydown = function (keysym) {
635             guac.sendKeyEvent(1, keysym);
636             return eventTargetFocused && isTypableCharacter(keysym);
637         };
638
639         keyboard.onkeyup = function (keysym) {
640             guac.sendKeyEvent(0, keysym);
641             return eventTargetFocused && isTypableCharacter(keysym);
642         };
643
644     }
645
646     // Enable keyboard by default
647     enableKeyboard();
648
649     // Handle client state change
650     guac.onstatechange = function(clientState) {
651
652         switch (clientState) {
653
654             // Idle
655             case 0:
656                 GuacamoleUI.showStatus("Idle.");
657                 title_prefix = "[Idle]";
658                 break;
659
660             // Connecting
661             case 1:
662                 GuacamoleUI.shadeMenu();
663                 GuacamoleUI.showStatus("Connecting...");
664                 title_prefix = "[Connecting...]";
665                 break;
666
667             // Connected + waiting
668             case 2:
669                 GuacamoleUI.showStatus("Connected, waiting for first update...");
670                 title_prefix = "[Waiting...]";
671                 break;
672
673             // Connected
674             case 3:
675                 GuacamoleUI.hideStatus();
676                 title_prefix = null;
677                 break;
678
679             // Disconnecting
680             case 4:
681                 GuacamoleUI.showStatus("Disconnecting...");
682                 title_prefix = "[Disconnecting...]";
683                 break;
684
685             // Disconnected
686             case 5:
687                 GuacamoleUI.showStatus("Disconnected.");
688                 title_prefix = "[Disconnected]";
689                 break;
690
691             // Unknown status code
692             default:
693                 GuacamoleUI.showStatus("[UNKNOWN STATUS]");
694
695         }
696
697         updateTitle();
698     };
699
700     // Name instruction handler
701     guac.onname = function(name) {
702         connection_name = name;
703         updateTitle();
704     };
705
706     // Error handler
707     guac.onerror = function(error) {
708
709         // Disconnect, if connected
710         guac.disconnect();
711
712         // Display error message
713         GuacamoleUI.showError(error);
714         
715     };
716
717     // Disconnect on close
718     window.onunload = function() {
719         guac.disconnect();
720     };
721
722     // Handle clipboard events
723     GuacamoleUI.clipboard.onchange = function() {
724
725         var text = GuacamoleUI.clipboard.value;
726         GuacamoleUI.touchClipboard.value = text;
727         guac.setClipboard(text);
728
729     };
730
731     GuacamoleUI.touchClipboard.onchange = function() {
732
733         var text = GuacamoleUI.touchClipboard.value;
734         GuacamoleUI.clipboard.value = text;
735         guac.setClipboard(text);
736
737     };
738
739     // Ignore keypresses when clipboard is focused
740     GuacamoleUI.clipboard.onfocus =
741     GuacamoleUI.touchClipboard.onfocus = function() {
742         disableKeyboard();
743     };
744
745     // Capture keypresses when clipboard is not focused
746     GuacamoleUI.clipboard.onblur =
747     GuacamoleUI.touchClipboard.onblur = function() {
748         enableKeyboard();
749     };
750
751     // Server copy handler
752     guac.onclipboard = function(data) {
753         GuacamoleUI.clipboard.value = data;
754         GuacamoleUI.touchClipboard.value = data;
755     };
756
757     GuacamoleUI.keyboard.onkeydown = function(keysym) {
758         guac.sendKeyEvent(1, keysym);
759     };
760
761     GuacamoleUI.keyboard.onkeyup = function(keysym) {
762         guac.sendKeyEvent(0, keysym);
763     };
764
765     // Send Ctrl-Alt-Delete
766     GuacamoleUI.buttons.ctrlAltDelete.onclick = function() {
767
768         var KEYSYM_CTRL   = 0xFFE3;
769         var KEYSYM_ALT    = 0xFFE9;
770         var KEYSYM_DELETE = 0xFFFF;
771
772         guac.sendKeyEvent(1, KEYSYM_CTRL);
773         guac.sendKeyEvent(1, KEYSYM_ALT);
774         guac.sendKeyEvent(1, KEYSYM_DELETE);
775         guac.sendKeyEvent(0, KEYSYM_DELETE);
776         guac.sendKeyEvent(0, KEYSYM_ALT);
777         guac.sendKeyEvent(0, KEYSYM_CTRL);
778     };
779
780 };