Commit 8e0f0088 authored by Chris Gordon's avatar Chris Gordon Committed by Joel Martin

Fixed bugs with connection panel, and moved functions into UI class.

parent c1e8b308
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
var UI = { var UI = {
settingsOpen : false, settingsOpen : false,
ConnSettingsOpen : true, connSettingsOpen : true,
clipboardOpen: false, clipboardOpen: false,
// Render default UI and initialize settings menu // Render default UI and initialize settings menu
...@@ -24,13 +24,13 @@ load: function() { ...@@ -24,13 +24,13 @@ load: function() {
sheet = WebUtil.selectStylesheet(); sheet = WebUtil.selectStylesheet();
sheets = WebUtil.getStylesheets(); sheets = WebUtil.getStylesheets();
for (i = 0; i < sheets.length; i += 1) { for (i = 0; i < sheets.length; i += 1) {
addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title); UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
} }
// Logging selection dropdown // Logging selection dropdown
llevels = ['error', 'warn', 'info', 'debug']; llevels = ['error', 'warn', 'info', 'debug'];
for (i = 0; i < llevels.length; i += 1) { for (i = 0; i < llevels.length; i += 1) {
addOption($D('noVNC_logging'),llevels[i], llevels[i]); UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
} }
// Settings with immediate effects // Settings with immediate effects
...@@ -38,7 +38,8 @@ load: function() { ...@@ -38,7 +38,8 @@ load: function() {
WebUtil.init_logging(UI.getSetting('logging')); WebUtil.init_logging(UI.getSetting('logging'));
UI.initSetting('stylesheet', 'default'); UI.initSetting('stylesheet', 'default');
WebUtil.selectStylesheet(null); // call twice to get around webkit bug WebUtil.selectStylesheet(null);
// call twice to get around webkit bug
WebUtil.selectStylesheet(UI.getSetting('stylesheet')); WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
/* Populate the controls if defaults are provided in the URL */ /* Populate the controls if defaults are provided in the URL */
...@@ -70,12 +71,16 @@ load: function() { ...@@ -70,12 +71,16 @@ load: function() {
window.scrollTo(0, 1); window.scrollTo(0, 1);
} }
//iOS Safari does not support CSS position:fixed. This detects iOS devices and enables javascript workaround. //iOS Safari does not support CSS position:fixed.
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) { //This detects iOS devices and enables javascript workaround.
if((navigator.userAgent.match(/iPhone/i))
setOnscroll(); ||(navigator.userAgent.match(/iPod/i))
setResize(); || (navigator.userAgent.match(/iPad/i))) {
UI.setOnscroll();
UI.setResize();
} }
$D('noVNC_host').focus();
}, },
// Read form control compatible setting from cookie // Read form control compatible setting from cookie
...@@ -120,7 +125,8 @@ updateSetting: function(name, value) { ...@@ -120,7 +125,8 @@ updateSetting: function(name, value) {
} }
} }
} else { } else {
/*Weird IE9 error leads to 'null' appearring in textboxes instead of ''.*/ /*Weird IE9 error leads to 'null' appearring
in textboxes instead of ''.*/
if(value === null) if(value === null)
{ {
value = ""; value = "";
...@@ -192,8 +198,8 @@ openSettingsMenu: function() { ...@@ -192,8 +198,8 @@ openSettingsMenu: function() {
UI.showClipboard(); UI.showClipboard();
} }
//Close connection settings if open //Close connection settings if open
if(UI.ConnSettingsOpen == true) { if(UI.connSettingsOpen == true) {
connectPanelbutton(); UI.connectPanelbutton();
} }
$D('noVNC_Settings').style.display = "block"; $D('noVNC_Settings').style.display = "block";
UI.settingsOpen = true; UI.settingsOpen = true;
...@@ -244,6 +250,11 @@ settingsApply: function() { ...@@ -244,6 +250,11 @@ settingsApply: function() {
setPassword: function() { setPassword: function() {
UI.rfb.sendPassword($D('noVNC_password').value); UI.rfb.sendPassword($D('noVNC_password').value);
//Reset connect button.
$D('noVNC_connect_button').value = "Connect";
$D('noVNC_connect_button').onclick = UI.Connect;
//Hide connection panel.
UI.connectPanelbutton();
return false; return false;
}, },
...@@ -283,13 +294,13 @@ updateState: function(rfb, state, oldstate, msg) { ...@@ -283,13 +294,13 @@ updateState: function(rfb, state, oldstate, msg) {
var s, sb, c, cad, klass; var s, sb, c, cad, klass;
s = $D('noVNC_status'); s = $D('noVNC_status');
sb = $D('noVNC_status_bar'); sb = $D('noVNC_status_bar');
c = $D('noVNC_connect_button'); c = $D('connectPanelbutton');
cad = $D('sendCtrlAltDelButton'); cad = $D('sendCtrlAltDelButton');
switch (state) { switch (state) {
case 'failed': case 'failed':
case 'fatal': case 'fatal':
c.disabled = true; c.disabled = true;
cad.disabled = true; cad.style.display = "none";
UI.settingsDisabled(true, rfb); UI.settingsDisabled(true, rfb);
klass = "noVNC_status_error"; klass = "noVNC_status_error";
break; break;
...@@ -297,33 +308,37 @@ updateState: function(rfb, state, oldstate, msg) { ...@@ -297,33 +308,37 @@ updateState: function(rfb, state, oldstate, msg) {
c.value = "Disconnect"; c.value = "Disconnect";
c.onclick = UI.disconnect; c.onclick = UI.disconnect;
c.disabled = false; c.disabled = false;
cad.disabled = false; cad.style.display = "block";
UI.settingsDisabled(true, rfb); UI.settingsDisabled(true, rfb);
klass = "noVNC_status_normal"; klass = "noVNC_status_normal";
break; break;
case 'disconnected': case 'disconnected':
$D('noVNC_defaultScreen').style.display = "block"; $D('noVNC_defaultScreen').style.display = "block";
c.value = "Connection";
c.onclick = UI.connectPanelbutton;
case 'loaded': case 'loaded':
c.value = "Connect"; c.value = "Connection";
c.onclick = UI.connect; c.onclick = UI.connectPanelbutton;
c.disabled = false; c.disabled = false;
cad.disabled = true; cad.style.display = "none";
UI.settingsDisabled(false, rfb); UI.settingsDisabled(false, rfb);
klass = "noVNC_status_normal"; klass = "noVNC_status_normal";
break; break;
case 'password': case 'password':
c.value = "Send Password"; UI.connectPanelbutton();
c.onclick = UI.setPassword;
$D('noVNC_connect_button').value = "Send Password";
$D('noVNC_connect_button').onclick = UI.setPassword;
$D('noVNC_password').focus();
c.disabled = false; c.disabled = false;
cad.disabled = true; cad.style.display = "none";
UI.settingsDisabled(true, rfb); UI.settingsDisabled(true, rfb);
klass = "noVNC_status_warn"; klass = "noVNC_status_warn";
break; break;
default: default:
c.disabled = true; c.disabled = true;
cad.disabled = true; cad.style.display = "none";
UI.settingsDisabled(true, rfb); UI.settingsDisabled(true, rfb);
klass = "noVNC_status_warn"; klass = "noVNC_status_warn";
break; break;
...@@ -348,7 +363,8 @@ connect: function() { ...@@ -348,7 +363,8 @@ connect: function() {
var host, port, password; var host, port, password;
UI.closeSettingsMenu(); UI.closeSettingsMenu();
connectPanelbutton(); UI.connectPanelbutton();
host = $D('noVNC_host').value; host = $D('noVNC_host').value;
port = $D('noVNC_port').value; port = $D('noVNC_port').value;
password = $D('noVNC_password').value; password = $D('noVNC_password').value;
...@@ -371,8 +387,10 @@ connect: function() { ...@@ -371,8 +387,10 @@ connect: function() {
disconnect: function() { disconnect: function() {
UI.closeSettingsMenu(); UI.closeSettingsMenu();
UI.rfb.disconnect(); UI.rfb.disconnect();
$D('noVNC_defaultScreen').style.display = "block"; $D('noVNC_defaultScreen').style.display = "block";
UI.openSettingsMenu(); UI.connSettingsOpen = false;
UI.connectPanelbutton();
}, },
displayBlur: function() { displayBlur: function() {
...@@ -403,8 +421,8 @@ showClipboard: function() { ...@@ -403,8 +421,8 @@ showClipboard: function() {
UI.closeSettingsMenu(); UI.closeSettingsMenu();
} }
//Close connection settings if open //Close connection settings if open
if(UI.ConnSettingsOpen == true) { if(UI.connSettingsOpen == true) {
connectPanelbutton(); UI.connectPanelbutton();
} }
//Toggle Connection Panel //Toggle Connection Panel
if(UI.clipboardOpen == true) if(UI.clipboardOpen == true)
...@@ -414,55 +432,35 @@ showClipboard: function() { ...@@ -414,55 +432,35 @@ showClipboard: function() {
$D('noVNC_clipboard').style.display = "block"; $D('noVNC_clipboard').style.display = "block";
UI.clipboardOpen = true; UI.clipboardOpen = true;
} }
} },
};
function connectPanelbutton() {
//Close connection settings if open
if(UI.settingsOpen == true) {
UI.closeSettingsMenu();
}
if(UI.clipboardOpen == true)
{
UI.showClipboard();
}
//Toggle Connection Panel
if(UI.ConnSettingsOpen == true)
{
$D('noVNC_controls').style.display = "none";
UI.ConnSettingsOpen = false;
} else {
$D('noVNC_controls').style.display = "block";
UI.ConnSettingsOpen = true;
}
}
function showkeyboard(){ showKeyboard: function() {
//Get Current Scroll Position //Get Current Scroll Position
var scrollx = (document.all)?document.body.scrollLeft:window.pageXOffset; var scrollx =
var scrolly = (document.all)?document.body.scrollTop:window.pageYOffset; (document.all)?document.body.scrollLeft:window.pageXOffset;
var scrolly =
(document.all)?document.body.scrollTop:window.pageYOffset;
//Stop browser zooming on textbox. //Stop browser zooming on textbox.
zoomDisable(); UI.zoomDisable();
$D('keyboardinput').focus(); $D('keyboardinput').focus();
scroll(scrollx,scrolly); scroll(scrollx,scrolly);
//Renable user zoom. //Renable user zoom.
zoomEnable(); UI.zoomEnable();
} },
function zoomDisable(){ zoomDisable: function() {
//Change viewport meta data to disable zooming. //Change viewport meta data to disable zooming.
changeViewportMeta("user-scalable=0"); UI.changeViewportMeta("user-scalable=0");
} },
function zoomEnable(){ zoomEnable: function(){
//Change viewport meta data to enable user zooming. //Change viewport meta data to enable user zooming.
changeViewportMeta("user-scalable=1"); UI.changeViewportMeta("user-scalable=1");
} },
function changeViewportMeta(newattributes) { changeViewportMeta: function (newattributes) {
// First, get the array of meta-tag elements // First, get the array of meta-tag elements
var metatags = document.getElementsByTagName("meta"); var metatags = document.getElementsByTagName("meta");
...@@ -478,35 +476,63 @@ function changeViewportMeta(newattributes) { ...@@ -478,35 +476,63 @@ function changeViewportMeta(newattributes) {
if (metatags[cnt].getAttribute("name") == "viewport") if (metatags[cnt].getAttribute("name") == "viewport")
metatags[cnt].setAttribute("content", newattributes); metatags[cnt].setAttribute("content", newattributes);
} }
} },
//iOS < Version 5 does not support position fixed. Javascript workaround: //iOS < Version 5 does not support position fixed. Javascript workaround:
function setOnscroll() { setOnscroll: function() {
window.onscroll = function() { window.onscroll = function() {
setBarPosition(); UI.setBarPosition();
}; };
} },
function setResize() { setResize: function () {
window.onResize = function() { window.onResize = function() {
setBarPosition(); UI.setBarPosition();
}; };
} },
//Helper to add options to dropdown.
addOption: function(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
},
function setBarPosition() { setBarPosition: function() {
$D('noVNC-control-bar').style.top = (window.pageYOffset) + 'px'; $D('noVNC-control-bar').style.top = (window.pageYOffset) + 'px';
$D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px'; $D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px';
$D('noVNC_mobile_buttons_right').style.right = 0 + 'px'; $D('noVNC_mobile_buttons_right').style.right = 0 + 'px';
var vncwidth = $('#noVNC_screen').width(); var vncwidth = $('#noVNC_screen').width();
$D('noVNC-control-bar').style.width = vncwidth + 'px'; $D('noVNC-control-bar').style.width = vncwidth + 'px';
} },
//Helper to add options to dropdown. connectPanelbutton: function() {
function addOption(selectbox,text,value ) //Close connection settings if open
{ if(UI.settingsOpen == true) {
var optn = document.createElement("OPTION"); UI.closeSettingsMenu();
optn.text = text; }
optn.value = value; if(UI.clipboardOpen == true)
selectbox.options.add(optn); {
UI.showClipboard();
}
//Toggle Connection Panel
if(UI.connSettingsOpen == true)
{
$D('noVNC_controls').style.display = "none";
UI.connSettingsOpen = false;
} else {
$D('noVNC_controls').style.display = "block";
UI.connSettingsOpen = true;
$D('noVNC_host').focus();
}
} }
};
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
<!-- Stylesheets --> <!-- Stylesheets -->
<link rel="stylesheet" href="include/base.css" /> <link rel="stylesheet" href="include/base.css" />
<link rel="alternate stylesheet" href="include/black.css" TITLE="Black" /> <link rel="alternate stylesheet" href="include/black.css" TITLE="Black" />
<link rel="alternate stylesheet" href="include/blue.css" TITLE="Blue" />
<!-- Google web fonts --> <!-- Google web fonts -->
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz|Nova+Square|Orbitron:400,500,700,900|Nova+Round|Nova+Mono|Nova+Slim|Nova+Oval|Nova+Flat|Nova+Cut' rel='stylesheet' type='text/css'> <link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz|Nova+Square|Orbitron:400,500,700,900|Nova+Round|Nova+Mono|Nova+Slim|Nova+Oval|Nova+Flat|Nova+Cut' rel='stylesheet' type='text/css'>
...@@ -58,17 +59,17 @@ ...@@ -58,17 +59,17 @@
<input type="button" class="noVNC_status_button" id="noVNC_mouse_button1" value="L" onclick="UI.setMouseButton(1);"> <input type="button" class="noVNC_status_button" id="noVNC_mouse_button1" value="L" onclick="UI.setMouseButton(1);">
<input type="button" class="noVNC_status_button" id="noVNC_mouse_button2" value="M" onclick="UI.setMouseButton(2);"> <input type="button" class="noVNC_status_button" id="noVNC_mouse_button2" value="M" onclick="UI.setMouseButton(2);">
<input type="button" class="noVNC_status_button" id="noVNC_mouse_button4" value="R" onclick="UI.setMouseButton(4);"> <input type="button" class="noVNC_status_button" id="noVNC_mouse_button4" value="R" onclick="UI.setMouseButton(4);">
<input type="button" class="noVNC_status_button" value="CtrlAltDel" id="sendCtrlAltDelButton" onclick="UI.sendCtrlAltDel();"> <input type="button" id="showKeyboard" onclick="UI.showKeyboard()" value="Keyboard" class="noVNC_status_button"/>
<input type="button" id="showKeyboard" onclick="showkeyboard()" value="Keyboard" class="noVNC_status_button"/>
</span> </span>
</nobr> </nobr>
</div> </div>
<!--noVNC Buttons--> <!--noVNC Buttons-->
<div class="noVNC_mobile_buttons_right"> <div class="noVNC_mobile_buttons_right">
<input type="button" class="noVNC_status_button" style="float:left;" value="CtrlAltDel" id="sendCtrlAltDelButton" onclick="UI.sendCtrlAltDel();">
<input type="button" id="clipboardbutton" onclick="UI.showClipboard();" value="Clipboard" /> <input type="button" id="clipboardbutton" onclick="UI.showClipboard();" value="Clipboard" />
<input type="button" class="VNC_status_button" value="Settings" id="menuButton" onclick="UI.clickSettingsMenu();"> <input type="button" class="VNC_status_button" value="Settings" id="menuButton" onclick="UI.clickSettingsMenu();">
<input type="button" id="connectPanelbutton" class="VNC_status_button" onclick="connectPanelbutton()" value="Connection" /> <input type="button" id="connectPanelbutton" class="VNC_status_button" style="width:100px;" onclick="UI.connectPanelbutton()" value="Connection" />
</div> </div>
<!-- Clipboard Panel --> <!-- Clipboard Panel -->
...@@ -113,7 +114,7 @@ ...@@ -113,7 +114,7 @@
<li><label><strong>Host: </strong><input id="noVNC_host" /></label></li> <li><label><strong>Host: </strong><input id="noVNC_host" /></label></li>
<li><label><strong>Port: </strong><input id="noVNC_port" /></label></li> <li><label><strong>Port: </strong><input id="noVNC_port" /></label></li>
<li><label><strong>Password: </strong><input id="noVNC_password" type="password" /></label></li> <li><label><strong>Password: </strong><input id="noVNC_password" type="password" /></label></li>
<li><input id="noVNC_connect_button" type="button" value="Loading" disabled></li> <li><input id="noVNC_connect_button" type="button" value="Connect" onclick="UI.connect();"></li>
</ul> </ul>
</div> </div>
...@@ -130,7 +131,7 @@ ...@@ -130,7 +131,7 @@
Canvas not supported. Canvas not supported.
</canvas> </canvas>
<input id="keyboardinput" style="width:0px;height:0px;background-color:#313131;" type="text" onKeyDown="onKeyDown(event);"/> <input id="keyboardinput" type="text" onKeyDown="onKeyDown(event);"/>
</div> </div>
<script> <script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment