]>
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
;
189 $D("showExtraKeysButton").onclick
= UI
.showExtraKeys
;
190 $D("toggleCtrlButton").onclick
= UI
.toggleCtrl
;
191 $D("toggleAltButton").onclick
= UI
.toggleAlt
;
192 $D("sendTabButton").onclick
= UI
.sendTab
;
193 $D("sendEscButton").onclick
= UI
.sendEsc
;
195 $D("sendCtrlAltDelButton").onclick
= UI
.sendCtrlAltDel
;
196 $D("xvpShutdownButton").onclick
= UI
.xvpShutdown
;
197 $D("xvpRebootButton").onclick
= UI
.xvpReboot
;
198 $D("xvpResetButton").onclick
= UI
.xvpReset
;
199 $D("noVNC_status").onclick
= UI
.togglePopupStatusPanel
;
200 $D("noVNC_popup_status_panel").onclick
= UI
.togglePopupStatusPanel
;
201 $D("xvpButton").onclick
= UI
.toggleXvpPanel
;
202 $D("clipboardButton").onclick
= UI
.toggleClipboardPanel
;
203 $D("settingsButton").onclick
= UI
.toggleSettingsPanel
;
204 $D("connectButton").onclick
= UI
.toggleConnectPanel
;
205 $D("disconnectButton").onclick
= UI
.disconnect
;
206 $D("descriptionButton").onclick
= UI
.toggleConnectPanel
;
208 $D("noVNC_clipboard_text").onfocus
= UI
.displayBlur
;
209 $D("noVNC_clipboard_text").onblur
= UI
.displayFocus
;
210 $D("noVNC_clipboard_text").onchange
= UI
.clipSend
;
211 $D("noVNC_clipboard_clear_button").onclick
= UI
.clipClear
;
213 $D("noVNC_settings_menu").onmouseover
= UI
.displayBlur
;
214 $D("noVNC_settings_menu").onmouseover
= UI
.displayFocus
;
215 $D("noVNC_apply").onclick
= UI
.settingsApply
;
217 $D("noVNC_connect_button").onclick
= UI
.connect
;
219 $D("noVNC_resize").onchange = function () {
220 var connected
= UI
.rfb
&& UI
.rfb_state
=== 'normal';
221 UI
.enableDisableClip(connected
);
225 onresize: function (callback
) {
228 var size
= UI
.getCanvasLimit();
230 if (size
&& UI
.rfb_state
=== 'normal' && UI
.rfb
.get_display()) {
231 var display
= UI
.rfb
.get_display();
232 var scaleType
= UI
.getSetting('resize');
233 if (scaleType
=== 'remote') {
234 // use remote resizing
236 // When the local window has been resized, wait until the size remains
237 // the same for 0.5 seconds before sending the request for changing
238 // the resolution of the session
239 clearTimeout(resizeTimeout
);
240 resizeTimeout
= setTimeout(function(){
241 display
.set_maxWidth(size
.w
);
242 display
.set_maxHeight(size
.h
);
243 Util
.Debug('Attempting setDesktopSize(' +
244 size
.w
+ ', ' + size
.h
+ ')');
245 UI
.rfb
.setDesktopSize(size
.w
, size
.h
);
247 } else if (scaleType
=== 'scale' || scaleType
=== 'downscale') {
250 var downscaleOnly
= scaleType
=== 'downscale';
251 var scaleRatio
= display
.autoscale(size
.w
, size
.h
, downscaleOnly
);
252 UI
.rfb
.get_mouse().set_scale(scaleRatio
);
253 Util
.Debug('Scaling by ' + UI
.rfb
.get_mouse().get_scale());
258 getCanvasLimit: function () {
259 var container
= $D('noVNC_container');
261 // Hide the scrollbars until the size is calculated
262 container
.style
.overflow
= "hidden";
264 var pos
= Util
.getPosition(container
);
268 container
.style
.overflow
= "visible";
270 if (isNaN(w
) || isNaN(h
)) {
277 // Read form control compatible setting from cookie
278 getSetting: function(name
) {
279 var ctrl
= $D('noVNC_' + name
);
280 var val
= WebUtil
.readSetting(name
);
281 if (typeof val
!== 'undefined' && val
!== null && ctrl
.type
=== 'checkbox') {
282 if (val
.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
291 // Update cookie and form control setting. If value is not set, then
292 // updates from control to current cookie setting.
293 updateSetting: function(name
, value
) {
295 // Save the cookie for this session
296 if (typeof value
!== 'undefined') {
297 WebUtil
.writeSetting(name
, value
);
300 // Update the settings control
301 value
= UI
.getSetting(name
);
303 var ctrl
= $D('noVNC_' + name
);
304 if (ctrl
.type
=== 'checkbox') {
305 ctrl
.checked
= value
;
307 } else if (typeof ctrl
.options
!== 'undefined') {
308 for (var i
= 0; i
< ctrl
.options
.length
; i
+= 1) {
309 if (ctrl
.options
[i
].value
=== value
) {
310 ctrl
.selectedIndex
= i
;
315 /*Weird IE9 error leads to 'null' appearring
316 in textboxes instead of ''.*/
317 if (value
=== null) {
324 // Save control setting to cookie
325 saveSetting: function(name
) {
326 var val
, ctrl
= $D('noVNC_' + name
);
327 if (ctrl
.type
=== 'checkbox') {
329 } else if (typeof ctrl
.options
!== 'undefined') {
330 val
= ctrl
.options
[ctrl
.selectedIndex
].value
;
334 WebUtil
.writeSetting(name
, val
);
335 //Util.Debug("Setting saved '" + name + "=" + val + "'");
339 // Initial page load read/initialization of settings
340 initSetting: function(name
, defVal
) {
341 // Check Query string followed by cookie
342 var val
= WebUtil
.getQueryVar(name
);
344 val
= WebUtil
.readSetting(name
, defVal
);
346 UI
.updateSetting(name
, val
);
350 // Force a setting to be a certain value
351 forceSetting: function(name
, val
) {
352 UI
.updateSetting(name
, val
);
357 // Show the popup status panel
358 togglePopupStatusPanel: function() {
359 var psp
= $D('noVNC_popup_status_panel');
360 if (UI
.popupStatusOpen
=== true) {
361 psp
.style
.display
= "none";
362 UI
.popupStatusOpen
= false;
364 psp
.innerHTML
= $D('noVNC_status').innerHTML
;
365 psp
.style
.display
= "block";
366 psp
.style
.left
= window
.innerWidth
/2 -
367 parseInt(window
.getComputedStyle(psp
, false).width
)/2 -30 + "px";
368 UI
.popupStatusOpen
= true;
372 // Show the XVP panel
373 toggleXvpPanel: function() {
374 // Close the description panel
375 $D('noVNC_description').style
.display
= "none";
376 // Close settings if open
377 if (UI
.settingsOpen
=== true) {
379 UI
.closeSettingsMenu();
381 // Close connection settings if open
382 if (UI
.connSettingsOpen
=== true) {
383 UI
.toggleConnectPanel();
385 // Close popup status panel if open
386 if (UI
.popupStatusOpen
=== true) {
387 UI
.togglePopupStatusPanel();
389 // Close clipboard panel if open
390 if (UI
.clipboardOpen
=== true) {
391 UI
.toggleClipboardPanel();
394 if (UI
.xvpOpen
=== true) {
395 $D('noVNC_xvp').style
.display
= "none";
396 $D('xvpButton').className
= "noVNC_status_button";
399 $D('noVNC_xvp').style
.display
= "block";
400 $D('xvpButton').className
= "noVNC_status_button_selected";
405 // Show the clipboard panel
406 toggleClipboardPanel: function() {
407 // Close the description panel
408 $D('noVNC_description').style
.display
= "none";
409 // Close settings if open
410 if (UI
.settingsOpen
=== true) {
412 UI
.closeSettingsMenu();
414 // Close connection settings if open
415 if (UI
.connSettingsOpen
=== true) {
416 UI
.toggleConnectPanel();
418 // Close popup status panel if open
419 if (UI
.popupStatusOpen
=== true) {
420 UI
.togglePopupStatusPanel();
422 // Close XVP panel if open
423 if (UI
.xvpOpen
=== true) {
426 // Toggle Clipboard Panel
427 if (UI
.clipboardOpen
=== true) {
428 $D('noVNC_clipboard').style
.display
= "none";
429 $D('clipboardButton').className
= "noVNC_status_button";
430 UI
.clipboardOpen
= false;
432 $D('noVNC_clipboard').style
.display
= "block";
433 $D('clipboardButton').className
= "noVNC_status_button_selected";
434 UI
.clipboardOpen
= true;
438 // Show the connection settings panel/menu
439 toggleConnectPanel: function() {
440 // Close the description panel
441 $D('noVNC_description').style
.display
= "none";
442 // Close connection settings if open
443 if (UI
.settingsOpen
=== true) {
445 UI
.closeSettingsMenu();
446 $D('connectButton').className
= "noVNC_status_button";
448 // Close clipboard panel if open
449 if (UI
.clipboardOpen
=== true) {
450 UI
.toggleClipboardPanel();
452 // Close popup status panel if open
453 if (UI
.popupStatusOpen
=== true) {
454 UI
.togglePopupStatusPanel();
456 // Close XVP panel if open
457 if (UI
.xvpOpen
=== true) {
461 // Toggle Connection Panel
462 if (UI
.connSettingsOpen
=== true) {
463 $D('noVNC_controls').style
.display
= "none";
464 $D('connectButton').className
= "noVNC_status_button";
465 UI
.connSettingsOpen
= false;
466 UI
.saveSetting('host');
467 UI
.saveSetting('port');
468 //UI.saveSetting('password');
470 $D('noVNC_controls').style
.display
= "block";
471 $D('connectButton').className
= "noVNC_status_button_selected";
472 UI
.connSettingsOpen
= true;
473 $D('noVNC_host').focus();
477 // Toggle the settings menu:
478 // On open, settings are refreshed from saved cookies.
479 // On close, settings are applied
480 toggleSettingsPanel: function() {
481 // Close the description panel
482 $D('noVNC_description').style
.display
= "none";
483 if (UI
.settingsOpen
) {
485 UI
.closeSettingsMenu();
487 UI
.updateSetting('encrypt');
488 UI
.updateSetting('true_color');
489 if (Util
.browserSupportsCursorURIs()) {
490 UI
.updateSetting('cursor');
492 UI
.updateSetting('cursor', !UI
.isTouchDevice
);
493 $D('noVNC_cursor').disabled
= true;
495 UI
.updateSetting('clip');
496 UI
.updateSetting('resize');
497 UI
.updateSetting('shared');
498 UI
.updateSetting('view_only');
499 UI
.updateSetting('path');
500 UI
.updateSetting('repeaterID');
501 UI
.updateSetting('stylesheet');
502 UI
.updateSetting('logging');
504 UI
.openSettingsMenu();
509 openSettingsMenu: function() {
510 // Close the description panel
511 $D('noVNC_description').style
.display
= "none";
512 // Close clipboard panel if open
513 if (UI
.clipboardOpen
=== true) {
514 UI
.toggleClipboardPanel();
516 // Close connection settings if open
517 if (UI
.connSettingsOpen
=== true) {
518 UI
.toggleConnectPanel();
520 // Close popup status panel if open
521 if (UI
.popupStatusOpen
=== true) {
522 UI
.togglePopupStatusPanel();
524 // Close XVP panel if open
525 if (UI
.xvpOpen
=== true) {
528 $D('noVNC_settings').style
.display
= "block";
529 $D('settingsButton').className
= "noVNC_status_button_selected";
530 UI
.settingsOpen
= true;
533 // Close menu (without applying settings)
534 closeSettingsMenu: function() {
535 $D('noVNC_settings').style
.display
= "none";
536 $D('settingsButton').className
= "noVNC_status_button";
537 UI
.settingsOpen
= false;
540 // Save/apply settings when 'Apply' button is pressed
541 settingsApply: function() {
542 //Util.Debug(">> settingsApply");
543 UI
.saveSetting('encrypt');
544 UI
.saveSetting('true_color');
545 if (Util
.browserSupportsCursorURIs()) {
546 UI
.saveSetting('cursor');
549 UI
.saveSetting('resize');
551 if (UI
.getSetting('resize') === 'downscale' || UI
.getSetting('resize') === 'scale') {
552 UI
.forceSetting('clip', false);
555 UI
.saveSetting('clip');
556 UI
.saveSetting('shared');
557 UI
.saveSetting('view_only');
558 UI
.saveSetting('path');
559 UI
.saveSetting('repeaterID');
560 UI
.saveSetting('stylesheet');
561 UI
.saveSetting('logging');
563 // Settings with immediate (non-connected related) effect
564 WebUtil
.selectStylesheet(UI
.getSetting('stylesheet'));
565 WebUtil
.init_logging(UI
.getSetting('logging'));
567 UI
.setViewDrag(UI
.rfb
&& UI
.rfb
.get_viewportDrag());
568 //Util.Debug("<< settingsApply");
573 setPassword: function() {
574 UI
.rfb
.sendPassword($D('noVNC_password').value
);
575 //Reset connect button.
576 $D('noVNC_connect_button').value
= "Connect";
577 $D('noVNC_connect_button').onclick
= UI
.Connect
;
578 //Hide connection panel.
579 UI
.toggleConnectPanel();
583 sendCtrlAltDel: function() {
584 UI
.rfb
.sendCtrlAltDel();
587 xvpShutdown: function() {
588 UI
.rfb
.xvpShutdown();
591 xvpReboot: function() {
595 xvpReset: function() {
599 setMouseButton: function(num
) {
600 if (typeof num
=== 'undefined') {
601 // Disable mouse buttons
605 UI
.rfb
.get_mouse().set_touchButton(num
);
608 var blist
= [0, 1,2,4];
609 for (var b
= 0; b
< blist
.length
; b
++) {
610 var button
= $D('noVNC_mouse_button' + blist
[b
]);
611 if (blist
[b
] === num
) {
612 button
.style
.display
= "";
614 button
.style
.display
= "none";
619 updateState: function(rfb
, state
, oldstate
, msg
) {
620 UI
.rfb_state
= state
;
625 klass
= "noVNC_status_error";
628 klass
= "noVNC_status_normal";
631 $D('noVNC_logo').style
.display
= "block";
632 $D('noVNC_container').style
.display
= "none";
635 klass
= "noVNC_status_normal";
638 UI
.toggleConnectPanel();
640 $D('noVNC_connect_button').value
= "Send Password";
641 $D('noVNC_connect_button').onclick
= UI
.setPassword
;
642 $D('noVNC_password').focus();
644 klass
= "noVNC_status_warn";
647 klass
= "noVNC_status_warn";
651 if (typeof(msg
) !== 'undefined') {
652 $D('noVNC-control-bar').setAttribute("class", klass
);
653 $D('noVNC_status').innerHTML
= msg
;
656 UI
.updateVisualState();
659 // Disable/enable controls depending on connection state
660 updateVisualState: function() {
661 var connected
= UI
.rfb
&& UI
.rfb_state
=== 'normal';
663 //Util.Debug(">> updateVisualState");
664 $D('noVNC_encrypt').disabled
= connected
;
665 $D('noVNC_true_color').disabled
= connected
;
666 if (Util
.browserSupportsCursorURIs()) {
667 $D('noVNC_cursor').disabled
= connected
;
669 UI
.updateSetting('cursor', !UI
.isTouchDevice
);
670 $D('noVNC_cursor').disabled
= true;
673 UI
.enableDisableClip(connected
);
674 $D('noVNC_resize').disabled
= connected
;
675 $D('noVNC_shared').disabled
= connected
;
676 $D('noVNC_view_only').disabled
= connected
;
677 $D('noVNC_path').disabled
= connected
;
678 $D('noVNC_repeaterID').disabled
= connected
;
682 UI
.setMouseButton(1);
683 $D('clipboardButton').style
.display
= "inline";
684 $D('showKeyboard').style
.display
= "inline";
685 $D('noVNC_extra_keys').style
.display
= "";
686 $D('sendCtrlAltDelButton').style
.display
= "inline";
689 $D('clipboardButton').style
.display
= "none";
690 $D('showKeyboard').style
.display
= "none";
691 $D('noVNC_extra_keys').style
.display
= "none";
692 $D('sendCtrlAltDelButton').style
.display
= "none";
693 UI
.updateXvpVisualState(0);
696 // State change disables viewport dragging.
697 // It is enabled (toggled) by direct click on the button
698 UI
.setViewDrag(false);
700 switch (UI
.rfb_state
) {
704 $D('connectButton').style
.display
= "";
705 $D('disconnectButton').style
.display
= "none";
706 UI
.connSettingsOpen
= false;
707 UI
.toggleConnectPanel();
710 $D('connectButton').style
.display
= "";
711 $D('disconnectButton').style
.display
= "none";
714 $D('connectButton').style
.display
= "none";
715 $D('disconnectButton').style
.display
= "";
719 //Util.Debug("<< updateVisualState");
722 // Disable/enable XVP button
723 updateXvpVisualState: function(ver
) {
725 $D('xvpButton').style
.display
= 'inline';
727 $D('xvpButton').style
.display
= 'none';
728 // Close XVP panel if open
729 if (UI
.xvpOpen
=== true) {
735 enableDisableClip: function (connected
) {
736 var resizeElem
= $D('noVNC_resize');
737 if (resizeElem
.value
=== 'downscale' || resizeElem
.value
=== 'scale') {
738 UI
.forceSetting('clip', false);
739 $D('noVNC_clip').disabled
= true;
741 $D('noVNC_clip').disabled
= connected
|| UI
.isTouchDevice
;
742 if (UI
.isTouchDevice
) {
743 UI
.forceSetting('clip', true);
748 // This resize can not be done until we know from the first Frame Buffer Update
749 // if it is supported or not.
750 // The resize is needed to make sure the server desktop size is updated to the
751 // corresponding size of the current local window when reconnecting to an
753 FBUComplete: function(rfb
, fbu
) {
755 UI
.rfb
.set_onFBUComplete(function() { });
758 // Display the desktop name in the document title
759 updateDocumentTitle: function(rfb
, name
) {
760 document
.title
= name
+ " - noVNC";
763 clipReceive: function(rfb
, text
) {
764 Util
.Debug(">> UI.clipReceive: " + text
.substr(0,40) + "...");
765 $D('noVNC_clipboard_text').value
= text
;
766 Util
.Debug("<< UI.clipReceive");
769 connect: function() {
770 UI
.closeSettingsMenu();
771 UI
.toggleConnectPanel();
773 var host
= $D('noVNC_host').value
;
774 var port
= $D('noVNC_port').value
;
775 var password
= $D('noVNC_password').value
;
776 var path
= $D('noVNC_path').value
;
777 if ((!host
) || (!port
)) {
778 throw new Error("Must set host and port");
781 if (!UI
.initRFB()) return;
783 UI
.rfb
.set_encrypt(UI
.getSetting('encrypt'));
784 UI
.rfb
.set_true_color(UI
.getSetting('true_color'));
785 UI
.rfb
.set_local_cursor(UI
.getSetting('cursor'));
786 UI
.rfb
.set_shared(UI
.getSetting('shared'));
787 UI
.rfb
.set_view_only(UI
.getSetting('view_only'));
788 UI
.rfb
.set_repeaterID(UI
.getSetting('repeaterID'));
790 UI
.rfb
.connect(host
, port
, password
, path
);
793 setTimeout(UI
.setBarPosition
, 100);
794 $D('noVNC_logo').style
.display
= "none";
795 $D('noVNC_container').style
.display
= "inline";
798 disconnect: function() {
799 UI
.closeSettingsMenu();
802 // Restore the callback used for initial resize
803 UI
.rfb
.set_onFBUComplete(UI
.FBUComplete
);
805 $D('noVNC_logo').style
.display
= "block";
806 $D('noVNC_container').style
.display
= "none";
808 // Don't display the connection settings until we're actually disconnected
811 displayBlur: function() {
814 UI
.rfb
.get_keyboard().set_focused(false);
815 UI
.rfb
.get_mouse().set_focused(false);
818 displayFocus: function() {
821 UI
.rfb
.get_keyboard().set_focused(true);
822 UI
.rfb
.get_mouse().set_focused(true);
825 clipClear: function() {
826 $D('noVNC_clipboard_text').value
= "";
827 UI
.rfb
.clipboardPasteFrom("");
830 clipSend: function() {
831 var text
= $D('noVNC_clipboard_text').value
;
832 Util
.Debug(">> UI.clipSend: " + text
.substr(0,40) + "...");
833 UI
.rfb
.clipboardPasteFrom(text
);
834 Util
.Debug("<< UI.clipSend");
837 // Enable/disable and configure viewport clipping
838 setViewClip: function(clip
) {
841 display
= UI
.rfb
.get_display();
846 var cur_clip
= display
.get_viewport();
848 if (typeof(clip
) !== 'boolean') {
849 // Use current setting
850 clip
= UI
.getSetting('clip');
853 if (clip
&& !cur_clip
) {
855 UI
.updateSetting('clip', true);
856 } else if (!clip
&& cur_clip
) {
858 UI
.updateSetting('clip', false);
859 display
.set_viewport(false);
860 display
.set_maxWidth(0);
861 display
.set_maxHeight(0);
862 display
.viewportChangeSize();
864 if (UI
.getSetting('clip')) {
865 // If clipping, update clipping settings
866 display
.set_viewport(true);
868 var size
= UI
.getCanvasLimit();
870 display
.set_maxWidth(size
.w
);
871 display
.set_maxHeight(size
.h
);
873 // Hide potential scrollbars that can skew the position
874 $D('noVNC_container').style
.overflow
= "hidden";
876 // The x position marks the left margin of the canvas,
877 // remove the margin from both sides to keep it centered
878 var new_w
= size
.w
- (2 * Util
.getPosition($D('noVNC_canvas')).x
);
880 $D('noVNC_container').style
.overflow
= "visible";
882 display
.viewportChangeSize(new_w
, size
.h
);
887 // Toggle/set/unset the viewport drag/move button
888 setViewDrag: function(drag
) {
891 UI
.updateViewDragButton();
893 if (typeof(drag
) === "undefined" ||
894 typeof(drag
) === "object") {
895 // If not specified, then toggle
896 drag
= !UI
.rfb
.get_viewportDrag();
898 var vmb
= $D('noVNC_view_drag_button');
900 vmb
.className
= "noVNC_status_button_selected";
901 UI
.rfb
.set_viewportDrag(true);
903 vmb
.className
= "noVNC_status_button";
904 UI
.rfb
.set_viewportDrag(false);
908 updateViewDragButton: function() {
909 var vmb
= $D('noVNC_view_drag_button');
910 if (UI
.rfb_state
=== 'normal' &&
911 UI
.rfb
.get_display().get_viewport() &&
912 UI
.rfb
.get_display().clippingDisplay()) {
913 vmb
.style
.display
= "inline";
915 vmb
.style
.display
= "none";
919 // On touch devices, show the OS keyboard
920 showKeyboard: function() {
921 var kbi
= $D('keyboardinput');
922 var skb
= $D('showKeyboard');
923 var l
= kbi
.value
.length
;
924 if(UI
.keyboardVisible
=== false) {
926 try { kbi
.setSelectionRange(l
, l
); } // Move the caret to the end
927 catch (err
) {} // setSelectionRange is undefined in Google Chrome
928 UI
.keyboardVisible
= true;
929 skb
.className
= "noVNC_status_button_selected";
930 } else if(UI
.keyboardVisible
=== true) {
932 skb
.className
= "noVNC_status_button";
933 UI
.keyboardVisible
= false;
937 keepKeyboard: function() {
938 clearTimeout(UI
.hideKeyboardTimeout
);
939 if(UI
.keyboardVisible
=== true) {
940 $D('keyboardinput').focus();
941 $D('showKeyboard').className
= "noVNC_status_button_selected";
942 } else if(UI
.keyboardVisible
=== false) {
943 $D('keyboardinput').blur();
944 $D('showKeyboard').className
= "noVNC_status_button";
948 keyboardinputReset: function() {
949 var kbi
= $D('keyboardinput');
950 kbi
.value
= new Array(UI
.defaultKeyboardinputLen
).join("_");
951 UI
.lastKeyboardinput
= kbi
.value
;
954 // When normal keyboard events are left uncought, use the input events from
955 // the keyboardinput element instead and generate the corresponding key events.
956 // This code is required since some browsers on Android are inconsistent in
957 // sending keyCodes in the normal keyboard events when using on screen keyboards.
958 keyInput: function(event
) {
962 var newValue
= event
.target
.value
;
964 if (!UI
.lastKeyboardinput
) {
965 UI
.keyboardinputReset();
967 var oldvalue
= UI
.lastKeyboardinput
;
971 // Try to check caret position since whitespace at the end
972 // will not be considered by value.length in some browsers
973 newLen
= Math
.max(event
.target
.selectionStart
, newValue
.length
);
975 // selectionStart is undefined in Google Chrome
976 newLen
= newValue
.length
;
978 var oldLen
= oldValue
.length
;
981 var inputs
= newLen
- oldLen
;
983 backspaces
= -inputs
;
988 // Compare the old string with the new to account for
989 // text-corrections or other input that modify existing text
991 for (i
= 0; i
< Math
.min(oldLen
, newLen
); i
++) {
992 if (newValue
.charAt(i
) != oldValue
.charAt(i
)) {
994 backspaces
= oldLen
- i
;
999 // Send the key events
1000 for (i
= 0; i
< backspaces
; i
++) {
1001 UI
.rfb
.sendKey(XK_BackSpace
);
1003 for (i
= newLen
- inputs
; i
< newLen
; i
++) {
1004 UI
.rfb
.sendKey(newValue
.charCodeAt(i
));
1007 // Control the text content length in the keyboardinput element
1008 if (newLen
> 2 * UI
.defaultKeyboardinputLen
) {
1009 UI
.keyboardinputReset();
1010 } else if (newLen
< 1) {
1011 // There always have to be some text in the keyboardinput
1012 // element with which backspace can interact.
1013 UI
.keyboardinputReset();
1014 // This sometimes causes the keyboard to disappear for a second
1015 // but it is required for the android keyboard to recognize that
1016 // text has been added to the field
1017 event
.target
.blur();
1018 // This has to be ran outside of the input handler in order to work
1019 setTimeout(function() { UI
.keepKeyboard(); }, 0);
1021 UI
.lastKeyboardinput
= newValue
;
1025 keyInputBlur: function() {
1026 $D('showKeyboard').className
= "noVNC_status_button";
1027 //Weird bug in iOS if you change keyboardVisible
1028 //here it does not actually occur so next time
1029 //you click keyboard icon it doesnt work.
1030 UI
.hideKeyboardTimeout
= setTimeout(function() { UI
.setKeyboard(); },100);
1033 showExtraKeys: function() {
1035 if(UI
.extraKeysVisible
=== false) {
1036 $D('toggleCtrlButton').style
.display
= "inline";
1037 $D('toggleAltButton').style
.display
= "inline";
1038 $D('sendTabButton').style
.display
= "inline";
1039 $D('sendEscButton').style
.display
= "inline";
1040 $D('showExtraKeysButton').className
= "noVNC_status_button_selected";
1041 UI
.extraKeysVisible
= true;
1042 } else if(UI
.extraKeysVisible
=== true) {
1043 $D('toggleCtrlButton').style
.display
= "";
1044 $D('toggleAltButton').style
.display
= "";
1045 $D('sendTabButton').style
.display
= "";
1046 $D('sendEscButton').style
.display
= "";
1047 $D('showExtraKeysButton').className
= "noVNC_status_button";
1048 UI
.extraKeysVisible
= false;
1052 toggleCtrl: function() {
1054 if(UI
.ctrlOn
=== false) {
1055 UI
.rfb
.sendKey(XK_Control_L
, true);
1056 $D('toggleCtrlButton').className
= "noVNC_status_button_selected";
1058 } else if(UI
.ctrlOn
=== true) {
1059 UI
.rfb
.sendKey(XK_Control_L
, false);
1060 $D('toggleCtrlButton').className
= "noVNC_status_button";
1065 toggleAlt: function() {
1067 if(UI
.altOn
=== false) {
1068 UI
.rfb
.sendKey(XK_Alt_L
, true);
1069 $D('toggleAltButton').className
= "noVNC_status_button_selected";
1071 } else if(UI
.altOn
=== true) {
1072 UI
.rfb
.sendKey(XK_Alt_L
, false);
1073 $D('toggleAltButton').className
= "noVNC_status_button";
1078 sendTab: function() {
1080 UI
.rfb
.sendKey(XK_Tab
);
1083 sendEsc: function() {
1085 UI
.rfb
.sendKey(XK_Escape
);
1088 setKeyboard: function() {
1089 UI
.keyboardVisible
= false;
1092 //Helper to add options to dropdown.
1093 addOption: function(selectbox
, text
, value
) {
1094 var optn
= document
.createElement("OPTION");
1097 selectbox
.options
.add(optn
);
1100 setBarPosition: function() {
1101 $D('noVNC-control-bar').style
.top
= (window
.pageYOffset
) + 'px';
1102 $D('noVNC_mobile_buttons').style
.left
= (window
.pageXOffset
) + 'px';
1104 var vncwidth
= $D('noVNC_screen').style
.offsetWidth
;
1105 $D('noVNC-control-bar').style
.width
= vncwidth
+ 'px';