2 * Copyright (C) 2010 Oregon State University et al.
4 * Javascript for custom noVNC interface.
12 var popout
= $('#popout');
13 var connect
= $('#connect');
14 var encrypt
= $('#encrypt');
15 var encrypt_check
= $('#encrypt_check');
16 var ctrlaltdelete
= $('#ctrlaltdelete');
17 var vnc_errors
= $("#vnc_errors");
18 var vnc_status_bar
= $("#VNC_status_bar");
19 var vnc_canvas
= $('#VNC_canvas');
20 var vnc_screen
= $('#VNC_screen');
22 // XXX remap document.write to a dom function so that it works after DOM is
23 // loaded function will be reset after noVNC scripts are loaded.
24 var old
= document
.write
;
25 document
.write = function(str
) {$(document
).append(str
)};
26 document
.write('<script type="text/javascript" src="'+INCLUDE_URI
+'vnc.js"><//script>');
29 // XXX manually call __initialize(). This normally happens onload, but
30 // won't work for us since document may have been loaded already
31 if (!Websock_native
) {WebSocket
.__initialize();}
34 var host
, port
, password
; // VNC proxy connection settings
35 var connected
= false;
37 // When the VNC Canvas is resized, this is called and resizes
38 // the window if it's a popup
39 function resize_popup() {
40 // Height will be VNC_canvas + a little bit
41 var cHeight
= vnc_canvas
.height();
42 // Width will be VNC_canvas + a little bit
43 var cWidth
= vnc_canvas
.width();
45 // Without this next line, the status hangs off to the right
46 // of the buttons. That looks really bad.
47 vnc_status_bar
.width(cWidth
);
50 vnc_screen
.width(cWidth
);
51 window
.resizeTo(cWidth
+ 50, cHeight
+ 100);
54 connect
.click(function(event
) {
55 event
.preventDefault();
57 if($this.hasClass('enabled')) {
65 // When connecting, change the window size to have
66 // the canvas fully viewable
70 encrypt
.click(function(event
){
71 event
.preventDefault();
74 if ($this.hasClass('enabled')){
75 encrypt_check
.attr('checked',false);
76 $this.removeClass('enabled')
78 encrypt_check
.attr('checked',true);
79 $this.addClass('enabled')
85 .click(function(event
){
86 event
.preventDefault();
87 if (!$(this).hasClass('disabled')) {
92 if (POPOUT_URL
!= undefined) {
93 popout
.click(function(event
) {
94 event
.preventDefault();
96 if (rfb
== undefined) {
99 url
= POPOUT_URL
+ '?auto_connect=1';
102 window
.open(url
, 'popout', 'height=550,width=775,status=no,toolbar=no,menubar=no,location=no');
106 // users exits the page by following link or closing the tab or sth else
107 $(window
).bind("unload", stop
);
110 function show_errors() {
111 if (host
===false || port
===false || password
===false) {
114 .attr("class", "VNC_status_error")
115 .html("Probably your proxy is not running or some errors occured. Try again.");
121 function updateState(rfb
, state
, oldstate
, msg
) {
126 klass
= "VNC_status_error";
129 klass
= "VNC_status_normal";
133 klass
= "VNC_status_normal";
136 msg
= 'Password required';
137 klass
= "VNC_status_warn";
140 klass
= "VNC_status_warn";
143 if (state
== "normal") {
148 ctrlaltdelete
.removeClass('disabled');
149 vnc_canvas
.addClass("connected");
151 vnc_canvas
.removeClass("connected");
154 .removeClass('enabled')
156 ctrlaltdelete
.addClass('disabled')
159 if (msg
!= undefined) {
161 .attr("class", klass
)
167 if (rfb
!= undefined) {
176 if (encrypt_check
.attr('checked')) {
178 data
= {"tls": true};
180 is_encrypted
= false;
186 "url": PROXY_REQUEST_URI
,
190 "success": function(data
){
196 if (!show_errors()) return false;
199 // jQuery doesn't work with that, need to stick
201 'target': document
.getElementById('VNC_canvas'),
202 'encrypt': is_encrypted
,
204 'local_cursor': true,
206 'updateState': updateState
208 rfb
.connect(host
, port
, password
);