]>
git.proxmox.com Git - mirror_novnc.git/blob - include/ui.js
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2012 Joel Martin
4 * Copyright (C) 2015 Samuel Mannehed for Cendio AB
5 * Licensed under MPL 2.0 (see LICENSE.txt)
7 * See README.md for usage and integration instructions.
10 /* jslint white: false, browser: true */
11 /* global window, $D, Util, WebUtil, RFB, Display */
20 // Load supporting scripts
21 window
.onscriptsload = function () { UI
.load(); };
22 Util
.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
23 "keysymdef.js", "keyboard.js", "input.js", "display.js",
24 "jsunzip.js", "rfb.js", "keysym.js"]);
30 connSettingsOpen
: false,
31 popupStatusOpen
: false,
33 keyboardVisible
: false,
34 hideKeyboardTimeout
: null,
35 lastKeyboardinput
: null,
36 defaultKeyboardinputLen
: 100,
37 extraKeysVisible
: false,
42 // Setup rfb object, load settings from browser storage, then call
43 // UI.init to setup the UI/menus
44 load: function (callback
) {
45 WebUtil
.initSettings(UI
.start
, callback
);
48 // Render default UI and initialize settings menu
49 start: function(callback
) {
50 UI
.isTouchDevice
= 'ontouchstart' in document
.documentElement
;
52 // Stylesheet selection dropdown
53 var sheet
= WebUtil
.selectStylesheet();
54 var sheets
= WebUtil
.getStylesheets();
56 for (i
= 0; i
< sheets
.length
; i
+= 1) {
57 UI
.addOption($D('noVNC_stylesheet'),sheets
[i
].title
, sheets
[i
].title
);
60 // Logging selection dropdown
61 var llevels
= ['error', 'warn', 'info', 'debug'];
62 for (i
= 0; i
< llevels
.length
; i
+= 1) {
63 UI
.addOption($D('noVNC_logging'),llevels
[i
], llevels
[i
]);
66 // Settings with immediate effects
67 UI
.initSetting('logging', 'warn');
68 WebUtil
.init_logging(UI
.getSetting('logging'));
70 UI
.initSetting('stylesheet', 'default');
71 WebUtil
.selectStylesheet(null);
72 // call twice to get around webkit bug
73 WebUtil
.selectStylesheet(UI
.getSetting('stylesheet'));
75 // if port == 80 (or 443) then it won't be present and should be
77 var port
= window
.location
.port
;
79 if (window
.location
.protocol
.substring(0,5) == 'https') {
82 else if (window
.location
.protocol
.substring(0,4) == 'http') {
87 /* Populate the controls if defaults are provided in the URL */
88 UI
.initSetting('host', window
.location
.hostname
);
89 UI
.initSetting('port', port
);
90 UI
.initSetting('password', '');
91 UI
.initSetting('encrypt', (window
.location
.protocol
=== "https:"));
92 UI
.initSetting('true_color', true);
93 UI
.initSetting('cursor', !UI
.isTouchDevice
);
94 UI
.initSetting('resize', 'off');
95 UI
.initSetting('shared', true);
96 UI
.initSetting('view_only', false);
97 UI
.initSetting('path', 'websockify');
98 UI
.initSetting('repeaterID', '');
100 var autoconnect
= WebUtil
.getQueryVar('autoconnect', false);
101 if (autoconnect
=== 'true' || autoconnect
== '1') {
108 UI
.updateVisualState();
110 $D('noVNC_host').focus();
112 // Show mouse selector buttons on touch screen devices
113 if (UI
.isTouchDevice
) {
114 // Show mobile buttons
115 $D('noVNC_mobile_buttons').style
.display
= "inline";
117 // Remove the address bar
118 setTimeout(function() { window
.scrollTo(0, 1); }, 100);
119 UI
.forceSetting('clip', true);
121 UI
.initSetting('clip', false);
127 Util
.addEvent(window
, 'resize', function () {
130 UI
.updateViewDragButton();
134 Util
.addEvent(window
, 'load', UI
.keyboardinputReset
);
136 Util
.addEvent(window
, 'beforeunload', function () {
137 if (UI
.rfb
&& UI
.rfb_state
=== 'normal') {
138 return "You are currently connected.";
142 // Show description by default when hosted at for kanaka.github.com
143 if (location
.host
=== "kanaka.github.io") {
144 // Open the description dialog
145 $D('noVNC_description').style
.display
= "block";
147 // Show the connect panel on first load unless autoconnecting
148 if (autoconnect
=== UI
.connSettingsOpen
) {
149 UI
.toggleConnectPanel();
153 // Add mouse event click/focus/blur event handlers to the UI
154 UI
.addMouseHandlers();
156 if (typeof callback
=== "function") {
161 initRFB: function () {
163 UI
.rfb
= new RFB({'target': $D('noVNC_canvas'),
164 'onUpdateState': UI
.updateState
,
165 'onXvpInit': UI
.updateXvpVisualState
,
166 'onClipboard': UI
.clipReceive
,
167 'onFBUComplete': UI
.FBUComplete
,
168 'onFBResize': UI
.updateViewDragButton
,
169 'onDesktopName': UI
.updateDocumentTitle
});
172 UI
.updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc
);
177 addMouseHandlers: function() {
178 // Setup interface handlers that can't be inline
179 $D("noVNC_view_drag_button").onclick
= UI
.setViewDrag
;
180 $D("noVNC_mouse_button0").onclick = function () { UI
.setMouseButton(1); };
181 $D("noVNC_mouse_button1").onclick = function () { UI
.setMouseButton(2); };
182 $D("noVNC_mouse_button2").onclick = function () { UI
.setMouseButton(4); };
183 $D("noVNC_mouse_button4").onclick = function () { UI
.setMouseButton(0); };
184 $D("showKeyboard").onclick
= UI
.showKeyboard
;
186 $D("keyboardinput").oninput
= UI
.keyInput
;
187 $D("keyboardinput").onblur
= UI
.keyInputBlur
;
188 $D("keyboardinput").onsubmit = function () { return false; };
190 $D("showExtraKeysButton").onclick
= UI
.showExtraKeys
;
191 $D("toggleCtrlButton").onclick
= UI
.toggleCtrl
;
192 $D("toggleAltButton").onclick
= UI
.toggleAlt
;
193 $D("sendTabButton").onclick
= UI
.sendTab
;
194 $D("sendEscButton").onclick
= UI
.sendEsc
;
196 $D("sendCtrlAltDelButton").onclick
= UI
.sendCtrlAltDel
;
197 $D("xvpShutdownButton").onclick
= UI
.xvpShutdown
;
198 $D("xvpRebootButton").onclick
= UI
.xvpReboot
;
199 $D("xvpResetButton").onclick
= UI
.xvpReset
;
200 $D("noVNC_status").onclick
= UI
.togglePopupStatusPanel
;
201 $D("noVNC_popup_status_panel").onclick
= UI
.togglePopupStatusPanel
;
202 $D("xvpButton").onclick
= UI
.toggleXvpPanel
;
203 $D("clipboardButton").onclick
= UI
.toggleClipboardPanel
;
204 $D("settingsButton").onclick
= UI
.toggleSettingsPanel
;
205 $D("connectButton").onclick
= UI
.toggleConnectPanel
;
206 $D("disconnectButton").onclick
= UI
.disconnect
;
207 $D("descriptionButton").onclick
= UI
.toggleConnectPanel
;
209 $D("noVNC_clipboard_text").onfocus
= UI
.displayBlur
;
210 $D("noVNC_clipboard_text").onblur
= UI
.displayFocus
;
211 $D("noVNC_clipboard_text").onchange
= UI
.clipSend
;
212 $D("noVNC_clipboard_clear_button").onclick
= UI
.clipClear
;
214 $D("noVNC_settings_menu").onmouseover
= UI
.displayBlur
;
215 $D("noVNC_settings_menu").onmouseover
= UI
.displayFocus
;
216 $D("noVNC_apply").onclick
= UI
.settingsApply
;
218 $D("noVNC_connect_button").onclick
= UI
.connect
;
220 $D("noVNC_resize").onchange = function () {
221 var connected
= UI
.rfb
&& UI
.rfb_state
=== 'normal';
222 UI
.enableDisableClip(connected
);
226 onresize: function (callback
) {
229 var size
= UI
.getCanvasLimit();
231 if (size
&& UI
.rfb_state
=== 'normal' && UI
.rfb
.get_display()) {
232 var display
= UI
.rfb
.get_display();
233 var scaleType
= UI
.getSetting('resize');
234 if (scaleType
=== 'remote') {
235 // use remote resizing
237 // When the local window has been resized, wait until the size remains
238 // the same for 0.5 seconds before sending the request for changing
239 // the resolution of the session
240 clearTimeout(resizeTimeout
);
241 resizeTimeout
= setTimeout(function(){
242 display
.set_maxWidth(size
.w
);
243 display
.set_maxHeight(size
.h
);
244 Util
.Debug('Attempting setDesktopSize(' +
245 size
.w
+ ', ' + size
.h
+ ')');
246 UI
.rfb
.setDesktopSize(size
.w
, size
.h
);
248 } else if (scaleType
=== 'scale' || scaleType
=== 'downscale') {
251 var downscaleOnly
= scaleType
=== 'downscale';
252 var scaleRatio
= display
.autoscale(size
.w
, size
.h
, downscaleOnly
);
253 UI
.rfb
.get_mouse().set_scale(scaleRatio
);
254 Util
.Debug('Scaling by ' + UI
.rfb
.get_mouse().get_scale());
259 getCanvasLimit: function () {
260 var container
= $D('noVNC_container');
262 // Hide the scrollbars until the size is calculated
263 container
.style
.overflow
= "hidden";
265 var pos
= Util
.getPosition(container
);
269 container
.style
.overflow
= "visible";
271 if (isNaN(w
) || isNaN(h
)) {
278 // Read form control compatible setting from cookie
279 getSetting: function(name
) {
280 var ctrl
= $D('noVNC_' + name
);
281 var val
= WebUtil
.readSetting(name
);
282 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
283 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
292 // Update cookie and form control setting. If value is not set, then
293 // updates from control to current cookie setting.
294 updateSetting: function(name
, value
) {
296 // Save the cookie for this session
297 if (typeof value
!== 'undefined') {
298 WebUtil
.writeSetting(name
, value
);
301 // Update the settings control
302 value
= UI
.getSetting(name
);
304 var ctrl
= $D('noVNC_' + name
);
305 if (ctrl
.type
=== 'checkbox') {
306 ctrl
.checked
= value
;
308 } else if (typeof ctrl
.options
!== 'undefined') {
309 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
310 if (ctrl
.options
[i
].value
=== value
) {
311 ctrl
.selectedIndex
= i
;
316 /*Weird IE9 error leads to 'null' appearring
317 in textboxes instead of ''.*/
318 if (value
=== null) {
325 // Save control setting to cookie
326 saveSetting: function(name
) {
327 var val
, ctrl
= $D('noVNC_' + name
);
328 if (ctrl
.type
=== 'checkbox') {
330 } else if (typeof ctrl
.options
!== 'undefined') {
331 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
335 WebUtil
.writeSetting(name
, val
);
336 //Util.Debug("Setting saved '" + name + "=" + val + "'");
340 // Initial page load read/initialization of settings
341 initSetting: function(name
, defVal
) {
342 // Check Query string followed by cookie
343 var val
= WebUtil
.getQueryVar(name
);
345 val
= WebUtil
.readSetting(name
, defVal
);
347 UI
.updateSetting(name
, val
);
351 // Force a setting to be a certain value
352 forceSetting: function(name
, val
) {
353 UI
.updateSetting(name
, val
);
358 // Show the popup status panel
359 togglePopupStatusPanel: function() {
360 var psp
= $D('noVNC_popup_status_panel');
361 if (UI
.popupStatusOpen
=== true) {
362 psp
.style
.display
= "none";
363 UI
.popupStatusOpen
= false;
365 psp
.innerHTML
= $D('noVNC_status').innerHTML
;
366 psp
.style
.display
= "block";
367 psp
.style
.left
= window
.innerWidth
/2 -
368 parseInt(window
.getComputedStyle(psp
, false).width
)/2 -30 + "px";
369 UI
.popupStatusOpen
= true;
373 // Show the XVP panel
374 toggleXvpPanel: function() {
375 // Close the description panel
376 $D('noVNC_description').style
.display
= "none";
377 // Close settings if open
378 if (UI
.settingsOpen
=== true) {
380 UI
.closeSettingsMenu();
382 // Close connection settings if open
383 if (UI
.connSettingsOpen
=== true) {
384 UI
.toggleConnectPanel();
386 // Close popup status panel if open
387 if (UI
.popupStatusOpen
=== true) {
388 UI
.togglePopupStatusPanel();
390 // Close clipboard panel if open
391 if (UI
.clipboardOpen
=== true) {
392 UI
.toggleClipboardPanel();
395 if (UI
.xvpOpen
=== true) {
396 $D('noVNC_xvp').style
.display
= "none";
397 $D('xvpButton').className
= "noVNC_status_button";
400 $D('noVNC_xvp').style
.display
= "block";
401 $D('xvpButton').className
= "noVNC_status_button_selected";
406 // Show the clipboard panel
407 toggleClipboardPanel: function() {
408 // Close the description panel
409 $D('noVNC_description').style
.display
= "none";
410 // Close settings if open
411 if (UI
.settingsOpen
=== true) {
413 UI
.closeSettingsMenu();
415 // Close connection settings if open
416 if (UI
.connSettingsOpen
=== true) {
417 UI
.toggleConnectPanel();
419 // Close popup status panel if open
420 if (UI
.popupStatusOpen
=== true) {
421 UI
.togglePopupStatusPanel();
423 // Close XVP panel if open
424 if (UI
.xvpOpen
=== true) {
427 // Toggle Clipboard Panel
428 if (UI
.clipboardOpen
=== true) {
429 $D('noVNC_clipboard').style
.display
= "none";
430 $D('clipboardButton').className
= "noVNC_status_button";
431 UI
.clipboardOpen
= false;
433 $D('noVNC_clipboard').style
.display
= "block";
434 $D('clipboardButton').className
= "noVNC_status_button_selected";
435 UI
.clipboardOpen
= true;
439 // Show the connection settings panel/menu
440 toggleConnectPanel: function() {
441 // Close the description panel
442 $D('noVNC_description').style
.display
= "none";
443 // Close connection settings if open
444 if (UI
.settingsOpen
=== true) {
446 UI
.closeSettingsMenu();
447 $D('connectButton').className
= "noVNC_status_button";
449 // Close clipboard panel if open
450 if (UI
.clipboardOpen
=== true) {
451 UI
.toggleClipboardPanel();
453 // Close popup status panel if open
454 if (UI
.popupStatusOpen
=== true) {
455 UI
.togglePopupStatusPanel();
457 // Close XVP panel if open
458 if (UI
.xvpOpen
=== true) {
462 // Toggle Connection Panel
463 if (UI
.connSettingsOpen
=== true) {
464 $D('noVNC_controls').style
.display
= "none";
465 $D('connectButton').className
= "noVNC_status_button";
466 UI
.connSettingsOpen
= false;
467 UI
.saveSetting('host');
468 UI
.saveSetting('port');
469 //UI.saveSetting('password');
471 $D('noVNC_controls').style
.display
= "block";
472 $D('connectButton').className
= "noVNC_status_button_selected";
473 UI
.connSettingsOpen
= true;
474 $D('noVNC_host').focus();
478 // Toggle the settings menu:
479 // On open, settings are refreshed from saved cookies.
480 // On close, settings are applied
481 toggleSettingsPanel: function() {
482 // Close the description panel
483 $D('noVNC_description').style
.display
= "none";
484 if (UI
.settingsOpen
) {
486 UI
.closeSettingsMenu();
488 UI
.updateSetting('encrypt');
489 UI
.updateSetting('true_color');
490 if (Util
.browserSupportsCursorURIs()) {
491 UI
.updateSetting('cursor');
493 UI
.updateSetting('cursor', !UI
.isTouchDevice
);
494 $D('noVNC_cursor').disabled
= true;
496 UI
.updateSetting('clip');
497 UI
.updateSetting('resize');
498 UI
.updateSetting('shared');
499 UI
.updateSetting('view_only');
500 UI
.updateSetting('path');
501 UI
.updateSetting('repeaterID');
502 UI
.updateSetting('stylesheet');
503 UI
.updateSetting('logging');
505 UI
.openSettingsMenu();
510 openSettingsMenu: function() {
511 // Close the description panel
512 $D('noVNC_description').style
.display
= "none";
513 // Close clipboard panel if open
514 if (UI
.clipboardOpen
=== true) {
515 UI
.toggleClipboardPanel();
517 // Close connection settings if open
518 if (UI
.connSettingsOpen
=== true) {
519 UI
.toggleConnectPanel();
521 // Close popup status panel if open
522 if (UI
.popupStatusOpen
=== true) {
523 UI
.togglePopupStatusPanel();
525 // Close XVP panel if open
526 if (UI
.xvpOpen
=== true) {
529 $D('noVNC_settings').style
.display
= "block";
530 $D('settingsButton').className
= "noVNC_status_button_selected";
531 UI
.settingsOpen
= true;
534 // Close menu (without applying settings)
535 closeSettingsMenu: function() {
536 $D('noVNC_settings').style
.display
= "none";
537 $D('settingsButton').className
= "noVNC_status_button";
538 UI
.settingsOpen
= false;
541 // Save/apply settings when 'Apply' button is pressed
542 settingsApply: function() {
543 //Util.Debug(">> settingsApply");
544 UI
.saveSetting('encrypt');
545 UI
.saveSetting('true_color');
546 if (Util
.browserSupportsCursorURIs()) {
547 UI
.saveSetting('cursor');
550 UI
.saveSetting('resize');
552 if (UI
.getSetting('resize') === 'downscale' || UI
.getSetting('resize') === 'scale') {
553 UI
.forceSetting('clip', false);
556 UI
.saveSetting('clip');
557 UI
.saveSetting('shared');
558 UI
.saveSetting('view_only');
559 UI
.saveSetting('path');
560 UI
.saveSetting('repeaterID');
561 UI
.saveSetting('stylesheet');
562 UI
.saveSetting('logging');
564 // Settings with immediate (non-connected related) effect
565 WebUtil
.selectStylesheet(UI
.getSetting('stylesheet'));
566 WebUtil
.init_logging(UI
.getSetting('logging'));
568 UI
.setViewDrag(UI
.rfb
&& UI
.rfb
.get_viewportDrag());
569 //Util.Debug("<< settingsApply");
574 setPassword: function() {
575 UI
.rfb
.sendPassword($D('noVNC_password').value
);
576 //Reset connect button.
577 $D('noVNC_connect_button').value
= "Connect";
578 $D('noVNC_connect_button').onclick
= UI
.Connect
;
579 //Hide connection panel.
580 UI
.toggleConnectPanel();
584 sendCtrlAltDel: function() {
585 UI
.rfb
.sendCtrlAltDel();
588 xvpShutdown: function() {
589 UI
.rfb
.xvpShutdown();
592 xvpReboot: function() {
596 xvpReset: function() {
600 setMouseButton: function(num
) {
601 if (typeof num
=== 'undefined') {
602 // Disable mouse buttons
606 UI
.rfb
.get_mouse().set_touchButton(num
);
609 var blist
= [0, 1,2,4];
610 for (var b
= 0; b
< blist
.length
; b
++) {
611 var button
= $D('noVNC_mouse_button' + blist
[b
]);
612 if (blist
[b
] === num
) {
613 button
.style
.display
= "";
615 button
.style
.display
= "none";
620 updateState: function(rfb
, state
, oldstate
, msg
) {
621 UI
.rfb_state
= state
;
626 klass
= "noVNC_status_error";
629 klass
= "noVNC_status_normal";
632 $D('noVNC_logo').style
.display
= "block";
633 $D('noVNC_container').style
.display
= "none";
636 klass
= "noVNC_status_normal";
639 UI
.toggleConnectPanel();
641 $D('noVNC_connect_button').value
= "Send Password";
642 $D('noVNC_connect_button').onclick
= UI
.setPassword
;
643 $D('noVNC_password').focus();
645 klass
= "noVNC_status_warn";
648 klass
= "noVNC_status_warn";
652 if (typeof(msg
) !== 'undefined') {
653 $D('noVNC-control-bar').setAttribute("class", klass
);
654 $D('noVNC_status').innerHTML
= msg
;
657 UI
.updateVisualState();
660 // Disable/enable controls depending on connection state
661 updateVisualState: function() {
662 var connected
= UI
.rfb
&& UI
.rfb_state
=== 'normal';
664 //Util.Debug(">> updateVisualState");
665 $D('noVNC_encrypt').disabled
= connected
;
666 $D('noVNC_true_color').disabled
= connected
;
667 if (Util
.browserSupportsCursorURIs()) {
668 $D('noVNC_cursor').disabled
= connected
;
670 UI
.updateSetting('cursor', !UI
.isTouchDevice
);
671 $D('noVNC_cursor').disabled
= true;
674 UI
.enableDisableClip(connected
);
675 $D('noVNC_resize').disabled
= connected
;
676 $D('noVNC_shared').disabled
= connected
;
677 $D('noVNC_view_only').disabled
= connected
;
678 $D('noVNC_path').disabled
= connected
;
679 $D('noVNC_repeaterID').disabled
= connected
;
683 UI
.setMouseButton(1);
684 $D('clipboardButton').style
.display
= "inline";
685 $D('showKeyboard').style
.display
= "inline";
686 $D('noVNC_extra_keys').style
.display
= "";
687 $D('sendCtrlAltDelButton').style
.display
= "inline";
690 $D('clipboardButton').style
.display
= "none";
691 $D('showKeyboard').style
.display
= "none";
692 $D('noVNC_extra_keys').style
.display
= "none";
693 $D('sendCtrlAltDelButton').style
.display
= "none";
694 UI
.updateXvpVisualState(0);
697 // State change disables viewport dragging.
698 // It is enabled (toggled) by direct click on the button
699 UI
.setViewDrag(false);
701 switch (UI
.rfb_state
) {
705 $D('connectButton').style
.display
= "";
706 $D('disconnectButton').style
.display
= "none";
707 UI
.connSettingsOpen
= false;
708 UI
.toggleConnectPanel();
711 $D('connectButton').style
.display
= "";
712 $D('disconnectButton').style
.display
= "none";
715 $D('connectButton').style
.display
= "none";
716 $D('disconnectButton').style
.display
= "";
720 //Util.Debug("<< updateVisualState");
723 // Disable/enable XVP button
724 updateXvpVisualState: function(ver
) {
726 $D('xvpButton').style
.display
= 'inline';
728 $D('xvpButton').style
.display
= 'none';
729 // Close XVP panel if open
730 if (UI
.xvpOpen
=== true) {
736 enableDisableClip: function (connected
) {
737 var resizeElem
= $D('noVNC_resize');
738 if (resizeElem
.value
=== 'downscale' || resizeElem
.value
=== 'scale') {
739 UI
.forceSetting('clip', false);
740 $D('noVNC_clip').disabled
= true;
742 $D('noVNC_clip').disabled
= connected
|| UI
.isTouchDevice
;
743 if (UI
.isTouchDevice
) {
744 UI
.forceSetting('clip', true);
749 // This resize can not be done until we know from the first Frame Buffer Update
750 // if it is supported or not.
751 // The resize is needed to make sure the server desktop size is updated to the
752 // corresponding size of the current local window when reconnecting to an
754 FBUComplete: function(rfb
, fbu
) {
756 UI
.rfb
.set_onFBUComplete(function() { });
759 // Display the desktop name in the document title
760 updateDocumentTitle: function(rfb
, name
) {
761 document
.title
= name
+ " - noVNC";
764 clipReceive: function(rfb
, text
) {
765 Util
.Debug(">> UI.clipReceive: " + text
.substr(0,40) + "...");
766 $D('noVNC_clipboard_text').value
= text
;
767 Util
.Debug("<< UI.clipReceive");
770 connect: function() {
771 UI
.closeSettingsMenu();
772 UI
.toggleConnectPanel();
774 var host
= $D('noVNC_host').value
;
775 var port
= $D('noVNC_port').value
;
776 var password
= $D('noVNC_password').value
;
777 var path
= $D('noVNC_path').value
;
778 if ((!host
) || (!port
)) {
779 throw new Error("Must set host and port");
782 if (!UI
.initRFB()) return;
784 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
785 UI
.rfb
.set_true_color(UI
.getSetting('true_color'));
786 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
787 UI
.rfb
.set_shared(UI
.getSetting('shared'));
788 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
789 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
791 UI
.rfb
.connect(host
, port
, password
, path
);
794 setTimeout(UI
.setBarPosition
, 100);
795 $D('noVNC_logo').style
.display
= "none";
796 $D('noVNC_container').style
.display
= "inline";
799 disconnect: function() {
800 UI
.closeSettingsMenu();
803 // Restore the callback used for initial resize
804 UI
.rfb
.set_onFBUComplete(UI
.FBUComplete
);
806 $D('noVNC_logo').style
.display
= "block";
807 $D('noVNC_container').style
.display
= "none";
809 // Don't display the connection settings until we're actually disconnected
812 displayBlur: function() {
815 UI
.rfb
.get_keyboard().set_focused(false);
816 UI
.rfb
.get_mouse().set_focused(false);
819 displayFocus: function() {
822 UI
.rfb
.get_keyboard().set_focused(true);
823 UI
.rfb
.get_mouse().set_focused(true);
826 clipClear: function() {
827 $D('noVNC_clipboard_text').value
= "";
828 UI
.rfb
.clipboardPasteFrom("");
831 clipSend: function() {
832 var text
= $D('noVNC_clipboard_text').value
;
833 Util
.Debug(">> UI.clipSend: " + text
.substr(0,40) + "...");
834 UI
.rfb
.clipboardPasteFrom(text
);
835 Util
.Debug("<< UI.clipSend");
838 // Enable/disable and configure viewport clipping
839 setViewClip: function(clip
) {
842 display
= UI
.rfb
.get_display();
847 var cur_clip
= display
.get_viewport();
849 if (typeof(clip
) !== 'boolean') {
850 // Use current setting
851 clip
= UI
.getSetting('clip');
854 if (clip
&& !cur_clip
) {
856 UI
.updateSetting('clip', true);
857 } else if (!clip
&& cur_clip
) {
859 UI
.updateSetting('clip', false);
860 display
.set_viewport(false);
861 display
.set_maxWidth(0);
862 display
.set_maxHeight(0);
863 display
.viewportChangeSize();
865 if (UI
.getSetting('clip')) {
866 // If clipping, update clipping settings
867 display
.set_viewport(true);
869 var size
= UI
.getCanvasLimit();
871 display
.set_maxWidth(size
.w
);
872 display
.set_maxHeight(size
.h
);
874 // Hide potential scrollbars that can skew the position
875 $D('noVNC_container').style
.overflow
= "hidden";
877 // The x position marks the left margin of the canvas,
878 // remove the margin from both sides to keep it centered
879 var new_w
= size
.w
- (2 * Util
.getPosition($D('noVNC_canvas')).x
);
881 $D('noVNC_container').style
.overflow
= "visible";
883 display
.viewportChangeSize(new_w
, size
.h
);
888 // Toggle/set/unset the viewport drag/move button
889 setViewDrag: function(drag
) {
892 UI
.updateViewDragButton();
894 if (typeof(drag
) === "undefined" ||
895 typeof(drag
) === "object") {
896 // If not specified, then toggle
897 drag
= !UI
.rfb
.get_viewportDrag();
899 var vmb
= $D('noVNC_view_drag_button');
901 vmb
.className
= "noVNC_status_button_selected";
902 UI
.rfb
.set_viewportDrag(true);
904 vmb
.className
= "noVNC_status_button";
905 UI
.rfb
.set_viewportDrag(false);
909 updateViewDragButton: function() {
910 var vmb
= $D('noVNC_view_drag_button');
911 if (UI
.rfb_state
=== 'normal' &&
912 UI
.rfb
.get_display().get_viewport() &&
913 UI
.rfb
.get_display().clippingDisplay()) {
914 vmb
.style
.display
= "inline";
916 vmb
.style
.display
= "none";
920 // On touch devices, show the OS keyboard
921 showKeyboard: function() {
922 var kbi
= $D('keyboardinput');
923 var skb
= $D('showKeyboard');
924 var l
= kbi
.value
.length
;
925 if(UI
.keyboardVisible
=== false) {
927 try { kbi
.setSelectionRange(l
, l
); } // Move the caret to the end
928 catch (err
) {} // setSelectionRange is undefined in Google Chrome
929 UI
.keyboardVisible
= true;
930 skb
.className
= "noVNC_status_button_selected";
931 } else if(UI
.keyboardVisible
=== true) {
933 skb
.className
= "noVNC_status_button";
934 UI
.keyboardVisible
= false;
938 keepKeyboard: function() {
939 clearTimeout(UI
.hideKeyboardTimeout
);
940 if(UI
.keyboardVisible
=== true) {
941 $D('keyboardinput').focus();
942 $D('showKeyboard').className
= "noVNC_status_button_selected";
943 } else if(UI
.keyboardVisible
=== false) {
944 $D('keyboardinput').blur();
945 $D('showKeyboard').className
= "noVNC_status_button";
949 keyboardinputReset: function() {
950 var kbi
= $D('keyboardinput');
951 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
952 UI
.lastKeyboardinput
= kbi
.value
;
955 // When normal keyboard events are left uncought, use the input events from
956 // the keyboardinput element instead and generate the corresponding key events.
957 // This code is required since some browsers on Android are inconsistent in
958 // sending keyCodes in the normal keyboard events when using on screen keyboards.
959 keyInput: function(event
) {
963 var newValue
= event
.target
.value
;
964 var oldValue
= UI
.lastKeyboardinput
;
968 // Try to check caret position since whitespace at the end
969 // will not be considered by value.length in some browsers
970 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
972 // selectionStart is undefined in Google Chrome
973 newLen
= newValue
.length
;
975 var oldLen
= oldValue
.length
;
978 var inputs
= newLen
- oldLen
;
980 backspaces
= -inputs
;
985 // Compare the old string with the new to account for
986 // text-corrections or other input that modify existing text
988 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
989 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
991 backspaces
= oldLen
- i
;
996 // Send the key events
997 for (i
= 0; i
< backspaces
; i
++) {
998 UI
.rfb
.sendKey(XK_BackSpace
);
1000 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1001 UI
.rfb
.sendKey(newValue
.charCodeAt(i
));
1004 // Control the text content length in the keyboardinput element
1005 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1006 UI
.keyboardinputReset();
1007 } else if (newLen
< 1) {
1008 // There always have to be some text in the keyboardinput
1009 // element with which backspace can interact.
1010 UI
.keyboardinputReset();
1011 // This sometimes causes the keyboard to disappear for a second
1012 // but it is required for the android keyboard to recognize that
1013 // text has been added to the field
1014 event
.target
.blur();
1015 // This has to be ran outside of the input handler in order to work
1016 setTimeout(function() { UI
.keepKeyboard(); }, 0);
1018 UI
.lastKeyboardinput
= newValue
;
1022 keyInputBlur: function() {
1023 $D('showKeyboard').className
= "noVNC_status_button";
1024 //Weird bug in iOS if you change keyboardVisible
1025 //here it does not actually occur so next time
1026 //you click keyboard icon it doesnt work.
1027 UI
.hideKeyboardTimeout
= setTimeout(function() { UI
.setKeyboard(); },100);
1030 showExtraKeys: function() {
1032 if(UI
.extraKeysVisible
=== false) {
1033 $D('toggleCtrlButton').style
.display
= "inline";
1034 $D('toggleAltButton').style
.display
= "inline";
1035 $D('sendTabButton').style
.display
= "inline";
1036 $D('sendEscButton').style
.display
= "inline";
1037 $D('showExtraKeysButton').className
= "noVNC_status_button_selected";
1038 UI
.extraKeysVisible
= true;
1039 } else if(UI
.extraKeysVisible
=== true) {
1040 $D('toggleCtrlButton').style
.display
= "";
1041 $D('toggleAltButton').style
.display
= "";
1042 $D('sendTabButton').style
.display
= "";
1043 $D('sendEscButton').style
.display
= "";
1044 $D('showExtraKeysButton').className
= "noVNC_status_button";
1045 UI
.extraKeysVisible
= false;
1049 toggleCtrl: function() {
1051 if(UI
.ctrlOn
=== false) {
1052 UI
.rfb
.sendKey(XK_Control_L
, true);
1053 $D('toggleCtrlButton').className
= "noVNC_status_button_selected";
1055 } else if(UI
.ctrlOn
=== true) {
1056 UI
.rfb
.sendKey(XK_Control_L
, false);
1057 $D('toggleCtrlButton').className
= "noVNC_status_button";
1062 toggleAlt: function() {
1064 if(UI
.altOn
=== false) {
1065 UI
.rfb
.sendKey(XK_Alt_L
, true);
1066 $D('toggleAltButton').className
= "noVNC_status_button_selected";
1068 } else if(UI
.altOn
=== true) {
1069 UI
.rfb
.sendKey(XK_Alt_L
, false);
1070 $D('toggleAltButton').className
= "noVNC_status_button";
1075 sendTab: function() {
1077 UI
.rfb
.sendKey(XK_Tab
);
1080 sendEsc: function() {
1082 UI
.rfb
.sendKey(XK_Escape
);
1085 setKeyboard: function() {
1086 UI
.keyboardVisible
= false;
1089 //Helper to add options to dropdown.
1090 addOption: function(selectbox
, text
, value
) {
1091 var optn
= document
.createElement("OPTION");
1094 selectbox
.options
.add(optn
);
1097 setBarPosition: function() {
1098 $D('noVNC-control-bar').style
.top
= (window
.pageYOffset
) + 'px';
1099 $D('noVNC_mobile_buttons').style
.left
= (window
.pageXOffset
) + 'px';
1101 var vncwidth
= $D('noVNC_screen').style
.offsetWidth
;
1102 $D('noVNC-control-bar').style
.width
= vncwidth
+ 'px';