ui.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * noVNC: HTML5 VNC client
  3. * Copyright (C) 2012 Joel Martin
  4. * Licensed under MPL 2.0 (see LICENSE.txt)
  5. *
  6. * See README.md for usage and integration instructions.
  7. */
  8. "use strict";
  9. /*jslint white: false, browser: true */
  10. /*global window, $D, Util, WebUtil, RFB, Display */
  11. // Load supporting scripts
  12. window.onscriptsload = function () { UI.load(); };
  13. Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
  14. "input.js", "display.js", "jsunzip.js", "rfb.js"]);
  15. var UI = {
  16. rfb_state : 'loaded',
  17. settingsOpen : false,
  18. connSettingsOpen : false,
  19. clipboardOpen: false,
  20. keyboardVisible: false,
  21. // Setup rfb object, load settings from browser storage, then call
  22. // UI.init to setup the UI/menus
  23. load: function (callback) {
  24. WebUtil.initSettings(UI.start, callback);
  25. },
  26. // Render default UI and initialize settings menu
  27. start: function(callback) {
  28. var html = '', i, sheet, sheets, llevels;
  29. // Stylesheet selection dropdown
  30. sheet = WebUtil.selectStylesheet();
  31. sheets = WebUtil.getStylesheets();
  32. for (i = 0; i < sheets.length; i += 1) {
  33. UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
  34. }
  35. // Logging selection dropdown
  36. llevels = ['error', 'warn', 'info', 'debug'];
  37. for (i = 0; i < llevels.length; i += 1) {
  38. UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
  39. }
  40. // Settings with immediate effects
  41. UI.initSetting('logging', 'warn');
  42. WebUtil.init_logging(UI.getSetting('logging'));
  43. UI.initSetting('stylesheet', 'default');
  44. WebUtil.selectStylesheet(null);
  45. // call twice to get around webkit bug
  46. WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
  47. /* Populate the controls if defaults are provided in the URL */
  48. UI.initSetting('host', window.location.hostname);
  49. UI.initSetting('port', window.location.port);
  50. UI.initSetting('password', '');
  51. UI.initSetting('encrypt', (window.location.protocol === "https:"));
  52. UI.initSetting('true_color', true);
  53. UI.initSetting('cursor', false);
  54. UI.initSetting('shared', true);
  55. UI.initSetting('view_only', false);
  56. UI.initSetting('connectTimeout', 2);
  57. UI.initSetting('path', 'websockify');
  58. UI.initSetting('repeaterID', '');
  59. UI.rfb = RFB({'target': $D('noVNC_canvas'),
  60. 'onUpdateState': UI.updateState,
  61. 'onClipboard': UI.clipReceive});
  62. UI.updateVisualState();
  63. // Unfocus clipboard when over the VNC area
  64. //$D('VNC_screen').onmousemove = function () {
  65. // var keyboard = UI.rfb.get_keyboard();
  66. // if ((! keyboard) || (! keyboard.get_focused())) {
  67. // $D('VNC_clipboard_text').blur();
  68. // }
  69. // };
  70. // Show mouse selector buttons on touch screen devices
  71. if ('ontouchstart' in document.documentElement) {
  72. // Show mobile buttons
  73. $D('noVNC_mobile_buttons').style.display = "inline";
  74. UI.setMouseButton();
  75. // Remove the address bar
  76. setTimeout(function() { window.scrollTo(0, 1); }, 100);
  77. UI.forceSetting('clip', true);
  78. $D('noVNC_clip').disabled = true;
  79. } else {
  80. UI.initSetting('clip', false);
  81. }
  82. //iOS Safari does not support CSS position:fixed.
  83. //This detects iOS devices and enables javascript workaround.
  84. if ((navigator.userAgent.match(/iPhone/i)) ||
  85. (navigator.userAgent.match(/iPod/i)) ||
  86. (navigator.userAgent.match(/iPad/i))) {
  87. //UI.setOnscroll();
  88. //UI.setResize();
  89. }
  90. UI.setBarPosition();
  91. $D('noVNC_host').focus();
  92. UI.setViewClip();
  93. Util.addEvent(window, 'resize', UI.setViewClip);
  94. Util.addEvent(window, 'beforeunload', function () {
  95. if (UI.rfb_state === 'normal') {
  96. return "You are currently connected.";
  97. }
  98. } );
  99. // Show description by default when hosted at for kanaka.github.com
  100. if (location.host === "kanaka.github.com") {
  101. // Open the description dialog
  102. $D('noVNC_description').style.display = "block";
  103. } else {
  104. // Open the connect panel on first load
  105. UI.toggleConnectPanel();
  106. }
  107. // Add mouse event click/focus/blur event handlers to the UI
  108. UI.addMouseHandlers();
  109. if (typeof callback === "function") {
  110. callback(UI.rfb);
  111. }
  112. },
  113. addMouseHandlers: function() {
  114. // Setup interface handlers that can't be inline
  115. $D("noVNC_view_drag_button").onclick = UI.setViewDrag;
  116. $D("noVNC_mouse_button0").onclick = function () { UI.setMouseButton(1); };
  117. $D("noVNC_mouse_button1").onclick = function () { UI.setMouseButton(2); };
  118. $D("noVNC_mouse_button2").onclick = function () { UI.setMouseButton(4); };
  119. $D("noVNC_mouse_button4").onclick = function () { UI.setMouseButton(0); };
  120. $D("showKeyboard").onclick = UI.showKeyboard;
  121. //$D("keyboardinput").onkeydown = function (event) { onKeyDown(event); };
  122. $D("keyboardinput").onblur = UI.keyInputBlur;
  123. $D("sendCtrlAltDelButton").onclick = UI.sendCtrlAltDel;
  124. $D("clipboardButton").onclick = UI.toggleClipboardPanel;
  125. $D("settingsButton").onclick = UI.toggleSettingsPanel;
  126. $D("connectButton").onclick = UI.toggleConnectPanel;
  127. $D("disconnectButton").onclick = UI.disconnect;
  128. $D("descriptionButton").onclick = UI.toggleConnectPanel;
  129. $D("noVNC_clipboard_text").onfocus = UI.displayBlur;
  130. $D("noVNC_clipboard_text").onblur = UI.displayFocus;
  131. $D("noVNC_clipboard_text").onchange = UI.clipSend;
  132. $D("noVNC_clipboard_clear_button").onclick = UI.clipClear;
  133. $D("noVNC_settings_menu").onmouseover = UI.displayBlur;
  134. $D("noVNC_settings_menu").onmouseover = UI.displayFocus;
  135. $D("noVNC_apply").onclick = UI.settingsApply;
  136. $D("noVNC_connect_button").onclick = UI.connect;
  137. },
  138. // Read form control compatible setting from cookie
  139. getSetting: function(name) {
  140. var val, ctrl = $D('noVNC_' + name);
  141. val = WebUtil.readSetting(name);
  142. if (val !== null && ctrl.type === 'checkbox') {
  143. if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
  144. val = false;
  145. } else {
  146. val = true;
  147. }
  148. }
  149. return val;
  150. },
  151. // Update cookie and form control setting. If value is not set, then
  152. // updates from control to current cookie setting.
  153. updateSetting: function(name, value) {
  154. var i, ctrl = $D('noVNC_' + name);
  155. // Save the cookie for this session
  156. if (typeof value !== 'undefined') {
  157. WebUtil.writeSetting(name, value);
  158. }
  159. // Update the settings control
  160. value = UI.getSetting(name);
  161. if (ctrl.type === 'checkbox') {
  162. ctrl.checked = value;
  163. } else if (typeof ctrl.options !== 'undefined') {
  164. for (i = 0; i < ctrl.options.length; i += 1) {
  165. if (ctrl.options[i].value === value) {
  166. ctrl.selectedIndex = i;
  167. break;
  168. }
  169. }
  170. } else {
  171. /*Weird IE9 error leads to 'null' appearring
  172. in textboxes instead of ''.*/
  173. if (value === null) {
  174. value = "";
  175. }
  176. ctrl.value = value;
  177. }
  178. },
  179. // Save control setting to cookie
  180. saveSetting: function(name) {
  181. var val, ctrl = $D('noVNC_' + name);
  182. if (ctrl.type === 'checkbox') {
  183. val = ctrl.checked;
  184. } else if (typeof ctrl.options !== 'undefined') {
  185. val = ctrl.options[ctrl.selectedIndex].value;
  186. } else {
  187. val = ctrl.value;
  188. }
  189. WebUtil.writeSetting(name, val);
  190. //Util.Debug("Setting saved '" + name + "=" + val + "'");
  191. return val;
  192. },
  193. // Initial page load read/initialization of settings
  194. initSetting: function(name, defVal) {
  195. var val;
  196. // Check Query string followed by cookie
  197. val = WebUtil.getQueryVar(name);
  198. if (val === null) {
  199. val = WebUtil.readSetting(name, defVal);
  200. }
  201. UI.updateSetting(name, val);
  202. //Util.Debug("Setting '" + name + "' initialized to '" + val + "'");
  203. return val;
  204. },
  205. // Force a setting to be a certain value
  206. forceSetting: function(name, val) {
  207. UI.updateSetting(name, val);
  208. return val;
  209. },
  210. // Show the clipboard panel
  211. toggleClipboardPanel: function() {
  212. // Close the description panel
  213. $D('noVNC_description').style.display = "none";
  214. //Close settings if open
  215. if (UI.settingsOpen === true) {
  216. UI.settingsApply();
  217. UI.closeSettingsMenu();
  218. }
  219. //Close connection settings if open
  220. if (UI.connSettingsOpen === true) {
  221. UI.toggleConnectPanel();
  222. }
  223. //Toggle Clipboard Panel
  224. if (UI.clipboardOpen === true) {
  225. $D('noVNC_clipboard').style.display = "none";
  226. $D('clipboardButton').className = "noVNC_status_button";
  227. UI.clipboardOpen = false;
  228. } else {
  229. $D('noVNC_clipboard').style.display = "block";
  230. $D('clipboardButton').className = "noVNC_status_button_selected";
  231. UI.clipboardOpen = true;
  232. }
  233. },
  234. // Show the connection settings panel/menu
  235. toggleConnectPanel: function() {
  236. // Close the description panel
  237. $D('noVNC_description').style.display = "none";
  238. //Close connection settings if open
  239. if (UI.settingsOpen === true) {
  240. UI.settingsApply();
  241. UI.closeSettingsMenu();
  242. $D('connectButton').className = "noVNC_status_button";
  243. }
  244. if (UI.clipboardOpen === true) {
  245. UI.toggleClipboardPanel();
  246. }
  247. //Toggle Connection Panel
  248. if (UI.connSettingsOpen === true) {
  249. $D('noVNC_controls').style.display = "none";
  250. $D('connectButton').className = "noVNC_status_button";
  251. UI.connSettingsOpen = false;
  252. UI.saveSetting('host');
  253. UI.saveSetting('port');
  254. //UI.saveSetting('password');
  255. } else {
  256. $D('noVNC_controls').style.display = "block";
  257. $D('connectButton').className = "noVNC_status_button_selected";
  258. UI.connSettingsOpen = true;
  259. $D('noVNC_host').focus();
  260. }
  261. },
  262. // Toggle the settings menu:
  263. // On open, settings are refreshed from saved cookies.
  264. // On close, settings are applied
  265. toggleSettingsPanel: function() {
  266. // Close the description panel
  267. $D('noVNC_description').style.display = "none";
  268. if (UI.settingsOpen) {
  269. UI.settingsApply();
  270. UI.closeSettingsMenu();
  271. } else {
  272. UI.updateSetting('encrypt');
  273. UI.updateSetting('true_color');
  274. if (UI.rfb.get_display().get_cursor_uri()) {
  275. UI.updateSetting('cursor');
  276. } else {
  277. UI.updateSetting('cursor', false);
  278. $D('noVNC_cursor').disabled = true;
  279. }
  280. UI.updateSetting('clip');
  281. UI.updateSetting('shared');
  282. UI.updateSetting('view_only');
  283. UI.updateSetting('connectTimeout');
  284. UI.updateSetting('path');
  285. UI.updateSetting('repeaterID');
  286. UI.updateSetting('stylesheet');
  287. UI.updateSetting('logging');
  288. UI.openSettingsMenu();
  289. }
  290. },
  291. // Open menu
  292. openSettingsMenu: function() {
  293. // Close the description panel
  294. $D('noVNC_description').style.display = "none";
  295. if (UI.clipboardOpen === true) {
  296. UI.toggleClipboardPanel();
  297. }
  298. //Close connection settings if open
  299. if (UI.connSettingsOpen === true) {
  300. UI.toggleConnectPanel();
  301. }
  302. $D('noVNC_settings').style.display = "block";
  303. $D('settingsButton').className = "noVNC_status_button_selected";
  304. UI.settingsOpen = true;
  305. },
  306. // Close menu (without applying settings)
  307. closeSettingsMenu: function() {
  308. $D('noVNC_settings').style.display = "none";
  309. $D('settingsButton').className = "noVNC_status_button";
  310. UI.settingsOpen = false;
  311. },
  312. // Save/apply settings when 'Apply' button is pressed
  313. settingsApply: function() {
  314. //Util.Debug(">> settingsApply");
  315. UI.saveSetting('encrypt');
  316. UI.saveSetting('true_color');
  317. if (UI.rfb.get_display().get_cursor_uri()) {
  318. UI.saveSetting('cursor');
  319. }
  320. UI.saveSetting('clip');
  321. UI.saveSetting('shared');
  322. UI.saveSetting('view_only');
  323. UI.saveSetting('connectTimeout');
  324. UI.saveSetting('path');
  325. UI.saveSetting('repeaterID');
  326. UI.saveSetting('stylesheet');
  327. UI.saveSetting('logging');
  328. // Settings with immediate (non-connected related) effect
  329. WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
  330. WebUtil.init_logging(UI.getSetting('logging'));
  331. UI.setViewClip();
  332. UI.setViewDrag(UI.rfb.get_viewportDrag());
  333. //Util.Debug("<< settingsApply");
  334. },
  335. setPassword: function() {
  336. UI.rfb.sendPassword($D('noVNC_password').value);
  337. //Reset connect button.
  338. $D('noVNC_connect_button').value = "Connect";
  339. $D('noVNC_connect_button').onclick = UI.Connect;
  340. //Hide connection panel.
  341. UI.toggleConnectPanel();
  342. return false;
  343. },
  344. sendCtrlAltDel: function() {
  345. UI.rfb.sendCtrlAltDel();
  346. },
  347. setMouseButton: function(num) {
  348. var b, blist = [0, 1,2,4], button;
  349. if (typeof num === 'undefined') {
  350. // Disable mouse buttons
  351. num = -1;
  352. }
  353. if (UI.rfb) {
  354. UI.rfb.get_mouse().set_touchButton(num);
  355. }
  356. for (b = 0; b < blist.length; b++) {
  357. button = $D('noVNC_mouse_button' + blist[b]);
  358. if (blist[b] === num) {
  359. button.style.display = "";
  360. } else {
  361. button.style.display = "none";
  362. /*
  363. button.style.backgroundColor = "black";
  364. button.style.color = "lightgray";
  365. button.style.backgroundColor = "";
  366. button.style.color = "";
  367. */
  368. }
  369. }
  370. },
  371. updateState: function(rfb, state, oldstate, msg) {
  372. var s, sb, c, d, cad, vd, klass;
  373. UI.rfb_state = state;
  374. s = $D('noVNC_status');
  375. sb = $D('noVNC_status_bar');
  376. switch (state) {
  377. case 'failed':
  378. case 'fatal':
  379. klass = "noVNC_status_error";
  380. break;
  381. case 'normal':
  382. klass = "noVNC_status_normal";
  383. break;
  384. case 'disconnected':
  385. $D('noVNC_logo').style.display = "block";
  386. // Fall through
  387. case 'loaded':
  388. klass = "noVNC_status_normal";
  389. break;
  390. case 'password':
  391. UI.toggleConnectPanel();
  392. $D('noVNC_connect_button').value = "Send Password";
  393. $D('noVNC_connect_button').onclick = UI.setPassword;
  394. $D('noVNC_password').focus();
  395. klass = "noVNC_status_warn";
  396. break;
  397. default:
  398. klass = "noVNC_status_warn";
  399. break;
  400. }
  401. if (typeof(msg) !== 'undefined') {
  402. s.setAttribute("class", klass);
  403. sb.setAttribute("class", klass);
  404. s.innerHTML = msg;
  405. }
  406. UI.updateVisualState();
  407. },
  408. // Disable/enable controls depending on connection state
  409. updateVisualState: function() {
  410. var connected = UI.rfb_state === 'normal' ? true : false;
  411. //Util.Debug(">> updateVisualState");
  412. $D('noVNC_encrypt').disabled = connected;
  413. $D('noVNC_true_color').disabled = connected;
  414. if (UI.rfb && UI.rfb.get_display() &&
  415. UI.rfb.get_display().get_cursor_uri()) {
  416. $D('noVNC_cursor').disabled = connected;
  417. } else {
  418. UI.updateSetting('cursor', false);
  419. $D('noVNC_cursor').disabled = true;
  420. }
  421. $D('noVNC_shared').disabled = connected;
  422. $D('noVNC_view_only').disabled = connected;
  423. $D('noVNC_connectTimeout').disabled = connected;
  424. $D('noVNC_path').disabled = connected;
  425. $D('noVNC_repeaterID').disabled = connected;
  426. if (connected) {
  427. UI.setViewClip();
  428. UI.setMouseButton(1);
  429. $D('clipboardButton').style.display = "inline";
  430. $D('showKeyboard').style.display = "inline";
  431. $D('sendCtrlAltDelButton').style.display = "inline";
  432. } else {
  433. UI.setMouseButton();
  434. $D('clipboardButton').style.display = "none";
  435. $D('showKeyboard').style.display = "none";
  436. $D('sendCtrlAltDelButton').style.display = "none";
  437. }
  438. // State change disables viewport dragging.
  439. // It is enabled (toggled) by direct click on the button
  440. UI.setViewDrag(false);
  441. switch (UI.rfb_state) {
  442. case 'fatal':
  443. case 'failed':
  444. case 'loaded':
  445. case 'disconnected':
  446. $D('connectButton').style.display = "";
  447. $D('disconnectButton').style.display = "none";
  448. break;
  449. default:
  450. $D('connectButton').style.display = "none";
  451. $D('disconnectButton').style.display = "";
  452. break;
  453. }
  454. //Util.Debug("<< updateVisualState");
  455. },
  456. clipReceive: function(rfb, text) {
  457. Util.Debug(">> UI.clipReceive: " + text.substr(0,40) + "...");
  458. $D('noVNC_clipboard_text').value = text;
  459. Util.Debug("<< UI.clipReceive");
  460. },
  461. connect: function() {
  462. var host, port, password, path;
  463. UI.closeSettingsMenu();
  464. UI.toggleConnectPanel();
  465. host = $D('noVNC_host').value;
  466. port = $D('noVNC_port').value;
  467. password = $D('noVNC_password').value;
  468. path = $D('noVNC_path').value;
  469. if ((!host) || (!port)) {
  470. throw("Must set host and port");
  471. }
  472. UI.rfb.set_encrypt(UI.getSetting('encrypt'));
  473. UI.rfb.set_true_color(UI.getSetting('true_color'));
  474. UI.rfb.set_local_cursor(UI.getSetting('cursor'));
  475. UI.rfb.set_shared(UI.getSetting('shared'));
  476. UI.rfb.set_view_only(UI.getSetting('view_only'));
  477. UI.rfb.set_connectTimeout(UI.getSetting('connectTimeout'));
  478. UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
  479. UI.rfb.connect(host, port, password, path);
  480. //Close dialog.
  481. setTimeout(UI.setBarPosition, 100);
  482. $D('noVNC_logo').style.display = "none";
  483. },
  484. disconnect: function() {
  485. UI.closeSettingsMenu();
  486. UI.rfb.disconnect();
  487. $D('noVNC_logo').style.display = "block";
  488. UI.connSettingsOpen = false;
  489. UI.toggleConnectPanel();
  490. },
  491. displayBlur: function() {
  492. UI.rfb.get_keyboard().set_focused(false);
  493. UI.rfb.get_mouse().set_focused(false);
  494. },
  495. displayFocus: function() {
  496. UI.rfb.get_keyboard().set_focused(true);
  497. UI.rfb.get_mouse().set_focused(true);
  498. },
  499. clipClear: function() {
  500. $D('noVNC_clipboard_text').value = "";
  501. UI.rfb.clipboardPasteFrom("");
  502. },
  503. clipSend: function() {
  504. var text = $D('noVNC_clipboard_text').value;
  505. Util.Debug(">> UI.clipSend: " + text.substr(0,40) + "...");
  506. UI.rfb.clipboardPasteFrom(text);
  507. Util.Debug("<< UI.clipSend");
  508. },
  509. // Enable/disable and configure viewport clipping
  510. setViewClip: function(clip) {
  511. var display, cur_clip, pos, new_w, new_h;
  512. if (UI.rfb) {
  513. display = UI.rfb.get_display();
  514. } else {
  515. return;
  516. }
  517. cur_clip = display.get_viewport();
  518. if (typeof(clip) !== 'boolean') {
  519. // Use current setting
  520. clip = UI.getSetting('clip');
  521. }
  522. if (clip && !cur_clip) {
  523. // Turn clipping on
  524. UI.updateSetting('clip', true);
  525. } else if (!clip && cur_clip) {
  526. // Turn clipping off
  527. UI.updateSetting('clip', false);
  528. display.set_viewport(false);
  529. $D('noVNC_canvas').style.position = 'static';
  530. display.viewportChange();
  531. }
  532. if (UI.getSetting('clip')) {
  533. // If clipping, update clipping settings
  534. $D('noVNC_canvas').style.position = 'absolute';
  535. pos = Util.getPosition($D('noVNC_canvas'));
  536. new_w = window.innerWidth - pos.x;
  537. new_h = window.innerHeight - pos.y;
  538. display.set_viewport(true);
  539. display.viewportChange(0, 0, new_w, new_h);
  540. }
  541. },
  542. // Toggle/set/unset the viewport drag/move button
  543. setViewDrag: function(drag) {
  544. var vmb = $D('noVNC_view_drag_button');
  545. if (!UI.rfb) { return; }
  546. if (UI.rfb_state === 'normal' &&
  547. UI.rfb.get_display().get_viewport()) {
  548. vmb.style.display = "inline";
  549. } else {
  550. vmb.style.display = "none";
  551. }
  552. if (typeof(drag) === "undefined") {
  553. // If not specified, then toggle
  554. drag = !UI.rfb.get_viewportDrag();
  555. }
  556. if (drag) {
  557. vmb.className = "noVNC_status_button_selected";
  558. UI.rfb.set_viewportDrag(true);
  559. } else {
  560. vmb.className = "noVNC_status_button";
  561. UI.rfb.set_viewportDrag(false);
  562. }
  563. },
  564. // On touch devices, show the OS keyboard
  565. showKeyboard: function() {
  566. if(UI.keyboardVisible === false) {
  567. $D('keyboardinput').focus();
  568. UI.keyboardVisible = true;
  569. $D('showKeyboard').className = "noVNC_status_button_selected";
  570. } else if(UI.keyboardVisible === true) {
  571. $D('keyboardinput').blur();
  572. $D('showKeyboard').className = "noVNC_status_button";
  573. UI.keyboardVisible = false;
  574. }
  575. },
  576. keyInputBlur: function() {
  577. $D('showKeyboard').className = "noVNC_status_button";
  578. //Weird bug in iOS if you change keyboardVisible
  579. //here it does not actually occur so next time
  580. //you click keyboard icon it doesnt work.
  581. setTimeout(function() { UI.setKeyboard(); },100);
  582. },
  583. setKeyboard: function() {
  584. UI.keyboardVisible = false;
  585. },
  586. // iOS < Version 5 does not support position fixed. Javascript workaround:
  587. setOnscroll: function() {
  588. window.onscroll = function() {
  589. UI.setBarPosition();
  590. };
  591. },
  592. setResize: function () {
  593. window.onResize = function() {
  594. UI.setBarPosition();
  595. };
  596. },
  597. //Helper to add options to dropdown.
  598. addOption: function(selectbox,text,value )
  599. {
  600. var optn = document.createElement("OPTION");
  601. optn.text = text;
  602. optn.value = value;
  603. selectbox.options.add(optn);
  604. },
  605. setBarPosition: function() {
  606. $D('noVNC-control-bar').style.top = (window.pageYOffset) + 'px';
  607. $D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px';
  608. var vncwidth = $D('noVNC_screen').style.offsetWidth;
  609. $D('noVNC-control-bar').style.width = vncwidth + 'px';
  610. }
  611. };