ui.js 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2012 Joel Martin
  4. * Copyright (C) 2016 Samuel Mannehed for Cendio AB
  5. * Licensed under MPL 2.0 (see LICENSE.txt)
  6. *
  7. * See README.md for usage and integration instructions.
  8. */
  9. /* jslint white: false, browser: true */
  10. /* global window, $D, Util, WebUtil, RFB, Display */
  11. var UI;
  12. (function () {
  13. "use strict";
  14. // Load supporting scripts
  15. window.onscriptsload = function () { UI.load(); };
  16. Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
  17. "keysymdef.js", "keyboard.js", "input.js", "display.js",
  18. "rfb.js", "keysym.js", "inflator.js"]);
  19. UI = {
  20. rfb_state: 'loaded',
  21. resizeTimeout: null,
  22. popupStatusTimeout: null,
  23. hideKeyboardTimeout: null,
  24. settingsOpen: false,
  25. connSettingsOpen: false,
  26. clipboardOpen: false,
  27. keyboardVisible: false,
  28. isTouchDevice: false,
  29. isSafari: false,
  30. rememberedClipSetting: null,
  31. lastKeyboardinput: null,
  32. defaultKeyboardinputLen: 100,
  33. shiftDown: false,
  34. ctrlDown: false,
  35. altDown: false,
  36. altGrDown: false,
  37. // Setup rfb object, load settings from browser storage, then call
  38. // UI.init to setup the UI/menus
  39. load: function(callback) {
  40. WebUtil.initSettings(UI.start, callback);
  41. },
  42. // Render default UI and initialize settings menu
  43. start: function(callback) {
  44. UI.isTouchDevice = 'ontouchstart' in document.documentElement;
  45. // Stylesheet selection dropdown
  46. var sheet = WebUtil.selectStylesheet();
  47. var sheets = WebUtil.getStylesheets();
  48. var i;
  49. for (i = 0; i < sheets.length; i += 1) {
  50. UI.addOption($D('noVNC_setting_stylesheet'),sheets[i].title, sheets[i].title);
  51. }
  52. // Logging selection dropdown
  53. var llevels = ['error', 'warn', 'info', 'debug'];
  54. for (i = 0; i < llevels.length; i += 1) {
  55. UI.addOption($D('noVNC_setting_logging'),llevels[i], llevels[i]);
  56. }
  57. // Settings with immediate effects
  58. UI.initSetting('logging', 'warn');
  59. WebUtil.init_logging(UI.getSetting('logging'));
  60. UI.initSetting('stylesheet', 'default');
  61. WebUtil.selectStylesheet(null);
  62. // call twice to get around webkit bug
  63. WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
  64. // if port == 80 (or 443) then it won't be present and should be
  65. // set manually
  66. var port = window.location.port;
  67. if (!port) {
  68. if (window.location.protocol.substring(0,5) == 'https') {
  69. port = 443;
  70. }
  71. else if (window.location.protocol.substring(0,4) == 'http') {
  72. port = 80;
  73. }
  74. }
  75. /* Populate the controls if defaults are provided in the URL */
  76. UI.initSetting('host', window.location.hostname);
  77. UI.initSetting('port', port);
  78. UI.initSetting('password', '');
  79. UI.initSetting('encrypt', (window.location.protocol === "https:"));
  80. UI.initSetting('true_color', true);
  81. UI.initSetting('cursor', !UI.isTouchDevice);
  82. UI.initSetting('resize', 'off');
  83. UI.initSetting('shared', true);
  84. UI.initSetting('view_only', false);
  85. UI.initSetting('path', 'websockify');
  86. UI.initSetting('repeaterID', '');
  87. UI.initSetting('token', '');
  88. var autoconnect = WebUtil.getConfigVar('autoconnect', false);
  89. if (autoconnect === 'true' || autoconnect == '1') {
  90. autoconnect = true;
  91. UI.connect();
  92. } else {
  93. autoconnect = false;
  94. }
  95. UI.updateVisualState();
  96. $D('noVNC_setting_host').focus();
  97. // Show mouse selector buttons on touch screen devices
  98. if (UI.isTouchDevice) {
  99. // Show mobile buttons
  100. $D('noVNC_mobile_buttons').style.display = "inline";
  101. UI.setMouseButton();
  102. // Remove the address bar
  103. setTimeout(function() { window.scrollTo(0, 1); }, 100);
  104. UI.forceSetting('clip', true);
  105. } else {
  106. UI.initSetting('clip', false);
  107. }
  108. UI.setViewClip();
  109. UI.setBarPosition();
  110. Util.addEvent(window, 'resize', function () {
  111. UI.applyResizeMode();
  112. UI.setViewClip();
  113. UI.updateViewDrag();
  114. UI.setBarPosition();
  115. } );
  116. UI.isSafari = (navigator.userAgent.indexOf('Safari') != -1 &&
  117. navigator.userAgent.indexOf('Chrome') == -1);
  118. // Only show the button if fullscreen is properly supported
  119. // * Safari doesn't support alphanumerical input while in fullscreen
  120. if (!UI.isSafari &&
  121. (document.documentElement.requestFullscreen ||
  122. document.documentElement.mozRequestFullScreen ||
  123. document.documentElement.webkitRequestFullscreen ||
  124. document.body.msRequestFullscreen)) {
  125. $D('noVNC_fullscreen_button').style.display = "inline";
  126. Util.addEvent(window, 'fullscreenchange', UI.updateFullscreenButton);
  127. Util.addEvent(window, 'mozfullscreenchange', UI.updateFullscreenButton);
  128. Util.addEvent(window, 'webkitfullscreenchange', UI.updateFullscreenButton);
  129. Util.addEvent(window, 'msfullscreenchange', UI.updateFullscreenButton);
  130. }
  131. Util.addEvent(window, 'load', UI.keyboardinputReset);
  132. Util.addEvent(window, 'beforeunload', function () {
  133. if (UI.rfb && UI.rfb_state === 'normal') {
  134. return "You are currently connected.";
  135. }
  136. } );
  137. // Show description by default when hosted at for kanaka.github.com
  138. if (location.host === "kanaka.github.io") {
  139. // Open the description dialog
  140. $D('noVNC_description').style.display = "block";
  141. } else {
  142. // Show the connect panel on first load unless autoconnecting
  143. if (autoconnect === UI.connSettingsOpen) {
  144. UI.toggleConnectPanel();
  145. }
  146. }
  147. // Add mouse event click/focus/blur event handlers to the UI
  148. UI.addMouseHandlers();
  149. if (typeof callback === "function") {
  150. callback(UI.rfb);
  151. }
  152. },
  153. initRFB: function() {
  154. try {
  155. UI.rfb = new RFB({'target': $D('noVNC_canvas'),
  156. 'onUpdateState': UI.updateState,
  157. 'onXvpInit': UI.updateXvpButton,
  158. 'onClipboard': UI.clipboardReceive,
  159. 'onFBUComplete': UI.initialResize,
  160. 'onFBResize': UI.updateViewDrag,
  161. 'onDesktopName': UI.updateDocumentTitle});
  162. return true;
  163. } catch (exc) {
  164. UI.updateState(null, 'fatal', null, 'Unable to create RFB client -- ' + exc);
  165. return false;
  166. }
  167. },
  168. addMouseHandlers: function() {
  169. // Setup interface handlers that can't be inline
  170. $D("noVNC_view_drag_button").onclick = UI.toggleViewDrag;
  171. $D("noVNC_mouse_button0").onclick = function () { UI.setMouseButton(1); };
  172. $D("noVNC_mouse_button1").onclick = function () { UI.setMouseButton(2); };
  173. $D("noVNC_mouse_button2").onclick = function () { UI.setMouseButton(4); };
  174. $D("noVNC_mouse_button4").onclick = function () { UI.setMouseButton(0); };
  175. $D("noVNC_keyboard_button").onclick = UI.showKeyboard;
  176. $D("noVNC_keyboardinput").oninput = UI.keyInput;
  177. $D("noVNC_keyboardinput").onblur = UI.hideKeyboard;
  178. $D("noVNC_keyboardinput").onsubmit = function () { return false; };
  179. $D("noVNC_toggleExtraKeys_button").onclick = UI.toggleExtraKeys;
  180. $D("noVNC_toggleCtrl_button").onclick = UI.toggleCtrl;
  181. $D("noVNC_toggleAlt_button").onclick = UI.toggleAlt;
  182. $D("noVNC_sendTab_button").onclick = UI.sendTab;
  183. $D("noVNC_sendEsc_button").onclick = UI.sendEsc;
  184. $D("noVNC_sendCtrlAltDel_button").onclick = UI.sendCtrlAltDel;
  185. $D("noVNC_xvpShutdown_button").onclick = function() { UI.rfb.xvpShutdown(); },
  186. $D("noVNC_xvpReboot_button").onclick = function() { UI.rfb.xvpReboot(); },
  187. $D("noVNC_xvpReset_button").onclick = function() { UI.rfb.xvpReset(); },
  188. $D("noVNC_status").onclick = UI.popupStatus;
  189. $D("noVNC_popup_status").onclick = UI.closePopup;
  190. $D("noVNC_toggleXvp_button").onclick = UI.toggleXvpPanel;
  191. $D("noVNC_clipboard_button").onclick = UI.toggleClipboardPanel;
  192. $D("noVNC_fullscreen_button").onclick = UI.toggleFullscreen;
  193. $D("noVNC_settings_button").onclick = UI.toggleSettingsPanel;
  194. $D("noVNC_connectPanel_button").onclick = UI.toggleConnectPanel;
  195. $D("noVNC_disconnect_button").onclick = UI.disconnect;
  196. $D("noVNC_description_button").onclick = UI.toggleConnectPanel;
  197. $D("noVNC_clipboard_text").onfocus = UI.displayBlur;
  198. $D("noVNC_clipboard_text").onblur = UI.displayFocus;
  199. $D("noVNC_clipboard_text").onchange = UI.clipboardSend;
  200. $D("noVNC_clipboard_clear_button").onclick = UI.clipboardClear;
  201. $D("noVNC_settings_menu").onmouseover = UI.displayBlur;
  202. $D("noVNC_settings_menu").onmouseover = UI.displayFocus;
  203. $D("noVNC_settings_apply").onclick = UI.settingsApply;
  204. $D("noVNC_connect_button").onclick = UI.connect;
  205. $D("noVNC_setting_resize").onchange = UI.enableDisableViewClip;
  206. },
  207. /* ------^-------
  208. * /INIT
  209. * ==============
  210. * VISUAL
  211. * ------v------*/
  212. updateState: function(rfb, state, oldstate, msg) {
  213. UI.rfb_state = state;
  214. var klass;
  215. switch (state) {
  216. case 'failed':
  217. case 'fatal':
  218. klass = "noVNC_status_error";
  219. break;
  220. case 'normal':
  221. klass = "noVNC_status_normal";
  222. break;
  223. case 'disconnected':
  224. $D('noVNC_logo').style.display = "block";
  225. $D('noVNC_screen').style.display = "none";
  226. /* falls through */
  227. case 'loaded':
  228. klass = "noVNC_status_normal";
  229. break;
  230. case 'password':
  231. UI.toggleConnectPanel();
  232. $D('noVNC_connect_button').value = "Send Password";
  233. $D('noVNC_connect_button').onclick = UI.setPassword;
  234. $D('noVNC_setting_password').focus();
  235. klass = "noVNC_status_warn";
  236. break;
  237. default:
  238. klass = "noVNC_status_warn";
  239. break;
  240. }
  241. if (typeof(msg) !== 'undefined') {
  242. $D('noVNC_control_bar').setAttribute("class", klass);
  243. $D('noVNC_status').textContent = msg;
  244. }
  245. UI.updateVisualState();
  246. },
  247. // Disable/enable controls depending on connection state
  248. updateVisualState: function() {
  249. var connected = UI.rfb && UI.rfb_state === 'normal';
  250. //Util.Debug(">> updateVisualState");
  251. $D('noVNC_setting_encrypt').disabled = connected;
  252. $D('noVNC_setting_true_color').disabled = connected;
  253. if (Util.browserSupportsCursorURIs()) {
  254. $D('noVNC_setting_cursor').disabled = connected;
  255. } else {
  256. UI.updateSetting('cursor', !UI.isTouchDevice);
  257. $D('noVNC_setting_cursor').disabled = true;
  258. }
  259. UI.enableDisableViewClip();
  260. $D('noVNC_setting_resize').disabled = connected;
  261. $D('noVNC_setting_shared').disabled = connected;
  262. $D('noVNC_setting_view_only').disabled = connected;
  263. $D('noVNC_setting_path').disabled = connected;
  264. $D('noVNC_setting_repeaterID').disabled = connected;
  265. if (connected) {
  266. UI.setViewClip();
  267. UI.setMouseButton(1);
  268. $D('noVNC_clipboard_button').style.display = "inline";
  269. $D('noVNC_keyboard_button').style.display = "inline";
  270. $D('noVNC_extra_keys').style.display = "";
  271. $D('noVNC_sendCtrlAltDel_button').style.display = "inline";
  272. } else {
  273. UI.setMouseButton();
  274. $D('noVNC_clipboard_button').style.display = "none";
  275. $D('noVNC_keyboard_button').style.display = "none";
  276. $D('noVNC_extra_keys').style.display = "none";
  277. $D('noVNC_sendCtrlAltDel_button').style.display = "none";
  278. UI.updateXvpButton(0);
  279. }
  280. // State change disables viewport dragging.
  281. // It is enabled (toggled) by direct click on the button
  282. UI.updateViewDrag(false);
  283. switch (UI.rfb_state) {
  284. case 'fatal':
  285. case 'failed':
  286. case 'disconnected':
  287. $D('noVNC_connectPanel_button').style.display = "";
  288. $D('noVNC_disconnect_button').style.display = "none";
  289. UI.connSettingsOpen = false;
  290. UI.toggleConnectPanel();
  291. break;
  292. case 'loaded':
  293. $D('noVNC_connectPanel_button').style.display = "";
  294. $D('noVNC_disconnect_button').style.display = "none";
  295. break;
  296. default:
  297. $D('noVNC_connectPanel_button').style.display = "none";
  298. $D('noVNC_disconnect_button').style.display = "";
  299. break;
  300. }
  301. //Util.Debug("<< updateVisualState");
  302. },
  303. popupStatus: function(text) {
  304. var psp = $D('noVNC_popup_status');
  305. clearTimeout(UI.popupStatusTimeout);
  306. if (typeof text === 'string') {
  307. psp.textContent = text;
  308. } else {
  309. psp.textContent = $D('noVNC_status').textContent;
  310. }
  311. psp.style.display = "block";
  312. psp.style.left = window.innerWidth/2 -
  313. parseInt(window.getComputedStyle(psp).width)/2 -30 + "px";
  314. // Show the popup for a maximum of 1.5 seconds
  315. UI.popupStatusTimeout = setTimeout(UI.closePopup, 1500);
  316. },
  317. closePopup: function() {
  318. clearTimeout(UI.popupStatusTimeout);
  319. $D('noVNC_popup_status').style.display = "none";
  320. },
  321. /* ------^-------
  322. * /VISUAL
  323. * ==============
  324. * SETTINGS
  325. * ------v------*/
  326. // Initial page load read/initialization of settings
  327. initSetting: function(name, defVal) {
  328. // Check Query string followed by cookie
  329. var val = WebUtil.getConfigVar(name);
  330. if (val === null) {
  331. val = WebUtil.readSetting(name, defVal);
  332. }
  333. UI.updateSetting(name, val);
  334. return val;
  335. },
  336. // Update cookie and form control setting. If value is not set, then
  337. // updates from control to current cookie setting.
  338. updateSetting: function(name, value) {
  339. // Save the cookie for this session
  340. if (typeof value !== 'undefined') {
  341. WebUtil.writeSetting(name, value);
  342. }
  343. // Update the settings control
  344. value = UI.getSetting(name);
  345. var ctrl = $D('noVNC_setting_' + name);
  346. if (ctrl.type === 'checkbox') {
  347. ctrl.checked = value;
  348. } else if (typeof ctrl.options !== 'undefined') {
  349. for (var i = 0; i < ctrl.options.length; i += 1) {
  350. if (ctrl.options[i].value === value) {
  351. ctrl.selectedIndex = i;
  352. break;
  353. }
  354. }
  355. } else {
  356. /*Weird IE9 error leads to 'null' appearring
  357. in textboxes instead of ''.*/
  358. if (value === null) {
  359. value = "";
  360. }
  361. ctrl.value = value;
  362. }
  363. },
  364. // Save control setting to cookie
  365. saveSetting: function(name) {
  366. var val, ctrl = $D('noVNC_setting_' + name);
  367. if (ctrl.type === 'checkbox') {
  368. val = ctrl.checked;
  369. } else if (typeof ctrl.options !== 'undefined') {
  370. val = ctrl.options[ctrl.selectedIndex].value;
  371. } else {
  372. val = ctrl.value;
  373. }
  374. WebUtil.writeSetting(name, val);
  375. //Util.Debug("Setting saved '" + name + "=" + val + "'");
  376. return val;
  377. },
  378. // Force a setting to be a certain value
  379. forceSetting: function(name, val) {
  380. UI.updateSetting(name, val);
  381. return val;
  382. },
  383. // Read form control compatible setting from cookie
  384. getSetting: function(name) {
  385. var ctrl = $D('noVNC_setting_' + name);
  386. var val = WebUtil.readSetting(name);
  387. if (typeof val !== 'undefined' && val !== null && ctrl.type === 'checkbox') {
  388. if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
  389. val = false;
  390. } else {
  391. val = true;
  392. }
  393. }
  394. return val;
  395. },
  396. // Save/apply settings when 'Apply' button is pressed
  397. settingsApply: function() {
  398. //Util.Debug(">> settingsApply");
  399. UI.saveSetting('encrypt');
  400. UI.saveSetting('true_color');
  401. if (Util.browserSupportsCursorURIs()) {
  402. UI.saveSetting('cursor');
  403. }
  404. UI.saveSetting('resize');
  405. if (UI.getSetting('resize') === 'downscale' || UI.getSetting('resize') === 'scale') {
  406. UI.forceSetting('clip', false);
  407. }
  408. UI.saveSetting('clip');
  409. UI.saveSetting('shared');
  410. UI.saveSetting('view_only');
  411. UI.saveSetting('path');
  412. UI.saveSetting('repeaterID');
  413. UI.saveSetting('stylesheet');
  414. UI.saveSetting('logging');
  415. // Settings with immediate (non-connected related) effect
  416. WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
  417. WebUtil.init_logging(UI.getSetting('logging'));
  418. UI.setViewClip();
  419. UI.updateViewDrag();
  420. //Util.Debug("<< settingsApply");
  421. },
  422. // Open menu
  423. openSettingsMenu: function() {
  424. // Close the description panel
  425. $D('noVNC_description').style.display = "none";
  426. // Close clipboard panel if open
  427. if (UI.clipboardOpen === true) {
  428. UI.toggleClipboardPanel();
  429. }
  430. // Close connection settings if open
  431. if (UI.connSettingsOpen === true) {
  432. UI.toggleConnectPanel();
  433. }
  434. // Close XVP panel if open
  435. if (UI.xvpOpen === true) {
  436. UI.toggleXvpPanel();
  437. }
  438. $D('noVNC_settings').style.display = "block";
  439. $D('noVNC_settings_button').className = "noVNC_status_button_selected";
  440. UI.settingsOpen = true;
  441. },
  442. // Close menu (without applying settings)
  443. closeSettingsMenu: function() {
  444. $D('noVNC_settings').style.display = "none";
  445. $D('noVNC_settings_button').className = "noVNC_status_button";
  446. UI.settingsOpen = false;
  447. },
  448. // Toggle the settings menu:
  449. // On open, settings are refreshed from saved cookies.
  450. // On close, settings are applied
  451. toggleSettingsPanel: function() {
  452. // Close the description panel
  453. $D('noVNC_description').style.display = "none";
  454. if (UI.settingsOpen) {
  455. UI.settingsApply();
  456. UI.closeSettingsMenu();
  457. } else {
  458. UI.updateSetting('encrypt');
  459. UI.updateSetting('true_color');
  460. if (Util.browserSupportsCursorURIs()) {
  461. UI.updateSetting('cursor');
  462. } else {
  463. UI.updateSetting('cursor', !UI.isTouchDevice);
  464. $D('noVNC_setting_cursor').disabled = true;
  465. }
  466. UI.updateSetting('clip');
  467. UI.updateSetting('resize');
  468. UI.updateSetting('shared');
  469. UI.updateSetting('view_only');
  470. UI.updateSetting('path');
  471. UI.updateSetting('repeaterID');
  472. UI.updateSetting('stylesheet');
  473. UI.updateSetting('logging');
  474. UI.openSettingsMenu();
  475. }
  476. },
  477. /* ------^-------
  478. * /SETTINGS
  479. * ==============
  480. * XVP
  481. * ------v------*/
  482. // Show the XVP panel
  483. toggleXvpPanel: function() {
  484. // Close the description panel
  485. $D('noVNC_description').style.display = "none";
  486. // Close settings if open
  487. if (UI.settingsOpen === true) {
  488. UI.settingsApply();
  489. UI.closeSettingsMenu();
  490. }
  491. // Close connection settings if open
  492. if (UI.connSettingsOpen === true) {
  493. UI.toggleConnectPanel();
  494. }
  495. // Close clipboard panel if open
  496. if (UI.clipboardOpen === true) {
  497. UI.toggleClipboardPanel();
  498. }
  499. // Toggle XVP panel
  500. if (UI.xvpOpen === true) {
  501. $D('noVNC_xvp').style.display = "none";
  502. $D('noVNC_toggleXvp_button').className = "noVNC_status_button";
  503. UI.xvpOpen = false;
  504. } else {
  505. $D('noVNC_xvp').style.display = "block";
  506. $D('noVNC_toggleXvp_button').className = "noVNC_status_button_selected";
  507. UI.xvpOpen = true;
  508. }
  509. },
  510. // Disable/enable XVP button
  511. updateXvpButton: function(ver) {
  512. if (ver >= 1) {
  513. $D('noVNC_toggleXvp_button').style.display = 'inline';
  514. } else {
  515. $D('noVNC_toggleXvp_button').style.display = 'none';
  516. // Close XVP panel if open
  517. if (UI.xvpOpen === true) {
  518. UI.toggleXvpPanel();
  519. }
  520. }
  521. },
  522. /* ------^-------
  523. * /XVP
  524. * ==============
  525. * CLIPBOARD
  526. * ------v------*/
  527. // Show the clipboard panel
  528. toggleClipboardPanel: function() {
  529. // Close the description panel
  530. $D('noVNC_description').style.display = "none";
  531. // Close settings if open
  532. if (UI.settingsOpen === true) {
  533. UI.settingsApply();
  534. UI.closeSettingsMenu();
  535. }
  536. // Close connection settings if open
  537. if (UI.connSettingsOpen === true) {
  538. UI.toggleConnectPanel();
  539. }
  540. // Close XVP panel if open
  541. if (UI.xvpOpen === true) {
  542. UI.toggleXvpPanel();
  543. }
  544. // Toggle Clipboard Panel
  545. if (UI.clipboardOpen === true) {
  546. $D('noVNC_clipboard').style.display = "none";
  547. $D('noVNC_clipboard_button').className = "noVNC_status_button";
  548. UI.clipboardOpen = false;
  549. } else {
  550. $D('noVNC_clipboard').style.display = "block";
  551. $D('noVNC_clipboard_button').className = "noVNC_status_button_selected";
  552. UI.clipboardOpen = true;
  553. }
  554. },
  555. clipboardReceive: function(rfb, text) {
  556. Util.Debug(">> UI.clipboardReceive: " + text.substr(0,40) + "...");
  557. $D('noVNC_clipboard_text').value = text;
  558. Util.Debug("<< UI.clipboardReceive");
  559. },
  560. clipboardClear: function() {
  561. $D('noVNC_clipboard_text').value = "";
  562. UI.rfb.clipboardPasteFrom("");
  563. },
  564. clipboardSend: function() {
  565. var text = $D('noVNC_clipboard_text').value;
  566. Util.Debug(">> UI.clipboardSend: " + text.substr(0,40) + "...");
  567. UI.rfb.clipboardPasteFrom(text);
  568. Util.Debug("<< UI.clipboardSend");
  569. },
  570. /* ------^-------
  571. * /CLIPBOARD
  572. * ==============
  573. * CONNECTION
  574. * ------v------*/
  575. // Show the connection settings panel/menu
  576. toggleConnectPanel: function() {
  577. // Close the description panel
  578. $D('noVNC_description').style.display = "none";
  579. // Close connection settings if open
  580. if (UI.settingsOpen === true) {
  581. UI.settingsApply();
  582. UI.closeSettingsMenu();
  583. $D('noVNC_connectPanel_button').className = "noVNC_status_button";
  584. }
  585. // Close clipboard panel if open
  586. if (UI.clipboardOpen === true) {
  587. UI.toggleClipboardPanel();
  588. }
  589. // Close XVP panel if open
  590. if (UI.xvpOpen === true) {
  591. UI.toggleXvpPanel();
  592. }
  593. // Toggle Connection Panel
  594. if (UI.connSettingsOpen === true) {
  595. $D('noVNC_controls').style.display = "none";
  596. $D('noVNC_connectPanel_button').className = "noVNC_status_button";
  597. UI.connSettingsOpen = false;
  598. UI.saveSetting('host');
  599. UI.saveSetting('port');
  600. UI.saveSetting('token');
  601. //UI.saveSetting('password');
  602. } else {
  603. $D('noVNC_controls').style.display = "block";
  604. $D('noVNC_connectPanel_button').className = "noVNC_status_button_selected";
  605. UI.connSettingsOpen = true;
  606. $D('noVNC_setting_host').focus();
  607. }
  608. },
  609. connect: function() {
  610. UI.closeSettingsMenu();
  611. UI.toggleConnectPanel();
  612. var host = $D('noVNC_setting_host').value;
  613. var port = $D('noVNC_setting_port').value;
  614. var password = $D('noVNC_setting_password').value;
  615. var token = $D('noVNC_setting_token').value;
  616. var path = $D('noVNC_setting_path').value;
  617. //if token is in path then ignore the new token variable
  618. if (token) {
  619. path = WebUtil.injectParamIfMissing(path, "token", token);
  620. }
  621. if ((!host) || (!port)) {
  622. throw new Error("Must set host and port");
  623. }
  624. if (!UI.initRFB()) return;
  625. UI.rfb.set_encrypt(UI.getSetting('encrypt'));
  626. UI.rfb.set_true_color(UI.getSetting('true_color'));
  627. UI.rfb.set_local_cursor(UI.getSetting('cursor'));
  628. UI.rfb.set_shared(UI.getSetting('shared'));
  629. UI.rfb.set_view_only(UI.getSetting('view_only'));
  630. UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
  631. UI.rfb.connect(host, port, password, path);
  632. //Close dialog.
  633. setTimeout(UI.setBarPosition, 100);
  634. $D('noVNC_logo').style.display = "none";
  635. $D('noVNC_screen').style.display = "inline";
  636. },
  637. disconnect: function() {
  638. UI.closeSettingsMenu();
  639. UI.rfb.disconnect();
  640. // Restore the callback used for initial resize
  641. UI.rfb.set_onFBUComplete(UI.initialResize);
  642. $D('noVNC_logo').style.display = "block";
  643. $D('noVNC_screen').style.display = "none";
  644. // Don't display the connection settings until we're actually disconnected
  645. },
  646. setPassword: function() {
  647. UI.rfb.sendPassword($D('noVNC_setting_password').value);
  648. //Reset connect button.
  649. $D('noVNC_connect_button').value = "Connect";
  650. $D('noVNC_connect_button').onclick = UI.connect;
  651. //Hide connection panel.
  652. UI.toggleConnectPanel();
  653. return false;
  654. },
  655. /* ------^-------
  656. * /CONNECTION
  657. * ==============
  658. * FULLSCREEN
  659. * ------v------*/
  660. toggleFullscreen: function() {
  661. if (document.fullscreenElement || // alternative standard method
  662. document.mozFullScreenElement || // currently working methods
  663. document.webkitFullscreenElement ||
  664. document.msFullscreenElement) {
  665. if (document.exitFullscreen) {
  666. document.exitFullscreen();
  667. } else if (document.mozCancelFullScreen) {
  668. document.mozCancelFullScreen();
  669. } else if (document.webkitExitFullscreen) {
  670. document.webkitExitFullscreen();
  671. } else if (document.msExitFullscreen) {
  672. document.msExitFullscreen();
  673. }
  674. } else {
  675. if (document.documentElement.requestFullscreen) {
  676. document.documentElement.requestFullscreen();
  677. } else if (document.documentElement.mozRequestFullScreen) {
  678. document.documentElement.mozRequestFullScreen();
  679. } else if (document.documentElement.webkitRequestFullscreen) {
  680. document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  681. } else if (document.body.msRequestFullscreen) {
  682. document.body.msRequestFullscreen();
  683. }
  684. }
  685. UI.enableDisableViewClip();
  686. UI.updateFullscreenButton();
  687. },
  688. updateFullscreenButton: function() {
  689. if (document.fullscreenElement || // alternative standard method
  690. document.mozFullScreenElement || // currently working methods
  691. document.webkitFullscreenElement ||
  692. document.msFullscreenElement ) {
  693. $D('noVNC_fullscreen_button').className = "noVNC_status_button_selected";
  694. } else {
  695. $D('noVNC_fullscreen_button').className = "noVNC_status_button";
  696. }
  697. },
  698. /* ------^-------
  699. * /FULLSCREEN
  700. * ==============
  701. * RESIZE
  702. * ------v------*/
  703. // Apply remote resizing or local scaling
  704. applyResizeMode: function() {
  705. if (!UI.rfb) return;
  706. var screen = UI.screenSize();
  707. if (screen && UI.rfb_state === 'normal' && UI.rfb.get_display()) {
  708. var display = UI.rfb.get_display();
  709. var resizeMode = UI.getSetting('resize');
  710. if (resizeMode === 'remote') {
  711. // Request changing the resolution of the remote display to
  712. // the size of the local browser viewport.
  713. // In order to not send multiple requests before the browser-resize
  714. // is finished we wait 0.5 seconds before sending the request.
  715. clearTimeout(UI.resizeTimeout);
  716. UI.resizeTimeout = setTimeout(function(){
  717. // Limit the viewport to the size of the browser window
  718. display.set_maxWidth(screen.w);
  719. display.set_maxHeight(screen.h);
  720. Util.Debug('Attempting requestDesktopSize(' +
  721. screen.w + ', ' + screen.h + ')');
  722. // Request a remote size covering the viewport
  723. UI.rfb.requestDesktopSize(screen.w, screen.h);
  724. }, 500);
  725. } else if (resizeMode === 'scale' || resizeMode === 'downscale') {
  726. var downscaleOnly = resizeMode === 'downscale';
  727. var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly);
  728. UI.rfb.get_mouse().set_scale(scaleRatio);
  729. Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale());
  730. }
  731. }
  732. },
  733. // The screen is always the same size as the available viewport
  734. // in the browser window minus the height of the control bar
  735. screenSize: function() {
  736. var screen = $D('noVNC_screen');
  737. // Hide the scrollbars until the size is calculated
  738. screen.style.overflow = "hidden";
  739. var pos = Util.getPosition(screen);
  740. var w = pos.width;
  741. var h = pos.height;
  742. screen.style.overflow = "visible";
  743. if (isNaN(w) || isNaN(h)) {
  744. return false;
  745. } else {
  746. return {w: w, h: h};
  747. }
  748. },
  749. // Normally we only apply the current resize mode after a window resize
  750. // event. This means that when a new connection is opened, there is no
  751. // resize mode active.
  752. // We have to wait until the first FBU because this is where the client
  753. // will find the supported encodings of the server. Some calls later in
  754. // the chain is dependant on knowing the server-capabilities.
  755. initialResize: function(rfb, fbu) {
  756. UI.applyResizeMode();
  757. // After doing this once, we remove the callback.
  758. UI.rfb.set_onFBUComplete(function() { });
  759. },
  760. /* ------^-------
  761. * /RESIZE
  762. * ==============
  763. * CLIPPING
  764. * ------v------*/
  765. // Set and configure viewport clipping
  766. setViewClip: function(clip) {
  767. var display;
  768. if (UI.rfb) {
  769. display = UI.rfb.get_display();
  770. } else {
  771. UI.forceSetting('clip', clip);
  772. return;
  773. }
  774. var cur_clip = display.get_viewport();
  775. if (typeof(clip) !== 'boolean') {
  776. // Use current setting
  777. clip = UI.getSetting('clip');
  778. }
  779. if (clip && !cur_clip) {
  780. // Turn clipping on
  781. UI.updateSetting('clip', true);
  782. } else if (!clip && cur_clip) {
  783. // Turn clipping off
  784. UI.updateSetting('clip', false);
  785. display.set_viewport(false);
  786. // Disable max dimensions
  787. display.set_maxWidth(0);
  788. display.set_maxHeight(0);
  789. display.viewportChangeSize();
  790. }
  791. if (UI.getSetting('clip')) {
  792. // If clipping, update clipping settings
  793. display.set_viewport(true);
  794. var size = UI.screenSize();
  795. if (size) {
  796. display.set_maxWidth(size.w);
  797. display.set_maxHeight(size.h);
  798. // Hide potential scrollbars that can skew the position
  799. $D('noVNC_screen').style.overflow = "hidden";
  800. // The x position marks the left margin of the canvas,
  801. // remove the margin from both sides to keep it centered
  802. var new_w = size.w - (2 * Util.getPosition($D('noVNC_canvas')).x);
  803. $D('noVNC_screen').style.overflow = "visible";
  804. display.viewportChangeSize(new_w, size.h);
  805. }
  806. }
  807. },
  808. // Handle special cases where clipping is forced on/off or locked
  809. enableDisableViewClip: function() {
  810. var resizeSetting = $D('noVNC_setting_resize');
  811. var connected = UI.rfb && UI.rfb_state === 'normal';
  812. if (UI.isSafari) {
  813. // Safari auto-hides the scrollbars which makes them
  814. // impossible to use in most cases
  815. UI.setViewClip(true);
  816. $D('noVNC_setting_clip').disabled = true;
  817. } else if (resizeSetting.value === 'downscale' || resizeSetting.value === 'scale') {
  818. // Disable clipping if we are scaling
  819. UI.setViewClip(false);
  820. $D('noVNC_setting_clip').disabled = true;
  821. } else if (document.msFullscreenElement) {
  822. // The browser is IE and we are in fullscreen mode.
  823. // - We need to force clipping while in fullscreen since
  824. // scrollbars doesn't work.
  825. UI.popupStatus("Forcing clipping mode since scrollbars aren't supported by IE in fullscreen");
  826. UI.rememberedClipSetting = UI.getSetting('clip');
  827. UI.setViewClip(true);
  828. $D('noVNC_setting_clip').disabled = true;
  829. } else if (document.body.msRequestFullscreen && UI.rememberedClip !== null) {
  830. // Restore view clip to what it was before fullscreen on IE
  831. UI.setViewClip(UI.rememberedClipSetting);
  832. $D('noVNC_setting_clip').disabled = connected || UI.isTouchDevice;
  833. } else {
  834. $D('noVNC_setting_clip').disabled = connected || UI.isTouchDevice;
  835. if (UI.isTouchDevice) {
  836. UI.setViewClip(true);
  837. }
  838. }
  839. },
  840. /* ------^-------
  841. * /CLIPPING
  842. * ==============
  843. * VIEWDRAG
  844. * ------v------*/
  845. // Update the viewport drag state
  846. updateViewDrag: function(drag) {
  847. if (!UI.rfb) return;
  848. var viewDragButton = $D('noVNC_view_drag_button');
  849. // Check if viewport drag is possible. It is only possible
  850. // if the remote display is clipping the client display.
  851. if (UI.rfb_state === 'normal' &&
  852. UI.rfb.get_display().get_viewport() &&
  853. UI.rfb.get_display().clippingDisplay()) {
  854. viewDragButton.style.display = "inline";
  855. viewDragButton.disabled = false;
  856. } else {
  857. // The size of the remote display is the same or smaller
  858. // than the client display. Make sure viewport drag isn't
  859. // active when it can't be used.
  860. if (UI.rfb.get_viewportDrag) {
  861. viewDragButton.className = "noVNC_status_button";
  862. UI.rfb.set_viewportDrag(false);
  863. }
  864. // The button is disabled instead of hidden on touch devices
  865. if (UI.rfb_state === 'normal' && UI.isTouchDevice) {
  866. viewDragButton.style.display = "inline";
  867. viewDragButton.disabled = true;
  868. } else {
  869. viewDragButton.style.display = "none";
  870. }
  871. return;
  872. }
  873. if (typeof(drag) !== "undefined" &&
  874. typeof(drag) !== "object") {
  875. if (drag) {
  876. viewDragButton.className = "noVNC_status_button_selected";
  877. UI.rfb.set_viewportDrag(true);
  878. } else {
  879. viewDragButton.className = "noVNC_status_button";
  880. UI.rfb.set_viewportDrag(false);
  881. }
  882. }
  883. },
  884. toggleViewDrag: function() {
  885. if (!UI.rfb) return;
  886. var viewDragButton = $D('noVNC_view_drag_button');
  887. if (UI.rfb.get_viewportDrag()) {
  888. viewDragButton.className = "noVNC_status_button";
  889. UI.rfb.set_viewportDrag(false);
  890. } else {
  891. viewDragButton.className = "noVNC_status_button_selected";
  892. UI.rfb.set_viewportDrag(true);
  893. }
  894. },
  895. /* ------^-------
  896. * /VIEWDRAG
  897. * ==============
  898. * KEYBOARD
  899. * ------v------*/
  900. // On touch devices, show the OS keyboard
  901. showKeyboard: function() {
  902. var kbi = $D('noVNC_keyboardinput');
  903. var skb = $D('noVNC_keyboard_button');
  904. var l = kbi.value.length;
  905. if(UI.keyboardVisible === false) {
  906. kbi.focus();
  907. try { kbi.setSelectionRange(l, l); } // Move the caret to the end
  908. catch (err) {} // setSelectionRange is undefined in Google Chrome
  909. UI.keyboardVisible = true;
  910. skb.className = "noVNC_status_button_selected";
  911. } else if(UI.keyboardVisible === true) {
  912. kbi.blur();
  913. skb.className = "noVNC_status_button";
  914. UI.keyboardVisible = false;
  915. }
  916. },
  917. hideKeyboard: function() {
  918. $D('noVNC_keyboard_button').className = "noVNC_status_button";
  919. //Weird bug in iOS if you change keyboardVisible
  920. //here it does not actually occur so next time
  921. //you click keyboard icon it doesnt work.
  922. UI.hideKeyboardTimeout = setTimeout(function() {
  923. UI.keyboardVisible = false;
  924. },100);
  925. },
  926. keepKeyboard: function() {
  927. clearTimeout(UI.hideKeyboardTimeout);
  928. if(UI.keyboardVisible === true) {
  929. $D('noVNC_keyboardinput').focus();
  930. $D('noVNC_keyboard_button').className = "noVNC_status_button_selected";
  931. } else if(UI.keyboardVisible === false) {
  932. $D('noVNC_keyboardinput').blur();
  933. $D('noVNC_keyboard_button').className = "noVNC_status_button";
  934. }
  935. },
  936. keyboardinputReset: function() {
  937. var kbi = $D('noVNC_keyboardinput');
  938. kbi.value = new Array(UI.defaultKeyboardinputLen).join("_");
  939. UI.lastKeyboardinput = kbi.value;
  940. },
  941. // When normal keyboard events are left uncought, use the input events from
  942. // the keyboardinput element instead and generate the corresponding key events.
  943. // This code is required since some browsers on Android are inconsistent in
  944. // sending keyCodes in the normal keyboard events when using on screen keyboards.
  945. keyInput: function(event) {
  946. if (!UI.rfb) return;
  947. var newValue = event.target.value;
  948. if (!UI.lastKeyboardinput) {
  949. UI.keyboardinputReset();
  950. }
  951. var oldValue = UI.lastKeyboardinput;
  952. var newLen;
  953. try {
  954. // Try to check caret position since whitespace at the end
  955. // will not be considered by value.length in some browsers
  956. newLen = Math.max(event.target.selectionStart, newValue.length);
  957. } catch (err) {
  958. // selectionStart is undefined in Google Chrome
  959. newLen = newValue.length;
  960. }
  961. var oldLen = oldValue.length;
  962. var backspaces;
  963. var inputs = newLen - oldLen;
  964. if (inputs < 0) {
  965. backspaces = -inputs;
  966. } else {
  967. backspaces = 0;
  968. }
  969. // Compare the old string with the new to account for
  970. // text-corrections or other input that modify existing text
  971. var i;
  972. for (i = 0; i < Math.min(oldLen, newLen); i++) {
  973. if (newValue.charAt(i) != oldValue.charAt(i)) {
  974. inputs = newLen - i;
  975. backspaces = oldLen - i;
  976. break;
  977. }
  978. }
  979. // Send the key events
  980. for (i = 0; i < backspaces; i++) {
  981. UI.rfb.sendKey(XK_BackSpace);
  982. }
  983. for (i = newLen - inputs; i < newLen; i++) {
  984. UI.rfb.sendKey(newValue.charCodeAt(i));
  985. }
  986. // Control the text content length in the keyboardinput element
  987. if (newLen > 2 * UI.defaultKeyboardinputLen) {
  988. UI.keyboardinputReset();
  989. } else if (newLen < 1) {
  990. // There always have to be some text in the keyboardinput
  991. // element with which backspace can interact.
  992. UI.keyboardinputReset();
  993. // This sometimes causes the keyboard to disappear for a second
  994. // but it is required for the android keyboard to recognize that
  995. // text has been added to the field
  996. event.target.blur();
  997. // This has to be ran outside of the input handler in order to work
  998. setTimeout(UI.keepKeyboard, 0);
  999. } else {
  1000. UI.lastKeyboardinput = newValue;
  1001. }
  1002. },
  1003. toggleExtraKeys: function() {
  1004. UI.keepKeyboard();
  1005. if(UI.extraKeysVisible === false) {
  1006. $D('noVNC_toggleCtrl_button').style.display = "inline";
  1007. $D('noVNC_toggleAlt_button').style.display = "inline";
  1008. $D('noVNC_sendTab_button').style.display = "inline";
  1009. $D('noVNC_sendEsc_button').style.display = "inline";
  1010. $D('noVNC_toggleExtraKeys_button').className = "noVNC_status_button_selected";
  1011. UI.extraKeysVisible = true;
  1012. } else if(UI.extraKeysVisible === true) {
  1013. $D('noVNC_toggleCtrl_button').style.display = "";
  1014. $D('noVNC_toggleAlt_button').style.display = "";
  1015. $D('noVNC_sendTab_button').style.display = "";
  1016. $D('noVNC_sendEsc_button').style.display = "";
  1017. $D('noVNC_toggleExtraKeys_button').className = "noVNC_status_button";
  1018. UI.extraKeysVisible = false;
  1019. }
  1020. },
  1021. sendEsc: function() {
  1022. UI.keepKeyboard();
  1023. UI.rfb.sendKey(XK_Escape);
  1024. },
  1025. sendTab: function() {
  1026. UI.keepKeyboard();
  1027. UI.rfb.sendKey(XK_Tab);
  1028. },
  1029. toggleCtrl: function() {
  1030. UI.keepKeyboard();
  1031. if(UI.ctrlOn === false) {
  1032. UI.rfb.sendKey(XK_Control_L, true);
  1033. $D('noVNC_toggleCtrl_button').className = "noVNC_status_button_selected";
  1034. UI.ctrlOn = true;
  1035. } else if(UI.ctrlOn === true) {
  1036. UI.rfb.sendKey(XK_Control_L, false);
  1037. $D('noVNC_toggleCtrl_button').className = "noVNC_status_button";
  1038. UI.ctrlOn = false;
  1039. }
  1040. },
  1041. toggleAlt: function() {
  1042. UI.keepKeyboard();
  1043. if(UI.altOn === false) {
  1044. UI.rfb.sendKey(XK_Alt_L, true);
  1045. $D('noVNC_toggleAlt_button').className = "noVNC_status_button_selected";
  1046. UI.altOn = true;
  1047. } else if(UI.altOn === true) {
  1048. UI.rfb.sendKey(XK_Alt_L, false);
  1049. $D('noVNC_toggleAlt_button').className = "noVNC_status_button";
  1050. UI.altOn = false;
  1051. }
  1052. },
  1053. sendCtrlAltDel: function() {
  1054. UI.rfb.sendCtrlAltDel();
  1055. },
  1056. /* ------^-------
  1057. * /KEYBOARD
  1058. * ==============
  1059. * MISC
  1060. * ------v------*/
  1061. setMouseButton: function(num) {
  1062. if (typeof num === 'undefined') {
  1063. // Disable mouse buttons
  1064. num = -1;
  1065. }
  1066. if (UI.rfb) {
  1067. UI.rfb.get_mouse().set_touchButton(num);
  1068. }
  1069. var blist = [0, 1,2,4];
  1070. for (var b = 0; b < blist.length; b++) {
  1071. var button = $D('noVNC_mouse_button' + blist[b]);
  1072. if (blist[b] === num) {
  1073. button.style.display = "";
  1074. } else {
  1075. button.style.display = "none";
  1076. }
  1077. }
  1078. },
  1079. displayBlur: function() {
  1080. if (!UI.rfb) return;
  1081. UI.rfb.get_keyboard().set_focused(false);
  1082. UI.rfb.get_mouse().set_focused(false);
  1083. },
  1084. displayFocus: function() {
  1085. if (!UI.rfb) return;
  1086. UI.rfb.get_keyboard().set_focused(true);
  1087. UI.rfb.get_mouse().set_focused(true);
  1088. },
  1089. // Display the desktop name in the document title
  1090. updateDocumentTitle: function(rfb, name) {
  1091. document.title = name + " - noVNC";
  1092. },
  1093. //Helper to add options to dropdown.
  1094. addOption: function(selectbox, text, value) {
  1095. var optn = document.createElement("OPTION");
  1096. optn.text = text;
  1097. optn.value = value;
  1098. selectbox.options.add(optn);
  1099. },
  1100. setBarPosition: function() {
  1101. $D('noVNC_control_bar').style.top = (window.pageYOffset) + 'px';
  1102. $D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px';
  1103. var vncwidth = $D('noVNC_container').style.offsetWidth;
  1104. $D('noVNC_control_bar').style.width = vncwidth + 'px';
  1105. }
  1106. /* ------^-------
  1107. * /MISC
  1108. * ==============
  1109. */
  1110. };
  1111. })();