DefaultControls = {
load: function(target) {
var url;
/* Handle state updates */
RFB.setUpdateState(DefaultControls.updateState);
RFB.setClipboardReceive(DefaultControls.clipReceive);
/* Populate the 'target' DOM element with default controls */
if (!target) { target = 'vnc'; }
html = "";
html += '
';
html += '
';
html += '
Host:
';
html += '
Port:
';
html += '
Password:
';
html += '
Encrypt:
';
html += '
True Color:
';
html += ' ';
html += '
';
html += '
';
html += '
';
html += '
Loading
';
html += ' ';
html += '
';
html += '
';
html += '
';
html += ' VNC Clipboard:';
html += ' ';
html += ' ';
html += ' ';
html += '
';
$(target).innerHTML = html;
/* Populate the controls if defaults are provided in the URL */
url = document.location.href;
$('VNC_host').value = (url.match(/host=([A-Za-z0-9.\-]*)/) ||
['',''])[1];
$('VNC_port').value = (url.match(/port=([0-9]*)/) ||
['',''])[1];
$('VNC_password').value = (url.match(/password=([^]*)/) ||
['',''])[1];
$('VNC_encrypt').checked = (url.match(/encrypt=([A-Za-z0-9]*)/) ||
['',''])[1];
},
updateState: function(state, msg) {
var s, c, klass;
s = $('VNC_status');
c = $('VNC_connect_button');
switch (state) {
case 'failed':
c.disabled = true;
klass = "VNC_status_error";
break;
case 'normal':
c.value = "Disconnect";
c.onclick = DefaultControls.disconnect;
c.disabled = false;
klass = "VNC_status_normal";
break;
case 'disconnected':
c.value = "Connect";
c.onclick = DefaultControls.connect;
c.disabled = false;
klass = "VNC_status_normal";
break;
default:
c.disabled = true;
klass = "VNC_status_warn";
break;
}
if (typeof(msg) !== 'undefined') {
s.setAttribute("class", klass);
s.innerHTML = msg;
}
},
connect: function() {
var host, port, password, encrypt, true_color;
host = $('VNC_host').value;
port = $('VNC_port').value;
password = $('VNC_password').value;
encrypt = $('VNC_encrypt').checked;
true_color = $('VNC_true_color').checked;
if ((!host) || (!port)) {
alert("Must set host and port");
return;
}
RFB.connect(host, port, password, encrypt, true_color);
},
disconnect: function() {
RFB.disconnect();
},
clipFocus: function() {
RFB.clipboardFocus = true;
},
clipBlur: function() {
RFB.clipboardFocus = false;
},
clipClear: function() {
$('VNC_clipboard_text').value = "";
RFB.clipboardPasteFrom("");
},
clipReceive: function(text) {
console.log(">> DefaultControls.clipReceive: " + text.substr(0,40) + "...");
$('VNC_clipboard_text').value = text;
console.log("<< DefaultControls.clipReceive");
},
clipSend: function() {
var text = $('VNC_clipboard_text').value;
console.log(">> DefaultControls.clipSend: " + text.substr(0,40) + "...");
RFB.clipboardPasteFrom(text);
console.log("<< DefaultControls.clipSend");
}
}