]> git.proxmox.com Git - mirror_novnc.git/blob - app/ui.js
New way of detecting touch
[mirror_novnc.git] / app / ui.js
1 /*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Copyright (C) 2016 Samuel Mannehed for Cendio AB
5 * Copyright (C) 2016 Pierre Ossman for Cendio AB
6 * Licensed under MPL 2.0 (see LICENSE.txt)
7 *
8 * See README.md for usage and integration instructions.
9 */
10
11 /* jslint white: false, browser: true */
12 /* global window, document.getElementById, Util, WebUtil, RFB, Display */
13
14 /* [module]
15 * import Util from "../core/util";
16 * import KeyTable from "../core/input/keysym";
17 * import RFB from "../core/rfb";
18 * import Display from "../core/display";
19 * import WebUtil from "./webutil";
20 */
21
22 var UI;
23
24 (function () {
25 "use strict";
26
27 /* [begin skip-as-module] */
28 // Load supporting scripts
29 WebUtil.load_scripts(
30 {'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js",
31 "input/xtscancodes.js", "input/util.js", "input/devices.js",
32 "display.js", "inflator.js", "rfb.js", "input/keysym.js"]});
33
34 window.onscriptsload = function () { UI.load(); };
35 /* [end skip-as-module] */
36
37 UI = {
38
39 connected: false,
40 desktopName: "",
41
42 resizeTimeout: null,
43 statusTimeout: null,
44 hideKeyboardTimeout: null,
45 idleControlbarTimeout: null,
46 closeControlbarTimeout: null,
47
48 controlbarGrabbed: false,
49 controlbarDrag: false,
50 controlbarMouseDownClientY: 0,
51 controlbarMouseDownOffsetY: 0,
52 keyboardVisible: false,
53
54 isSafari: false,
55 rememberedClipSetting: null,
56 lastKeyboardinput: null,
57 defaultKeyboardinputLen: 100,
58
59 // Setup rfb object, load settings from browser storage, then call
60 // UI.init to setup the UI/menus
61 load: function(callback) {
62 WebUtil.initSettings(UI.start, callback);
63 },
64
65 // Render default UI and initialize settings menu
66 start: function(callback) {
67
68 // Setup global variables first
69 UI.isSafari = (navigator.userAgent.indexOf('Safari') !== -1 &&
70 navigator.userAgent.indexOf('Chrome') === -1);
71
72 UI.initSettings();
73
74 // Adapt the interface for touch screen devices
75 if (Util.isTouchDevice) {
76 document.documentElement.classList.add("noVNC_touch");
77 // Remove the address bar
78 setTimeout(function() { window.scrollTo(0, 1); }, 100);
79 UI.forceSetting('clip', true);
80 } else {
81 UI.initSetting('clip', false);
82 }
83
84 // Setup and initialize event handlers
85 UI.setupWindowEvents();
86 UI.setupFullscreen();
87 UI.addControlbarHandlers();
88 UI.addTouchSpecificHandlers();
89 UI.addExtraKeysHandlers();
90 UI.addXvpHandlers();
91 UI.addConnectionControlHandlers();
92 UI.addClipboardHandlers();
93 UI.addSettingsHandlers();
94
95 // Show the connect panel on first load unless autoconnecting
96 if (!autoconnect) {
97 UI.openConnectPanel();
98 }
99
100 UI.updateViewClip();
101
102 UI.updateVisualState();
103
104 document.getElementById('noVNC_setting_host').focus();
105
106 var autoconnect = WebUtil.getConfigVar('autoconnect', false);
107 if (autoconnect === 'true' || autoconnect == '1') {
108 autoconnect = true;
109 UI.connect();
110 } else {
111 autoconnect = false;
112 }
113
114 if (typeof callback === "function") {
115 callback(UI.rfb);
116 }
117 },
118
119 initSettings: function() {
120 // Stylesheet selection dropdown
121 var sheet = WebUtil.selectStylesheet();
122 var sheets = WebUtil.getStylesheets();
123 var i;
124 for (i = 0; i < sheets.length; i += 1) {
125 UI.addOption(document.getElementById('noVNC_setting_stylesheet'),sheets[i].title, sheets[i].title);
126 }
127
128 // Logging selection dropdown
129 var llevels = ['error', 'warn', 'info', 'debug'];
130 for (i = 0; i < llevels.length; i += 1) {
131 UI.addOption(document.getElementById('noVNC_setting_logging'),llevels[i], llevels[i]);
132 }
133
134 // Settings with immediate effects
135 UI.initSetting('logging', 'warn');
136 WebUtil.init_logging(UI.getSetting('logging'));
137
138 UI.initSetting('stylesheet', 'default');
139 WebUtil.selectStylesheet(null);
140 // call twice to get around webkit bug
141 WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
142
143 // if port == 80 (or 443) then it won't be present and should be
144 // set manually
145 var port = window.location.port;
146 if (!port) {
147 if (window.location.protocol.substring(0,5) == 'https') {
148 port = 443;
149 }
150 else if (window.location.protocol.substring(0,4) == 'http') {
151 port = 80;
152 }
153 }
154
155 /* Populate the controls if defaults are provided in the URL */
156 UI.initSetting('host', window.location.hostname);
157 UI.initSetting('port', port);
158 UI.initSetting('password', '');
159 UI.initSetting('encrypt', (window.location.protocol === "https:"));
160 UI.initSetting('true_color', true);
161 UI.initSetting('cursor', !Util.isTouchDevice);
162 UI.initSetting('resize', 'off');
163 UI.initSetting('shared', true);
164 UI.initSetting('view_only', false);
165 UI.initSetting('path', 'websockify');
166 UI.initSetting('repeaterID', '');
167 UI.initSetting('token', '');
168 },
169
170 setupWindowEvents: function() {
171 window.addEventListener( 'resize', function () {
172 UI.applyResizeMode();
173 UI.updateViewClip();
174 UI.updateViewDrag();
175 } );
176
177 document.getElementById("noVNC_status")
178 .addEventListener('click', UI.hideStatus);
179 },
180
181 setupFullscreen: function() {
182 // Only show the button if fullscreen is properly supported
183 // * Safari doesn't support alphanumerical input while in fullscreen
184 if (!UI.isSafari &&
185 (document.documentElement.requestFullscreen ||
186 document.documentElement.mozRequestFullScreen ||
187 document.documentElement.webkitRequestFullscreen ||
188 document.body.msRequestFullscreen)) {
189 document.getElementById('noVNC_fullscreen_button')
190 .classList.remove("noVNC_hidden");
191 UI.addFullscreenHandlers();
192 }
193 },
194
195 addControlbarHandlers: function() {
196 document.getElementById("noVNC_control_bar")
197 .addEventListener('mousemove', UI.activateControlbar);
198 document.getElementById("noVNC_control_bar")
199 .addEventListener('mouseup', UI.activateControlbar);
200 document.getElementById("noVNC_control_bar")
201 .addEventListener('mousedown', UI.activateControlbar);
202 document.getElementById("noVNC_control_bar")
203 .addEventListener('keypress', UI.activateControlbar);
204
205 document.getElementById("noVNC_control_bar")
206 .addEventListener('mousedown', UI.keepControlbar);
207 document.getElementById("noVNC_control_bar")
208 .addEventListener('keypress', UI.keepControlbar);
209
210 document.getElementById("noVNC_view_drag_button")
211 .addEventListener('click', UI.toggleViewDrag);
212
213 document.getElementById("noVNC_control_bar_handle")
214 .addEventListener('mousedown', UI.controlbarHandleMouseDown);
215 document.getElementById("noVNC_control_bar_handle")
216 .addEventListener('mouseup', UI.controlbarHandleMouseUp);
217 document.getElementById("noVNC_control_bar_handle")
218 .addEventListener('mousemove', UI.dragControlbarHandle);
219 // resize events aren't available for elements
220 window.addEventListener('resize', UI.updateControlbarHandle);
221 },
222
223 addTouchSpecificHandlers: function() {
224 document.getElementById("noVNC_mouse_button0")
225 .addEventListener('click', function () { UI.setMouseButton(1); });
226 document.getElementById("noVNC_mouse_button1")
227 .addEventListener('click', function () { UI.setMouseButton(2); });
228 document.getElementById("noVNC_mouse_button2")
229 .addEventListener('click', function () { UI.setMouseButton(4); });
230 document.getElementById("noVNC_mouse_button4")
231 .addEventListener('click', function () { UI.setMouseButton(0); });
232 document.getElementById("noVNC_keyboard_button")
233 .addEventListener('click', UI.toggleVirtualKeyboard);
234
235 document.getElementById("noVNC_keyboardinput")
236 .addEventListener('input', UI.keyInput);
237 document.getElementById("noVNC_keyboardinput")
238 .addEventListener('blur', UI.onblurVirtualKeyboard);
239 document.getElementById("noVNC_keyboardinput")
240 .addEventListener('submit', function () { return false; });
241
242 document.getElementById("noVNC_control_bar")
243 .addEventListener('touchstart', UI.activateControlbar);
244 document.getElementById("noVNC_control_bar")
245 .addEventListener('touchmove', UI.activateControlbar);
246 document.getElementById("noVNC_control_bar")
247 .addEventListener('touchend', UI.activateControlbar);
248 document.getElementById("noVNC_control_bar")
249 .addEventListener('input', UI.activateControlbar);
250
251 document.getElementById("noVNC_control_bar")
252 .addEventListener('touchstart', UI.keepControlbar);
253 document.getElementById("noVNC_control_bar")
254 .addEventListener('input', UI.keepControlbar);
255
256 document.getElementById("noVNC_control_bar_handle")
257 .addEventListener('touchstart', UI.controlbarHandleMouseDown);
258 document.getElementById("noVNC_control_bar_handle")
259 .addEventListener('touchend', UI.controlbarHandleMouseUp);
260 document.getElementById("noVNC_control_bar_handle")
261 .addEventListener('touchmove', UI.dragControlbarHandle);
262
263 window.addEventListener('load', UI.keyboardinputReset);
264 },
265
266 addExtraKeysHandlers: function() {
267 document.getElementById("noVNC_toggle_extra_keys_button")
268 .addEventListener('click', UI.toggleExtraKeys);
269 document.getElementById("noVNC_toggle_ctrl_button")
270 .addEventListener('click', UI.toggleCtrl);
271 document.getElementById("noVNC_toggle_alt_button")
272 .addEventListener('click', UI.toggleAlt);
273 document.getElementById("noVNC_send_tab_button")
274 .addEventListener('click', UI.sendTab);
275 document.getElementById("noVNC_send_esc_button")
276 .addEventListener('click', UI.sendEsc);
277 document.getElementById("noVNC_send_ctrl_alt_del_button")
278 .addEventListener('click', UI.sendCtrlAltDel);
279 },
280
281 addXvpHandlers: function() {
282 document.getElementById("noVNC_xvp_shutdown_button")
283 .addEventListener('click', function() { UI.rfb.xvpShutdown(); });
284 document.getElementById("noVNC_xvp_reboot_button")
285 .addEventListener('click', function() { UI.rfb.xvpReboot(); });
286 document.getElementById("noVNC_xvp_reset_button")
287 .addEventListener('click', function() { UI.rfb.xvpReset(); });
288 document.getElementById("noVNC_xvp_button")
289 .addEventListener('click', UI.toggleXvpPanel);
290 },
291
292 addConnectionControlHandlers: function() {
293 document.getElementById("noVNC_connect_controls_button")
294 .addEventListener('click', UI.toggleConnectPanel);
295 document.getElementById("noVNC_disconnect_button")
296 .addEventListener('click', UI.disconnect);
297 document.getElementById("noVNC_connect_button")
298 .addEventListener('click', UI.connect);
299
300 document.getElementById("noVNC_password_button")
301 .addEventListener('click', UI.setPassword);
302 },
303
304 addClipboardHandlers: function() {
305 document.getElementById("noVNC_clipboard_button")
306 .addEventListener('click', UI.toggleClipboardPanel);
307 document.getElementById("noVNC_clipboard_text")
308 .addEventListener('focus', UI.displayBlur);
309 document.getElementById("noVNC_clipboard_text")
310 .addEventListener('blur', UI.displayFocus);
311 document.getElementById("noVNC_clipboard_text")
312 .addEventListener('change', UI.clipboardSend);
313 document.getElementById("noVNC_clipboard_clear_button")
314 .addEventListener('click', UI.clipboardClear);
315 },
316
317 addSettingsHandlers: function() {
318 document.getElementById("noVNC_settings_button")
319 .addEventListener('click', UI.toggleSettingsPanel);
320 document.getElementById("noVNC_settings_apply")
321 .addEventListener('click', UI.settingsApply);
322
323 document.getElementById("noVNC_setting_resize")
324 .addEventListener('change', UI.enableDisableViewClip);
325 },
326
327 addFullscreenHandlers: function() {
328 document.getElementById("noVNC_fullscreen_button")
329 .addEventListener('click', UI.toggleFullscreen);
330
331 window.addEventListener('fullscreenchange', UI.updateFullscreenButton);
332 window.addEventListener('mozfullscreenchange', UI.updateFullscreenButton);
333 window.addEventListener('webkitfullscreenchange', UI.updateFullscreenButton);
334 window.addEventListener('msfullscreenchange', UI.updateFullscreenButton);
335 },
336
337 initRFB: function() {
338 try {
339 UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'),
340 'onNotification': UI.notification,
341 'onUpdateState': UI.updateState,
342 'onDisconnected': UI.disconnectFinished,
343 'onPasswordRequired': UI.passwordRequired,
344 'onXvpInit': UI.updateXvpButton,
345 'onClipboard': UI.clipboardReceive,
346 'onBell': UI.bell,
347 'onFBUComplete': UI.initialResize,
348 'onFBResize': UI.updateViewDrag,
349 'onDesktopName': UI.updateDesktopName});
350 return true;
351 } catch (exc) {
352 UI.showStatus('Unable to create RFB client -- ' + exc, 'error');
353 return false;
354 }
355 },
356
357 /* ------^-------
358 * /INIT
359 * ==============
360 * VISUAL
361 * ------v------*/
362
363 updateState: function(rfb, state, oldstate) {
364 switch (state) {
365 case 'connecting':
366 UI.showStatus("Connecting");
367 break;
368 case 'connected':
369 UI.connected = true;
370 if (rfb && rfb.get_encrypt()) {
371 UI.showStatus("Connected (encrypted) to " +
372 UI.desktopName);
373 } else {
374 UI.showStatus("Connected (unencrypted) to " +
375 UI.desktopName);
376 }
377 break;
378 case 'disconnecting':
379 UI.showStatus("Disconnecting");
380 break;
381 case 'disconnected':
382 UI.connected = false;
383 UI.showStatus("Disconnected");
384 break;
385 default:
386 UI.showStatus("Invalid state", 'error');
387 break;
388 }
389
390 UI.updateVisualState();
391 },
392
393 // Disable/enable controls depending on connection state
394 updateVisualState: function() {
395 //Util.Debug(">> updateVisualState");
396 document.getElementById('noVNC_setting_encrypt').disabled = UI.connected;
397 document.getElementById('noVNC_setting_true_color').disabled = UI.connected;
398 if (Util.browserSupportsCursorURIs()) {
399 document.getElementById('noVNC_setting_cursor').disabled = UI.connected;
400 } else {
401 UI.updateSetting('cursor', !Util.isTouchDevice);
402 document.getElementById('noVNC_setting_cursor').disabled = true;
403 }
404
405 UI.enableDisableViewClip();
406 document.getElementById('noVNC_setting_resize').disabled = UI.connected;
407 document.getElementById('noVNC_setting_shared').disabled = UI.connected;
408 document.getElementById('noVNC_setting_view_only').disabled = UI.connected;
409 document.getElementById('noVNC_setting_path').disabled = UI.connected;
410 document.getElementById('noVNC_setting_repeaterID').disabled = UI.connected;
411
412 if (UI.connected) {
413 document.documentElement.classList.add("noVNC_connected");
414 UI.updateViewClip();
415 UI.setMouseButton(1);
416
417 // Hide the controlbar after 2 seconds
418 UI.closeControlbarTimeout = setTimeout(UI.closeControlbar, 2000);
419 } else {
420 document.documentElement.classList.remove("noVNC_connected");
421 UI.updateXvpButton(0);
422 UI.keepControlbar();
423 }
424
425 // State change disables viewport dragging.
426 // It is enabled (toggled) by direct click on the button
427 UI.setViewDrag(false);
428
429 // State change also closes the password dialog
430 document.getElementById('noVNC_password_dlg')
431 .classList.remove('noVNC_open');
432
433 //Util.Debug("<< updateVisualState");
434 },
435
436 showStatus: function(text, status_type, time) {
437 var statusElem = document.getElementById('noVNC_status');
438
439 clearTimeout(UI.statusTimeout);
440
441 if (typeof status_type === 'undefined') {
442 status_type = 'normal';
443 }
444
445 statusElem.classList.remove("noVNC_status_normal",
446 "noVNC_status_warn",
447 "noVNC_status_error");
448
449 switch (status_type) {
450 case 'warning':
451 case 'warn':
452 statusElem.classList.add("noVNC_status_warn");
453 break;
454 case 'error':
455 statusElem.classList.add("noVNC_status_error");
456 break;
457 case 'normal':
458 case 'info':
459 default:
460 statusElem.classList.add("noVNC_status_normal");
461 break;
462 }
463
464 statusElem.innerHTML = text;
465 statusElem.classList.add("noVNC_open");
466
467 // If no time was specified, show the status for 1.5 seconds
468 if (typeof time === 'undefined') {
469 time = 1500;
470 }
471
472 // Error messages do not timeout
473 if (status_type !== 'error') {
474 UI.statusTimeout = window.setTimeout(UI.hideStatus, time);
475 }
476 },
477
478 hideStatus: function() {
479 clearTimeout(UI.statusTimeout);
480 document.getElementById('noVNC_status').classList.remove("noVNC_open");
481 },
482
483 notification: function (rfb, msg, level, options) {
484 UI.showStatus(msg, level);
485 },
486
487 activateControlbar: function(event) {
488 clearTimeout(UI.idleControlbarTimeout);
489 // We manipulate the anchor instead of the actual control
490 // bar in order to avoid creating new a stacking group
491 document.getElementById('noVNC_control_bar_anchor')
492 .classList.remove("noVNC_idle");
493 UI.idleControlbarTimeout = window.setTimeout(UI.idleControlbar, 2000);
494 },
495
496 idleControlbar: function() {
497 document.getElementById('noVNC_control_bar_anchor')
498 .classList.add("noVNC_idle");
499 },
500
501 keepControlbar: function() {
502 clearTimeout(UI.closeControlbarTimeout);
503 },
504
505 openControlbar: function() {
506 document.getElementById('noVNC_control_bar')
507 .classList.add("noVNC_open");
508 },
509
510 closeControlbar: function() {
511 UI.closeAllPanels();
512 document.getElementById('noVNC_control_bar')
513 .classList.remove("noVNC_open");
514 },
515
516 toggleControlbar: function() {
517 if (document.getElementById('noVNC_control_bar')
518 .classList.contains("noVNC_open")) {
519 UI.closeControlbar();
520 } else {
521 UI.openControlbar();
522 }
523 },
524
525 dragControlbarHandle: function (e) {
526 if (!UI.controlbarGrabbed) return;
527
528 var ptr = Util.getPointerEvent(e);
529
530 if (!UI.controlbarDrag) {
531 // The goal is to trigger on a certain physical width, the
532 // devicePixelRatio brings us a bit closer but is not optimal.
533 var dragThreshold = 10 * (window.devicePixelRatio || 1);
534 var dragDistance = Math.abs(ptr.clientY - UI.controlbarMouseDownClientY);
535
536 if (dragDistance < dragThreshold) return;
537
538 UI.controlbarDrag = true;
539 }
540
541 var eventY = ptr.clientY - UI.controlbarMouseDownOffsetY;
542
543 UI.moveControlbarHandle(eventY);
544
545 e.preventDefault();
546 e.stopPropagation();
547 },
548
549 // Move the handle but don't allow any position outside the bounds
550 moveControlbarHandle: function (posY) {
551 var handle = document.getElementById("noVNC_control_bar_handle");
552 var handleHeight = Util.getPosition(handle).height;
553 var controlbar = document.getElementById("noVNC_control_bar");
554 var controlbarBounds = Util.getPosition(controlbar);
555 var controlbarTop = controlbarBounds.y;
556 var controlbarBottom = controlbarBounds.y + controlbarBounds.height;
557 var margin = 10;
558
559 var viewportY = posY;
560
561 // Refuse coordinates outside the control bar
562 if (viewportY < controlbarTop + margin) {
563 viewportY = controlbarTop + margin;
564 } else if (viewportY > controlbarBottom - handleHeight - margin) {
565 viewportY = controlbarBottom - handleHeight - margin;
566 }
567
568 // Corner case: control bar too small for stable position
569 if (controlbarBounds.height < (handleHeight + margin * 2)) {
570 viewportY = controlbarTop + (controlbarBounds.height - handleHeight) / 2;
571 }
572
573 var relativeY = viewportY - controlbarTop;
574 handle.style.transform = "translateY(" + relativeY + "px)";
575 },
576
577 updateControlbarHandle: function () {
578 var handle = document.getElementById("noVNC_control_bar_handle");
579 var pos = Util.getPosition(handle);
580 UI.moveControlbarHandle(pos.y);
581 },
582
583 controlbarHandleMouseUp: function(e) {
584 if ((e.type == "mouseup") && (e.button != 0)) return;
585
586 // mouseup and mousedown on the same place toggles the controlbar
587 if (UI.controlbarGrabbed && !UI.controlbarDrag) {
588 UI.toggleControlbar();
589 e.preventDefault();
590 e.stopPropagation();
591 }
592 UI.controlbarGrabbed = false;
593 },
594
595 controlbarHandleMouseDown: function(e) {
596 if ((e.type == "mousedown") && (e.button != 0)) return;
597
598 var ptr = Util.getPointerEvent(e);
599
600 var handle = document.getElementById("noVNC_control_bar_handle");
601 var bounds = handle.getBoundingClientRect();
602
603 WebUtil.setCapture(handle);
604 UI.controlbarGrabbed = true;
605 UI.controlbarDrag = false;
606
607 UI.controlbarMouseDownClientY = ptr.clientY;
608 UI.controlbarMouseDownOffsetY = ptr.clientY - bounds.top;
609 e.preventDefault();
610 e.stopPropagation();
611 },
612
613 /* ------^-------
614 * /VISUAL
615 * ==============
616 * SETTINGS
617 * ------v------*/
618
619 // Initial page load read/initialization of settings
620 initSetting: function(name, defVal) {
621 // Check Query string followed by cookie
622 var val = WebUtil.getConfigVar(name);
623 if (val === null) {
624 val = WebUtil.readSetting(name, defVal);
625 }
626 UI.updateSetting(name, val);
627 return val;
628 },
629
630 // Update cookie and form control setting. If value is not set, then
631 // updates from control to current cookie setting.
632 updateSetting: function(name, value) {
633
634 // Save the cookie for this session
635 if (typeof value !== 'undefined') {
636 WebUtil.writeSetting(name, value);
637 }
638
639 // Update the settings control
640 value = UI.getSetting(name);
641
642 var ctrl = document.getElementById('noVNC_setting_' + name);
643 if (ctrl.type === 'checkbox') {
644 ctrl.checked = value;
645
646 } else if (typeof ctrl.options !== 'undefined') {
647 for (var i = 0; i < ctrl.options.length; i += 1) {
648 if (ctrl.options[i].value === value) {
649 ctrl.selectedIndex = i;
650 break;
651 }
652 }
653 } else {
654 /*Weird IE9 error leads to 'null' appearring
655 in textboxes instead of ''.*/
656 if (value === null) {
657 value = "";
658 }
659 ctrl.value = value;
660 }
661 },
662
663 // Save control setting to cookie
664 saveSetting: function(name) {
665 var val, ctrl = document.getElementById('noVNC_setting_' + name);
666 if (ctrl.type === 'checkbox') {
667 val = ctrl.checked;
668 } else if (typeof ctrl.options !== 'undefined') {
669 val = ctrl.options[ctrl.selectedIndex].value;
670 } else {
671 val = ctrl.value;
672 }
673 WebUtil.writeSetting(name, val);
674 //Util.Debug("Setting saved '" + name + "=" + val + "'");
675 return val;
676 },
677
678 // Force a setting to be a certain value
679 forceSetting: function(name, val) {
680 UI.updateSetting(name, val);
681 return val;
682 },
683
684 // Read form control compatible setting from cookie
685 getSetting: function(name) {
686 var ctrl = document.getElementById('noVNC_setting_' + name);
687 var val = WebUtil.readSetting(name);
688 if (typeof val !== 'undefined' && val !== null && ctrl.type === 'checkbox') {
689 if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
690 val = false;
691 } else {
692 val = true;
693 }
694 }
695 return val;
696 },
697
698 // Save/apply settings when 'Apply' button is pressed
699 settingsApply: function() {
700 //Util.Debug(">> settingsApply");
701 UI.saveSetting('encrypt');
702 UI.saveSetting('true_color');
703 if (Util.browserSupportsCursorURIs()) {
704 UI.saveSetting('cursor');
705 }
706
707 UI.saveSetting('resize');
708
709 if (UI.getSetting('resize') === 'downscale' || UI.getSetting('resize') === 'scale') {
710 UI.forceSetting('clip', false);
711 }
712
713 UI.saveSetting('clip');
714 UI.saveSetting('shared');
715 UI.saveSetting('view_only');
716 UI.saveSetting('path');
717 UI.saveSetting('repeaterID');
718 UI.saveSetting('stylesheet');
719 UI.saveSetting('logging');
720
721 // Settings with immediate (non-connected related) effect
722 WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
723 WebUtil.init_logging(UI.getSetting('logging'));
724 UI.updateViewClip();
725 UI.updateViewDrag();
726 //Util.Debug("<< settingsApply");
727 },
728
729 /* ------^-------
730 * /SETTINGS
731 * ==============
732 * PANELS
733 * ------v------*/
734
735 closeAllPanels: function() {
736 UI.closeSettingsPanel();
737 UI.closeXvpPanel();
738 UI.closeClipboardPanel();
739 UI.closeConnectPanel();
740 UI.closeExtraKeys();
741 },
742
743 /* ------^-------
744 * /PANELS
745 * ==============
746 * SETTINGS (panel)
747 * ------v------*/
748
749 openSettingsPanel: function() {
750 UI.closeAllPanels();
751 UI.openControlbar();
752
753 UI.updateSetting('encrypt');
754 UI.updateSetting('true_color');
755 if (Util.browserSupportsCursorURIs()) {
756 UI.updateSetting('cursor');
757 } else {
758 UI.updateSetting('cursor', !Util.isTouchDevice);
759 document.getElementById('noVNC_setting_cursor').disabled = true;
760 }
761 UI.updateSetting('clip');
762 UI.updateSetting('resize');
763 UI.updateSetting('shared');
764 UI.updateSetting('view_only');
765 UI.updateSetting('path');
766 UI.updateSetting('repeaterID');
767 UI.updateSetting('stylesheet');
768 UI.updateSetting('logging');
769
770 document.getElementById('noVNC_settings')
771 .classList.add("noVNC_open");
772 document.getElementById('noVNC_settings_button')
773 .classList.add("noVNC_selected");
774 },
775
776 closeSettingsPanel: function() {
777 document.getElementById('noVNC_settings')
778 .classList.remove("noVNC_open");
779 document.getElementById('noVNC_settings_button')
780 .classList.remove("noVNC_selected");
781 },
782
783 // Toggle the settings menu:
784 // On open, settings are refreshed from saved cookies.
785 // On close, settings are applied
786 toggleSettingsPanel: function() {
787 if (document.getElementById('noVNC_settings')
788 .classList.contains("noVNC_open")) {
789 UI.settingsApply();
790 UI.closeSettingsPanel();
791 } else {
792 UI.openSettingsPanel();
793 }
794 },
795
796 /* ------^-------
797 * /SETTINGS
798 * ==============
799 * XVP
800 * ------v------*/
801
802 openXvpPanel: function() {
803 UI.closeAllPanels();
804 UI.openControlbar();
805
806 document.getElementById('noVNC_xvp')
807 .classList.add("noVNC_open");
808 document.getElementById('noVNC_xvp_button')
809 .classList.add("noVNC_selected");
810 },
811
812 closeXvpPanel: function() {
813 document.getElementById('noVNC_xvp')
814 .classList.remove("noVNC_open");
815 document.getElementById('noVNC_xvp_button')
816 .classList.remove("noVNC_selected");
817 },
818
819 toggleXvpPanel: function() {
820 if (document.getElementById('noVNC_xvp')
821 .classList.contains("noVNC_open")) {
822 UI.closeXvpPanel();
823 } else {
824 UI.openXvpPanel();
825 }
826 },
827
828 // Disable/enable XVP button
829 updateXvpButton: function(ver) {
830 if (ver >= 1) {
831 document.getElementById('noVNC_xvp_button')
832 .classList.remove("noVNC_hidden");
833 } else {
834 document.getElementById('noVNC_xvp_button')
835 .classList.add("noVNC_hidden");
836 // Close XVP panel if open
837 UI.closeXvpPanel();
838 }
839 },
840
841 /* ------^-------
842 * /XVP
843 * ==============
844 * CLIPBOARD
845 * ------v------*/
846
847 openClipboardPanel: function() {
848 UI.closeAllPanels();
849 UI.openControlbar();
850
851 document.getElementById('noVNC_clipboard')
852 .classList.add("noVNC_open");
853 document.getElementById('noVNC_clipboard_button')
854 .classList.add("noVNC_selected");
855 },
856
857 closeClipboardPanel: function() {
858 document.getElementById('noVNC_clipboard')
859 .classList.remove("noVNC_open");
860 document.getElementById('noVNC_clipboard_button')
861 .classList.remove("noVNC_selected");
862 },
863
864 toggleClipboardPanel: function() {
865 if (document.getElementById('noVNC_clipboard')
866 .classList.contains("noVNC_open")) {
867 UI.closeClipboardPanel();
868 } else {
869 UI.openClipboardPanel();
870 }
871 },
872
873 clipboardReceive: function(rfb, text) {
874 Util.Debug(">> UI.clipboardReceive: " + text.substr(0,40) + "...");
875 document.getElementById('noVNC_clipboard_text').value = text;
876 Util.Debug("<< UI.clipboardReceive");
877 },
878
879 clipboardClear: function() {
880 document.getElementById('noVNC_clipboard_text').value = "";
881 UI.rfb.clipboardPasteFrom("");
882 },
883
884 clipboardSend: function() {
885 var text = document.getElementById('noVNC_clipboard_text').value;
886 Util.Debug(">> UI.clipboardSend: " + text.substr(0,40) + "...");
887 UI.rfb.clipboardPasteFrom(text);
888 Util.Debug("<< UI.clipboardSend");
889 },
890
891 /* ------^-------
892 * /CLIPBOARD
893 * ==============
894 * CONNECTION
895 * ------v------*/
896
897 openConnectPanel: function() {
898 UI.closeAllPanels();
899 UI.openControlbar();
900
901 document.getElementById('noVNC_connect_controls')
902 .classList.add("noVNC_open");
903 document.getElementById('noVNC_connect_controls_button')
904 .classList.add("noVNC_selected");
905
906 document.getElementById('noVNC_setting_host').focus();
907 },
908
909 closeConnectPanel: function() {
910 document.getElementById('noVNC_connect_controls')
911 .classList.remove("noVNC_open");
912 document.getElementById('noVNC_connect_controls_button')
913 .classList.remove("noVNC_selected");
914
915 UI.saveSetting('host');
916 UI.saveSetting('port');
917 UI.saveSetting('token');
918 //UI.saveSetting('password');
919 },
920
921 toggleConnectPanel: function() {
922 if (document.getElementById('noVNC_connect_controls')
923 .classList.contains("noVNC_open")) {
924 UI.closeConnectPanel();
925 } else {
926 UI.openConnectPanel();
927 }
928 },
929
930 connect: function() {
931 var host = document.getElementById('noVNC_setting_host').value;
932 var port = document.getElementById('noVNC_setting_port').value;
933 var password = document.getElementById('noVNC_setting_password').value;
934 var token = document.getElementById('noVNC_setting_token').value;
935 var path = document.getElementById('noVNC_setting_path').value;
936
937 //if token is in path then ignore the new token variable
938 if (token) {
939 path = WebUtil.injectParamIfMissing(path, "token", token);
940 }
941
942 if ((!host) || (!port)) {
943 UI.showStatus("Must set host and port", 'error');
944 return;
945 }
946
947 if (!UI.initRFB()) return;
948
949 UI.closeAllPanels();
950
951 UI.rfb.set_encrypt(UI.getSetting('encrypt'));
952 UI.rfb.set_true_color(UI.getSetting('true_color'));
953 UI.rfb.set_local_cursor(UI.getSetting('cursor'));
954 UI.rfb.set_shared(UI.getSetting('shared'));
955 UI.rfb.set_view_only(UI.getSetting('view_only'));
956 UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
957
958 UI.rfb.connect(host, port, password, path);
959 },
960
961 disconnect: function() {
962 UI.closeAllPanels();
963 UI.rfb.disconnect();
964
965 // Restore the callback used for initial resize
966 UI.rfb.set_onFBUComplete(UI.initialResize);
967
968 // Don't display the connection settings until we're actually disconnected
969 },
970
971 disconnectFinished: function (rfb, reason) {
972 if (typeof reason !== 'undefined') {
973 UI.showStatus(reason, 'error');
974 }
975 UI.openConnectPanel();
976 },
977
978 /* ------^-------
979 * /CONNECTION
980 * ==============
981 * PASSWORD
982 * ------v------*/
983
984 passwordRequired: function(rfb, msg) {
985
986 document.getElementById('noVNC_password_dlg')
987 .classList.add('noVNC_open');
988
989 setTimeout(function () {
990 document.getElementById('noVNC_password_input').focus();
991 }, 100);
992
993 if (typeof msg === 'undefined') {
994 msg = "Password is required";
995 }
996 UI.showStatus(msg, "warning");
997 },
998
999 setPassword: function() {
1000 UI.rfb.sendPassword(document.getElementById('noVNC_password_input').value);
1001 document.getElementById('noVNC_password_dlg')
1002 .classList.remove('noVNC_open');
1003 return false;
1004 },
1005
1006 /* ------^-------
1007 * /PASSWORD
1008 * ==============
1009 * FULLSCREEN
1010 * ------v------*/
1011
1012 toggleFullscreen: function() {
1013 if (document.fullscreenElement || // alternative standard method
1014 document.mozFullScreenElement || // currently working methods
1015 document.webkitFullscreenElement ||
1016 document.msFullscreenElement) {
1017 if (document.exitFullscreen) {
1018 document.exitFullscreen();
1019 } else if (document.mozCancelFullScreen) {
1020 document.mozCancelFullScreen();
1021 } else if (document.webkitExitFullscreen) {
1022 document.webkitExitFullscreen();
1023 } else if (document.msExitFullscreen) {
1024 document.msExitFullscreen();
1025 }
1026 } else {
1027 if (document.documentElement.requestFullscreen) {
1028 document.documentElement.requestFullscreen();
1029 } else if (document.documentElement.mozRequestFullScreen) {
1030 document.documentElement.mozRequestFullScreen();
1031 } else if (document.documentElement.webkitRequestFullscreen) {
1032 document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
1033 } else if (document.body.msRequestFullscreen) {
1034 document.body.msRequestFullscreen();
1035 }
1036 }
1037 UI.enableDisableViewClip();
1038 UI.updateFullscreenButton();
1039 },
1040
1041 updateFullscreenButton: function() {
1042 if (document.fullscreenElement || // alternative standard method
1043 document.mozFullScreenElement || // currently working methods
1044 document.webkitFullscreenElement ||
1045 document.msFullscreenElement ) {
1046 document.getElementById('noVNC_fullscreen_button')
1047 .classList.add("noVNC_selected");
1048 } else {
1049 document.getElementById('noVNC_fullscreen_button')
1050 .classList.remove("noVNC_selected");
1051 }
1052 },
1053
1054 /* ------^-------
1055 * /FULLSCREEN
1056 * ==============
1057 * RESIZE
1058 * ------v------*/
1059
1060 // Apply remote resizing or local scaling
1061 applyResizeMode: function() {
1062 if (!UI.rfb) return;
1063
1064 var screen = UI.screenSize();
1065
1066 if (screen && UI.connected && UI.rfb.get_display()) {
1067
1068 var display = UI.rfb.get_display();
1069 var resizeMode = UI.getSetting('resize');
1070
1071 if (resizeMode === 'remote') {
1072
1073 // Request changing the resolution of the remote display to
1074 // the size of the local browser viewport.
1075
1076 // In order to not send multiple requests before the browser-resize
1077 // is finished we wait 0.5 seconds before sending the request.
1078 clearTimeout(UI.resizeTimeout);
1079 UI.resizeTimeout = setTimeout(function(){
1080
1081 // Limit the viewport to the size of the browser window
1082 display.set_maxWidth(screen.w);
1083 display.set_maxHeight(screen.h);
1084
1085 Util.Debug('Attempting requestDesktopSize(' +
1086 screen.w + ', ' + screen.h + ')');
1087
1088 // Request a remote size covering the viewport
1089 UI.rfb.requestDesktopSize(screen.w, screen.h);
1090 }, 500);
1091
1092 } else if (resizeMode === 'scale' || resizeMode === 'downscale') {
1093 var downscaleOnly = resizeMode === 'downscale';
1094 var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly);
1095 UI.rfb.get_mouse().set_scale(scaleRatio);
1096 Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale());
1097 }
1098 }
1099 },
1100
1101 // The screen is always the same size as the available viewport
1102 // in the browser window minus the height of the control bar
1103 screenSize: function() {
1104 var screen = document.getElementById('noVNC_screen');
1105
1106 // Hide the scrollbars until the size is calculated
1107 screen.style.overflow = "hidden";
1108
1109 var pos = Util.getPosition(screen);
1110 var w = pos.width;
1111 var h = pos.height;
1112
1113 screen.style.overflow = "visible";
1114
1115 if (isNaN(w) || isNaN(h)) {
1116 return false;
1117 } else {
1118 return {w: w, h: h};
1119 }
1120 },
1121
1122 // Normally we only apply the current resize mode after a window resize
1123 // event. This means that when a new connection is opened, there is no
1124 // resize mode active.
1125 // We have to wait until the first FBU because this is where the client
1126 // will find the supported encodings of the server. Some calls later in
1127 // the chain is dependant on knowing the server-capabilities.
1128 initialResize: function(rfb, fbu) {
1129 UI.applyResizeMode();
1130 // After doing this once, we remove the callback.
1131 UI.rfb.set_onFBUComplete(function() { });
1132 },
1133
1134 /* ------^-------
1135 * /RESIZE
1136 * ==============
1137 * CLIPPING
1138 * ------v------*/
1139
1140 // Set and configure viewport clipping
1141 setViewClip: function(clip) {
1142 UI.updateSetting('clip', clip);
1143 UI.updateViewClip();
1144 },
1145
1146 // Update parameters that depend on the clip setting
1147 updateViewClip: function() {
1148 if (!UI.rfb) return;
1149
1150 var display = UI.rfb.get_display();
1151 var cur_clip = display.get_viewport();
1152 var new_clip = UI.getSetting('clip');
1153
1154 if (cur_clip !== new_clip) {
1155 display.set_viewport(new_clip);
1156 }
1157
1158 var size = UI.screenSize();
1159
1160 if (new_clip && size) {
1161 // When clipping is enabled, the screen is limited to
1162 // the size of the browser window.
1163 display.set_maxWidth(size.w);
1164 display.set_maxHeight(size.h);
1165
1166 var screen = document.getElementById('noVNC_screen');
1167 var canvas = document.getElementById('noVNC_canvas');
1168
1169 // Hide potential scrollbars that can skew the position
1170 screen.style.overflow = "hidden";
1171
1172 // The x position marks the left margin of the canvas,
1173 // remove the margin from both sides to keep it centered.
1174 var new_w = size.w - (2 * Util.getPosition(canvas).x);
1175
1176 screen.style.overflow = "visible";
1177
1178 display.viewportChangeSize(new_w, size.h);
1179 } else {
1180 // Disable max dimensions
1181 display.set_maxWidth(0);
1182 display.set_maxHeight(0);
1183 display.viewportChangeSize();
1184 }
1185 },
1186
1187 // Handle special cases where clipping is forced on/off or locked
1188 enableDisableViewClip: function() {
1189 var resizeSetting = document.getElementById('noVNC_setting_resize');
1190
1191 if (UI.isSafari) {
1192 // Safari auto-hides the scrollbars which makes them
1193 // impossible to use in most cases
1194 UI.setViewClip(true);
1195 document.getElementById('noVNC_setting_clip').disabled = true;
1196 } else if (resizeSetting.value === 'downscale' || resizeSetting.value === 'scale') {
1197 // Disable clipping if we are scaling
1198 UI.setViewClip(false);
1199 document.getElementById('noVNC_setting_clip').disabled = true;
1200 } else if (document.msFullscreenElement) {
1201 // The browser is IE and we are in fullscreen mode.
1202 // - We need to force clipping while in fullscreen since
1203 // scrollbars doesn't work.
1204 UI.showStatus("Forcing clipping mode since scrollbars aren't supported by IE in fullscreen");
1205 UI.rememberedClipSetting = UI.getSetting('clip');
1206 UI.setViewClip(true);
1207 document.getElementById('noVNC_setting_clip').disabled = true;
1208 } else if (document.body.msRequestFullscreen && UI.rememberedClip !== null) {
1209 // Restore view clip to what it was before fullscreen on IE
1210 UI.setViewClip(UI.rememberedClipSetting);
1211 document.getElementById('noVNC_setting_clip').disabled =
1212 UI.connected || Util.isTouchDevice;
1213 } else {
1214 document.getElementById('noVNC_setting_clip').disabled =
1215 UI.connected || Util.isTouchDevice;
1216 if (Util.isTouchDevice) {
1217 UI.setViewClip(true);
1218 }
1219 }
1220 },
1221
1222 /* ------^-------
1223 * /CLIPPING
1224 * ==============
1225 * VIEWDRAG
1226 * ------v------*/
1227
1228 toggleViewDrag: function() {
1229 if (!UI.rfb) return;
1230
1231 var drag = UI.rfb.get_viewportDrag();
1232 UI.setViewDrag(!drag);
1233 },
1234
1235 // Set the view drag mode which moves the viewport on mouse drags
1236 setViewDrag: function(drag) {
1237 if (!UI.rfb) return;
1238
1239 UI.rfb.set_viewportDrag(drag);
1240
1241 UI.updateViewDrag();
1242 },
1243
1244 updateViewDrag: function() {
1245 var clipping = false;
1246
1247 if (!UI.connected) return;
1248
1249 // Check if viewport drag is possible. It is only possible
1250 // if the remote display is clipping the client display.
1251 if (UI.rfb.get_display().get_viewport() &&
1252 UI.rfb.get_display().clippingDisplay()) {
1253 clipping = true;
1254 }
1255
1256 var viewDragButton = document.getElementById('noVNC_view_drag_button');
1257
1258 if (!clipping &&
1259 UI.rfb.get_viewportDrag()) {
1260 // The size of the remote display is the same or smaller
1261 // than the client display. Make sure viewport drag isn't
1262 // active when it can't be used.
1263 UI.rfb.set_viewportDrag(false);
1264 }
1265
1266 if (UI.rfb.get_viewportDrag()) {
1267 viewDragButton.classList.add("noVNC_selected");
1268 } else {
1269 viewDragButton.classList.remove("noVNC_selected");
1270 }
1271
1272 // Different behaviour for touch vs non-touch
1273 // The button is disabled instead of hidden on touch devices
1274 if (Util.isTouchDevice) {
1275 viewDragButton.classList.remove("noVNC_hidden");
1276
1277 if (clipping) {
1278 viewDragButton.disabled = false;
1279 } else {
1280 viewDragButton.disabled = true;
1281 }
1282 } else {
1283 viewDragButton.disabled = false;
1284
1285 if (clipping) {
1286 viewDragButton.classList.remove("noVNC_hidden");
1287 } else {
1288 viewDragButton.classList.add("noVNC_hidden");
1289 }
1290 }
1291 },
1292
1293 /* ------^-------
1294 * /VIEWDRAG
1295 * ==============
1296 * KEYBOARD
1297 * ------v------*/
1298
1299 showVirtualKeyboard: function() {
1300 if (!Util.isTouchDevice) return;
1301
1302 var input = document.getElementById('noVNC_keyboardinput');
1303
1304 if (document.activeElement == input) return;
1305
1306 UI.keyboardVisible = true;
1307 document.getElementById('noVNC_keyboard_button')
1308 .classList.add("noVNC_selected");
1309 input.focus();
1310
1311 try {
1312 var l = input.value.length;
1313 // Move the caret to the end
1314 input.setSelectionRange(l, l);
1315 } catch (err) {} // setSelectionRange is undefined in Google Chrome
1316 },
1317
1318 hideVirtualKeyboard: function() {
1319 if (!Util.isTouchDevice) return;
1320
1321 var input = document.getElementById('noVNC_keyboardinput');
1322
1323 if (document.activeElement != input) return;
1324
1325 input.blur();
1326 },
1327
1328 toggleVirtualKeyboard: function () {
1329 if (UI.keyboardVisible) {
1330 UI.hideVirtualKeyboard();
1331 } else {
1332 UI.showVirtualKeyboard();
1333 }
1334 },
1335
1336 onblurVirtualKeyboard: function() {
1337 //Weird bug in iOS if you change keyboardVisible
1338 //here it does not actually occur so next time
1339 //you click keyboard icon it doesnt work.
1340 UI.hideKeyboardTimeout = setTimeout(function() {
1341 UI.keyboardVisible = false;
1342 document.getElementById('noVNC_keyboard_button')
1343 .classList.remove("noVNC_selected");
1344 },100);
1345 },
1346
1347 keepKeyboard: function() {
1348 clearTimeout(UI.hideKeyboardTimeout);
1349 if(UI.keyboardVisible === true) {
1350 UI.showVirtualKeyboard();
1351 } else if(UI.keyboardVisible === false) {
1352 UI.hideVirtualKeyboard();
1353 }
1354 },
1355
1356 keyboardinputReset: function() {
1357 var kbi = document.getElementById('noVNC_keyboardinput');
1358 kbi.value = new Array(UI.defaultKeyboardinputLen).join("_");
1359 UI.lastKeyboardinput = kbi.value;
1360 },
1361
1362 // When normal keyboard events are left uncought, use the input events from
1363 // the keyboardinput element instead and generate the corresponding key events.
1364 // This code is required since some browsers on Android are inconsistent in
1365 // sending keyCodes in the normal keyboard events when using on screen keyboards.
1366 keyInput: function(event) {
1367
1368 if (!UI.rfb) return;
1369
1370 var newValue = event.target.value;
1371
1372 if (!UI.lastKeyboardinput) {
1373 UI.keyboardinputReset();
1374 }
1375 var oldValue = UI.lastKeyboardinput;
1376
1377 var newLen;
1378 try {
1379 // Try to check caret position since whitespace at the end
1380 // will not be considered by value.length in some browsers
1381 newLen = Math.max(event.target.selectionStart, newValue.length);
1382 } catch (err) {
1383 // selectionStart is undefined in Google Chrome
1384 newLen = newValue.length;
1385 }
1386 var oldLen = oldValue.length;
1387
1388 var backspaces;
1389 var inputs = newLen - oldLen;
1390 if (inputs < 0) {
1391 backspaces = -inputs;
1392 } else {
1393 backspaces = 0;
1394 }
1395
1396 // Compare the old string with the new to account for
1397 // text-corrections or other input that modify existing text
1398 var i;
1399 for (i = 0; i < Math.min(oldLen, newLen); i++) {
1400 if (newValue.charAt(i) != oldValue.charAt(i)) {
1401 inputs = newLen - i;
1402 backspaces = oldLen - i;
1403 break;
1404 }
1405 }
1406
1407 // Send the key events
1408 for (i = 0; i < backspaces; i++) {
1409 UI.rfb.sendKey(KeyTable.XK_BackSpace);
1410 }
1411 for (i = newLen - inputs; i < newLen; i++) {
1412 UI.rfb.sendKey(newValue.charCodeAt(i));
1413 }
1414
1415 // Control the text content length in the keyboardinput element
1416 if (newLen > 2 * UI.defaultKeyboardinputLen) {
1417 UI.keyboardinputReset();
1418 } else if (newLen < 1) {
1419 // There always have to be some text in the keyboardinput
1420 // element with which backspace can interact.
1421 UI.keyboardinputReset();
1422 // This sometimes causes the keyboard to disappear for a second
1423 // but it is required for the android keyboard to recognize that
1424 // text has been added to the field
1425 event.target.blur();
1426 // This has to be ran outside of the input handler in order to work
1427 setTimeout(UI.keepKeyboard, 0);
1428 } else {
1429 UI.lastKeyboardinput = newValue;
1430 }
1431 },
1432
1433 /* ------^-------
1434 * /KEYBOARD
1435 * ==============
1436 * EXTRA KEYS
1437 * ------v------*/
1438
1439 openExtraKeys: function() {
1440 UI.closeAllPanels();
1441 UI.openControlbar();
1442
1443 document.getElementById('noVNC_modifiers')
1444 .classList.add("noVNC_open");
1445 document.getElementById('noVNC_toggle_extra_keys_button')
1446 .classList.add("noVNC_selected");
1447 },
1448
1449 closeExtraKeys: function() {
1450 document.getElementById('noVNC_modifiers')
1451 .classList.remove("noVNC_open");
1452 document.getElementById('noVNC_toggle_extra_keys_button')
1453 .classList.remove("noVNC_selected");
1454 },
1455
1456 toggleExtraKeys: function() {
1457 UI.keepKeyboard();
1458 if(document.getElementById('noVNC_modifiers')
1459 .classList.contains("noVNC_open")) {
1460 UI.closeExtraKeys();
1461 } else {
1462 UI.openExtraKeys();
1463 }
1464 },
1465
1466 sendEsc: function() {
1467 UI.keepKeyboard();
1468 UI.rfb.sendKey(KeyTable.XK_Escape);
1469 },
1470
1471 sendTab: function() {
1472 UI.keepKeyboard();
1473 UI.rfb.sendKey(KeyTable.XK_Tab);
1474 },
1475
1476 toggleCtrl: function() {
1477 UI.keepKeyboard();
1478 var btn = document.getElementById('noVNC_toggle_ctrl_button');
1479 if (btn.classList.contains("noVNC_selected")) {
1480 UI.rfb.sendKey(KeyTable.XK_Control_L, false);
1481 btn.classList.remove("noVNC_selected");
1482 } else {
1483 UI.rfb.sendKey(KeyTable.XK_Control_L, true);
1484 btn.classList.add("noVNC_selected");
1485 }
1486 },
1487
1488 toggleAlt: function() {
1489 UI.keepKeyboard();
1490 var btn = document.getElementById('noVNC_toggle_alt_button');
1491 if (btn.classList.contains("noVNC_selected")) {
1492 UI.rfb.sendKey(KeyTable.XK_Alt_L, false);
1493 btn.classList.remove("noVNC_selected");
1494 } else {
1495 UI.rfb.sendKey(KeyTable.XK_Alt_L, true);
1496 btn.classList.add("noVNC_selected");
1497 }
1498 },
1499
1500 sendCtrlAltDel: function() {
1501 UI.keepKeyboard();
1502 UI.rfb.sendCtrlAltDel();
1503 },
1504
1505 /* ------^-------
1506 * /EXTRA KEYS
1507 * ==============
1508 * MISC
1509 * ------v------*/
1510
1511 setMouseButton: function(num) {
1512 if (UI.rfb) {
1513 UI.rfb.get_mouse().set_touchButton(num);
1514 }
1515
1516 var blist = [0, 1,2,4];
1517 for (var b = 0; b < blist.length; b++) {
1518 var button = document.getElementById('noVNC_mouse_button' + blist[b]);
1519 if (blist[b] === num) {
1520 button.classList.remove("noVNC_hidden");
1521 } else {
1522 button.classList.add("noVNC_hidden");
1523 }
1524 }
1525 },
1526
1527 displayBlur: function() {
1528 if (!UI.rfb) return;
1529
1530 UI.rfb.get_keyboard().set_focused(false);
1531 UI.rfb.get_mouse().set_focused(false);
1532 },
1533
1534 displayFocus: function() {
1535 if (!UI.rfb) return;
1536
1537 UI.rfb.get_keyboard().set_focused(true);
1538 UI.rfb.get_mouse().set_focused(true);
1539 },
1540
1541 updateDesktopName: function(rfb, name) {
1542 UI.desktopName = name;
1543 // Display the desktop name in the document title
1544 document.title = name + " - noVNC";
1545 },
1546
1547 bell: function(rfb) {
1548 if (WebUtil.getConfigVar('bell', 'on') === 'on') {
1549 document.getElementById('noVNC_bell').play();
1550 }
1551 },
1552
1553 //Helper to add options to dropdown.
1554 addOption: function(selectbox, text, value) {
1555 var optn = document.createElement("OPTION");
1556 optn.text = text;
1557 optn.value = value;
1558 selectbox.options.add(optn);
1559 },
1560
1561 /* ------^-------
1562 * /MISC
1563 * ==============
1564 */
1565 };
1566
1567 /* [module] UI.load(); */
1568 })();
1569
1570 /* [module] export default UI; */