]> git.proxmox.com Git - mirror_novnc.git/blob - include/default_controls.js
Disabled ctrlAltDel button when N/A.
[mirror_novnc.git] / include / default_controls.js
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";
9 /*global console, $, RFB, Canvas, VNC_uri_prefix, Element, Fx */
10
11 // Load mootools
12 (function () {
13 var pre = (typeof VNC_uri_prefix !== "undefined") ?
14 VNC_uri_prefix : "include/";
15 document.write("<script src='" + pre + "mootools.js'><\/script>");
16 }());
17
18
19 var DefaultControls = {
20
21 load: function(target) {
22 var url, html;
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">';
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 += ' id="sendCtrlAltDelButton"';
53 html += ' onclick="DefaultControls.sendCtrlAltDel();"></div></td>';
54 html += ' </tr></table>';
55 html += ' </div>';
56 html += ' <canvas id="VNC_canvas" width="640px" height="20px">';
57 html += ' Canvas not supported.';
58 html += ' </canvas>';
59 html += '</div>';
60 html += '<br><br>';
61 html += '<div id="VNC_clipboard">';
62 html += ' VNC Clipboard:';
63 html += ' <input id="VNC_clipboard_clear_button"';
64 html += ' type="button" value="Clear"';
65 html += ' onclick="DefaultControls.clipClear();">';
66 html += ' <br>';
67 html += ' <textarea id="VNC_clipboard_text" cols=80 rows=5';
68 html += ' onfocus="DefaultControls.clipFocus();"';
69 html += ' onblur="DefaultControls.clipBlur();"';
70 html += ' onchange="DefaultControls.clipSend();"></textarea>';
71 html += '</div>';
72 $(target).innerHTML = html;
73
74 /* Populate the controls if defaults are provided in the URL */
75 url = document.location.href;
76 $('VNC_host').value = (url.match(/host=([A-Za-z0-9.\-]*)/) ||
77 ['',''])[1];
78 $('VNC_port').value = (url.match(/port=([0-9]*)/) ||
79 ['',''])[1];
80 $('VNC_password').value = (url.match(/password=([^&#]*)/) ||
81 ['',''])[1];
82 $('VNC_encrypt').checked = (url.match(/encrypt=([A-Za-z0-9]*)/) ||
83 ['',''])[1];
84
85 $('VNC_screen').onmousemove = function () {
86 // Unfocus clipboard when over the VNC area
87 if (! Canvas.focused) {
88 $('VNC_clipboard_text').blur();
89 }
90 };
91 },
92
93 sendCtrlAltDel: function() {
94 RFB.sendCtrlAltDel();
95 },
96
97 updateState: function(state, msg) {
98 var s, c, klass;
99 s = $('VNC_status');
100 sb = $('VNC_status_bar');
101 c = $('VNC_connect_button');
102 cad = $('sendCtrlAltDelButton');
103 switch (state) {
104 case 'failed':
105 c.disabled = true;
106 cad.disabled = true;
107 klass = "VNC_status_error";
108 break;
109 case 'normal':
110 c.value = "Disconnect";
111 c.onclick = DefaultControls.disconnect;
112 c.disabled = false;
113 cad.disabled = false;
114 klass = "VNC_status_normal";
115 break;
116 case 'disconnected':
117 c.value = "Connect";
118 c.onclick = DefaultControls.connect;
119
120 c.disabled = false;
121 cad.disabled = true;
122 klass = "VNC_status_normal";
123 break;
124 default:
125 c.disabled = true;
126 cad.disabled = true;
127 klass = "VNC_status_warn";
128 break;
129 }
130
131 if (typeof(msg) !== 'undefined') {
132 s.setAttribute("class", klass);
133 sb.setAttribute("class", klass);
134 s.innerHTML = msg;
135 }
136
137 },
138
139 connect: function() {
140 var host, port, password, encrypt, true_color;
141 host = $('VNC_host').value;
142 port = $('VNC_port').value;
143 password = $('VNC_password').value;
144 encrypt = $('VNC_encrypt').checked;
145 true_color = $('VNC_true_color').checked;
146 if ((!host) || (!port)) {
147 throw("Must set host and port");
148 }
149
150 RFB.connect(host, port, password, encrypt, true_color);
151 },
152
153 disconnect: function() {
154 RFB.disconnect();
155 },
156
157 clipFocus: function() {
158 Canvas.focused = false;
159 },
160
161 clipBlur: function() {
162 Canvas.focused = true;
163 },
164
165 clipClear: function() {
166 $('VNC_clipboard_text').value = "";
167 RFB.clipboardPasteFrom("");
168 },
169
170 clipReceive: function(text) {
171 console.log(">> DefaultControls.clipReceive: " + text.substr(0,40) + "...");
172 $('VNC_clipboard_text').value = text;
173 console.log("<< DefaultControls.clipReceive");
174 },
175
176 clipSend: function() {
177 var text = $('VNC_clipboard_text').value;
178 console.log(">> DefaultControls.clipSend: " + text.substr(0,40) + "...");
179 RFB.clipboardPasteFrom(text);
180 console.log("<< DefaultControls.clipSend");
181 }
182
183 };