]> git.proxmox.com Git - mirror_novnc.git/blame - include/default_controls.js
Add CtrlAltDel send button to status bar.
[mirror_novnc.git] / include / default_controls.js
CommitLineData
15046f00
JM
1/*
2 * noVNC: HTML5 VNC client
3 * Copyright (C) 2010 Joel Martin
4 * Licensed under LGPL-3 (see LICENSE.LGPL-3)
5 *
6 * See README.md for usage and integration instructions.
7 */
8"use strict";
63708ff5 9/*global console, $, RFB, Canvas, VNC_uri_prefix, Element, Fx */
15046f00
JM
10
11// Load mootools
12(function () {
63708ff5 13 var pre = (typeof VNC_uri_prefix !== "undefined") ?
15046f00 14 VNC_uri_prefix : "include/";
63708ff5 15 document.write("<script src='" + pre + "mootools.js'><\/script>");
15046f00
JM
16}());
17
18
63708ff5 19var DefaultControls = {
91308399
JM
20
21load: function(target) {
63708ff5 22 var url, html;
91308399
JM
23
24 /* Handle state updates */
25 RFB.setUpdateState(DefaultControls.updateState);
26 RFB.setClipboardReceive(DefaultControls.clipReceive);
27
28 /* Populate the 'target' DOM element with default controls */
29 if (!target) { target = 'vnc'; }
30
31 html = "";
32 html += '<div id="VNC_controls">';
33 html += ' <ul>';
34 html += ' <li>Host: <input id="VNC_host"></li>';
35 html += ' <li>Port: <input id="VNC_port"></li>';
36 html += ' <li>Password: <input id="VNC_password"';
37 html += ' type="password"></li>';
38 html += ' <li>Encrypt: <input id="VNC_encrypt"';
39 html += ' type="checkbox"></li>';
40 html += ' <li>True Color: <input id="VNC_true_color"';
41 html += ' type="checkbox" checked></li>';
42 html += ' <li><input id="VNC_connect_button" type="button"';
43 html += ' value="Loading" disabled></li>';
44 html += ' </ul>';
45 html += '</div>';
46 html += '<div id="VNC_screen">';
63708ff5
JM
47 html += ' <div id="VNC_status_bar" class="VNC_status_bar" style="margin-top: 0px;">';
48 html += ' <table border=0 width=100%><tr>';
49 html += ' <td><div id="VNC_status">Loading</div></td>';
50 html += ' <td width=10%><div id="VNC_buttons">';
51 html += ' <input type=button value="Send CtrlAltDel"';
52 html += ' onclick="DefaultControls.sendCtrlAltDel();"></div></td>';
53 html += ' </tr></table>';
54 html += ' </div>';
91308399
JM
55 html += ' <canvas id="VNC_canvas" width="640px" height="20px">';
56 html += ' Canvas not supported.';
57 html += ' </canvas>';
58 html += '</div>';
59 html += '<br><br>';
60 html += '<div id="VNC_clipboard">';
61 html += ' VNC Clipboard:';
62 html += ' <input id="VNC_clipboard_clear_button"';
63 html += ' type="button" value="Clear"';
64 html += ' onclick="DefaultControls.clipClear();">';
65 html += ' <br>';
66 html += ' <textarea id="VNC_clipboard_text" cols=80 rows=5';
67 html += ' onfocus="DefaultControls.clipFocus();"';
68 html += ' onblur="DefaultControls.clipBlur();"';
69 html += ' onchange="DefaultControls.clipSend();"></textarea>';
70 html += '</div>';
71 $(target).innerHTML = html;
72
73 /* Populate the controls if defaults are provided in the URL */
74 url = document.location.href;
75 $('VNC_host').value = (url.match(/host=([A-Za-z0-9.\-]*)/) ||
76 ['',''])[1];
77 $('VNC_port').value = (url.match(/port=([0-9]*)/) ||
78 ['',''])[1];
79 $('VNC_password').value = (url.match(/password=([^&#]*)/) ||
80 ['',''])[1];
81 $('VNC_encrypt').checked = (url.match(/encrypt=([A-Za-z0-9]*)/) ||
82 ['',''])[1];
3954ae14
JM
83
84 $('VNC_screen').onmousemove = function () {
85 // Unfocus clipboard when over the VNC area
15046f00 86 if (! Canvas.focused) {
3954ae14
JM
87 $('VNC_clipboard_text').blur();
88 }
89 };
91308399
JM
90},
91
63708ff5
JM
92sendCtrlAltDel: function() {
93 RFB.sendCtrlAltDel();
94},
95
91308399
JM
96updateState: function(state, msg) {
97 var s, c, klass;
98 s = $('VNC_status');
63708ff5 99 sb = $('VNC_status_bar');
91308399
JM
100 c = $('VNC_connect_button');
101 switch (state) {
102 case 'failed':
103 c.disabled = true;
104 klass = "VNC_status_error";
105 break;
106 case 'normal':
107 c.value = "Disconnect";
108 c.onclick = DefaultControls.disconnect;
109 c.disabled = false;
110 klass = "VNC_status_normal";
111 break;
112 case 'disconnected':
113 c.value = "Connect";
114 c.onclick = DefaultControls.connect;
115
116 c.disabled = false;
117 klass = "VNC_status_normal";
118 break;
119 default:
120 c.disabled = true;
121 klass = "VNC_status_warn";
122 break;
123 }
124
125 if (typeof(msg) !== 'undefined') {
126 s.setAttribute("class", klass);
63708ff5 127 sb.setAttribute("class", klass);
91308399
JM
128 s.innerHTML = msg;
129 }
130
131},
132
133connect: function() {
134 var host, port, password, encrypt, true_color;
135 host = $('VNC_host').value;
136 port = $('VNC_port').value;
137 password = $('VNC_password').value;
138 encrypt = $('VNC_encrypt').checked;
139 true_color = $('VNC_true_color').checked;
140 if ((!host) || (!port)) {
63708ff5 141 throw("Must set host and port");
91308399
JM
142 }
143
144 RFB.connect(host, port, password, encrypt, true_color);
145},
146
147disconnect: function() {
148 RFB.disconnect();
149},
150
151clipFocus: function() {
15046f00 152 Canvas.focused = false;
91308399
JM
153},
154
155clipBlur: function() {
15046f00 156 Canvas.focused = true;
91308399
JM
157},
158
159clipClear: function() {
160 $('VNC_clipboard_text').value = "";
161 RFB.clipboardPasteFrom("");
162},
163
164clipReceive: function(text) {
165 console.log(">> DefaultControls.clipReceive: " + text.substr(0,40) + "...");
166 $('VNC_clipboard_text').value = text;
167 console.log("<< DefaultControls.clipReceive");
168},
169
170clipSend: function() {
171 var text = $('VNC_clipboard_text').value;
172 console.log(">> DefaultControls.clipSend: " + text.substr(0,40) + "...");
173 RFB.clipboardPasteFrom(text);
174 console.log("<< DefaultControls.clipSend");
175}
176
63708ff5 177};