2010-06-15 17:10:18 +01:00
|
|
|
/*
|
2010-06-15 21:21:41 +01:00
|
|
|
* noVNC: HTML5 VNC client
|
|
|
|
* Copyright (C) 2010 Joel Martin
|
2010-09-08 21:06:34 +01:00
|
|
|
* Licensed under LGPL-3 (see LICENSE.txt)
|
2010-06-15 21:21:41 +01:00
|
|
|
*
|
|
|
|
* See README.md for usage and integration instructions.
|
2010-06-15 17:10:18 +01:00
|
|
|
*/
|
|
|
|
|
2010-06-15 21:21:41 +01:00
|
|
|
"use strict";
|
|
|
|
/*jslint bitwise: false, white: false */
|
2010-07-22 16:54:47 +01:00
|
|
|
/*global window, console, document, navigator, ActiveXObject*/
|
2010-06-15 17:10:18 +01:00
|
|
|
|
2010-06-15 21:21:41 +01:00
|
|
|
// Globals defined here
|
|
|
|
var Util = {}, $;
|
|
|
|
|
2010-07-06 17:56:13 +01:00
|
|
|
|
2010-07-22 02:34:23 +01:00
|
|
|
/*
|
|
|
|
* Simple DOM selector by ID
|
|
|
|
*/
|
2010-06-15 21:21:41 +01:00
|
|
|
if (!window.$) {
|
|
|
|
$ = function (id) {
|
|
|
|
if (document.getElementById) {
|
|
|
|
return document.getElementById(id);
|
|
|
|
} else if (document.all) {
|
|
|
|
return document.all[id];
|
|
|
|
} else if (document.layers) {
|
|
|
|
return document.layers[id];
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
}
|
2010-05-15 20:55:33 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Make arrays quack
|
|
|
|
*/
|
|
|
|
|
|
|
|
Array.prototype.push8 = function (num) {
|
|
|
|
this.push(num & 0xFF);
|
|
|
|
};
|
|
|
|
|
|
|
|
Array.prototype.push16 = function (num) {
|
|
|
|
this.push((num >> 8) & 0xFF,
|
|
|
|
(num ) & 0xFF );
|
|
|
|
};
|
|
|
|
Array.prototype.push32 = function (num) {
|
|
|
|
this.push((num >> 24) & 0xFF,
|
|
|
|
(num >> 16) & 0xFF,
|
|
|
|
(num >> 8) & 0xFF,
|
|
|
|
(num ) & 0xFF );
|
|
|
|
};
|
|
|
|
|
2010-06-15 21:21:41 +01:00
|
|
|
/*
|
|
|
|
* ------------------------------------------------------
|
|
|
|
* Namespaced in Util
|
|
|
|
* ------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
/*
|
|
|
|
* Logging/debug routines
|
|
|
|
*/
|
|
|
|
|
2010-09-22 23:11:57 +01:00
|
|
|
Util._log_level = 'warn';
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
Util.init_logging = function (level) {
|
2010-09-22 23:11:57 +01:00
|
|
|
if (typeof level === 'undefined') {
|
|
|
|
Util._log_level = (document.location.href.match(
|
|
|
|
/logging=([A-Za-z0-9\._\-]*)/) ||
|
|
|
|
['', Util._log_level])[1];
|
|
|
|
level = Util._log_level;
|
|
|
|
} else {
|
|
|
|
Util._log_level = level;
|
|
|
|
}
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
if (typeof window.console === "undefined") {
|
|
|
|
if (typeof window.opera !== "undefined") {
|
|
|
|
window.console = {
|
|
|
|
'log' : window.opera.postError,
|
|
|
|
'warn' : window.opera.postError,
|
|
|
|
'error': window.opera.postError };
|
|
|
|
} else {
|
|
|
|
window.console = {
|
|
|
|
'log' : function(m) {},
|
|
|
|
'warn' : function(m) {},
|
|
|
|
'error': function(m) {}};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
|
|
|
|
switch (level) {
|
|
|
|
case 'debug': Util.Debug = function (msg) { console.log(msg); };
|
|
|
|
case 'info': Util.Info = function (msg) { console.log(msg); };
|
|
|
|
case 'warn': Util.Warn = function (msg) { console.warn(msg); };
|
|
|
|
case 'error': Util.Error = function (msg) { console.error(msg); };
|
|
|
|
case 'none':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw("invalid logging type '" + level + "'");
|
|
|
|
}
|
|
|
|
};
|
2010-09-22 23:11:57 +01:00
|
|
|
Util.get_logging = function () {
|
|
|
|
return Util._log_level;
|
|
|
|
}
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
// Initialize logging level
|
2010-09-22 23:11:57 +01:00
|
|
|
Util.init_logging();
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
|
2010-06-15 21:21:41 +01:00
|
|
|
Util.dirObj = function (obj, depth, parent) {
|
|
|
|
var i, msg = "", val = "";
|
|
|
|
if (! depth) { depth=2; }
|
|
|
|
if (! parent) { parent= ""; }
|
|
|
|
|
|
|
|
// Print the properties of the passed-in object
|
|
|
|
for (i in obj) {
|
|
|
|
if ((depth > 1) && (typeof obj[i] === "object")) {
|
|
|
|
// Recurse attributes that are objects
|
|
|
|
msg += Util.dirObj(obj[i], depth-1, parent + "." + i);
|
|
|
|
} else {
|
|
|
|
//val = new String(obj[i]).replace("\n", " ");
|
|
|
|
val = obj[i].toString().replace("\n", " ");
|
|
|
|
if (val.length > 30) {
|
|
|
|
val = val.substr(0,30) + "...";
|
|
|
|
}
|
|
|
|
msg += parent + "." + i + ": " + val + "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return msg;
|
|
|
|
};
|
|
|
|
|
2010-07-22 17:33:21 +01:00
|
|
|
// Read a query string variable
|
|
|
|
Util.getQueryVar = function(name, defVal) {
|
|
|
|
var re = new RegExp('[?][^#]*' + name + '=([^&#]*)');
|
|
|
|
if (typeof defVal === 'undefined') { defVal = null; }
|
|
|
|
return (document.location.href.match(re) || ['',defVal])[1];
|
|
|
|
};
|
|
|
|
|
2010-07-30 15:53:33 +01:00
|
|
|
// Set defaults for Crockford style function namespaces
|
2010-09-23 15:39:24 +01:00
|
|
|
Util.conf_default = function(cfg, api, v, type, defval, desc) {
|
|
|
|
// Description
|
|
|
|
api['get_' + v + '_desc'] = desc;
|
2010-07-30 15:53:33 +01:00
|
|
|
// Default getter
|
|
|
|
if (typeof api['get_' + v] === 'undefined') {
|
|
|
|
api['get_' + v] = function () {
|
|
|
|
return cfg[v];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Default setter
|
|
|
|
if (typeof api['set_' + v] === 'undefined') {
|
|
|
|
api['set_' + v] = function (val) {
|
2010-09-23 15:39:24 +01:00
|
|
|
if (type in {'boolean':1, 'bool':1}) {
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
|
|
|
|
val = false;
|
|
|
|
} else {
|
|
|
|
val = true;
|
|
|
|
}
|
2010-09-23 15:39:24 +01:00
|
|
|
} else if (type in {'integer':1, 'int':1}) {
|
|
|
|
val = parseInt(val, 10);
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
}
|
2010-07-30 15:53:33 +01:00
|
|
|
cfg[v] = val;
|
|
|
|
};
|
|
|
|
}
|
2010-09-23 15:39:24 +01:00
|
|
|
|
|
|
|
if (typeof cfg[v] === 'undefined') {
|
|
|
|
// Set to default
|
|
|
|
api['set_' + v](defval);
|
|
|
|
} else {
|
|
|
|
// Coerce existing setting to the right type
|
|
|
|
api['set_' + v](cfg[v]);
|
|
|
|
}
|
2010-07-30 15:53:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-07-22 17:33:21 +01:00
|
|
|
|
2010-06-15 21:21:41 +01:00
|
|
|
/*
|
|
|
|
* Cross-browser routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Get DOM element position on page
|
|
|
|
Util.getPosition = function (obj) {
|
|
|
|
var x = 0, y = 0;
|
|
|
|
if (obj.offsetParent) {
|
|
|
|
do {
|
|
|
|
x += obj.offsetLeft;
|
|
|
|
y += obj.offsetTop;
|
|
|
|
obj = obj.offsetParent;
|
|
|
|
} while (obj);
|
|
|
|
}
|
|
|
|
return {'x': x, 'y': y};
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get mouse event position in DOM element
|
2010-07-30 15:53:33 +01:00
|
|
|
Util.getEventPosition = function (e, obj, scale) {
|
2010-06-15 21:21:41 +01:00
|
|
|
var evt, docX, docY, pos;
|
|
|
|
//if (!e) evt = window.event;
|
|
|
|
evt = (e ? e : window.event);
|
|
|
|
if (evt.pageX || evt.pageY) {
|
|
|
|
docX = evt.pageX;
|
|
|
|
docY = evt.pageY;
|
|
|
|
} else if (evt.clientX || evt.clientY) {
|
|
|
|
docX = evt.clientX + document.body.scrollLeft +
|
|
|
|
document.documentElement.scrollLeft;
|
|
|
|
docY = evt.clientY + document.body.scrollTop +
|
|
|
|
document.documentElement.scrollTop;
|
|
|
|
}
|
|
|
|
pos = Util.getPosition(obj);
|
2010-07-30 15:53:33 +01:00
|
|
|
if (typeof scale === "undefined") {
|
|
|
|
scale = 1;
|
|
|
|
}
|
|
|
|
return {'x': (docX - pos.x) / scale, 'y': (docY - pos.y) / scale};
|
2010-06-15 21:21:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Event registration. Based on: http://www.scottandrew.com/weblog/articles/cbs-events
|
|
|
|
Util.addEvent = function (obj, evType, fn){
|
2010-06-23 22:08:36 +01:00
|
|
|
if (obj.attachEvent){
|
2010-06-15 21:21:41 +01:00
|
|
|
var r = obj.attachEvent("on"+evType, fn);
|
|
|
|
return r;
|
2010-06-23 22:08:36 +01:00
|
|
|
} else if (obj.addEventListener){
|
|
|
|
obj.addEventListener(evType, fn, false);
|
|
|
|
return true;
|
2010-06-15 21:21:41 +01:00
|
|
|
} else {
|
|
|
|
throw("Handler could not be attached");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Util.removeEvent = function(obj, evType, fn){
|
2010-06-23 22:08:36 +01:00
|
|
|
if (obj.detachEvent){
|
2010-06-15 21:21:41 +01:00
|
|
|
var r = obj.detachEvent("on"+evType, fn);
|
|
|
|
return r;
|
2010-06-23 22:08:36 +01:00
|
|
|
} else if (obj.removeEventListener){
|
|
|
|
obj.removeEventListener(evType, fn, false);
|
|
|
|
return true;
|
2010-06-15 21:21:41 +01:00
|
|
|
} else {
|
|
|
|
throw("Handler could not be removed");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Util.stopEvent = function(e) {
|
|
|
|
if (e.stopPropagation) { e.stopPropagation(); }
|
|
|
|
else { e.cancelBubble = true; }
|
|
|
|
|
|
|
|
if (e.preventDefault) { e.preventDefault(); }
|
|
|
|
else { e.returnValue = false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Set browser engine versions. Based on mootools.
|
|
|
|
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
|
|
|
|
|
|
|
Util.Engine = {
|
|
|
|
'presto': (function() {
|
|
|
|
return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
|
|
|
'trident': (function() {
|
|
|
|
return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); }()),
|
|
|
|
'webkit': (function() {
|
2010-06-21 22:30:32 +01:00
|
|
|
try { return (navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); } catch (e) { return false; } }()),
|
|
|
|
//'webkit': (function() {
|
|
|
|
// return ((typeof navigator.taintEnabled !== "unknown") && navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); }()),
|
2010-06-15 21:21:41 +01:00
|
|
|
'gecko': (function() {
|
2010-09-23 14:08:08 +01:00
|
|
|
return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18); }())
|
2010-06-15 21:21:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Util.Flash = (function(){
|
|
|
|
var v, version;
|
|
|
|
try {
|
|
|
|
v = navigator.plugins['Shockwave Flash'].description;
|
|
|
|
} catch(err1) {
|
|
|
|
try {
|
|
|
|
v = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
|
|
|
|
} catch(err2) {
|
|
|
|
v = '0 r0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
version = v.match(/\d+/g);
|
|
|
|
return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
|
|
|
|
}());
|
|
|
|
|
2010-07-22 02:34:23 +01:00
|
|
|
/*
|
|
|
|
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
|
|
|
*/
|
2010-07-22 17:33:21 +01:00
|
|
|
|
2010-07-22 02:34:23 +01:00
|
|
|
// No days means only for this browser session
|
|
|
|
Util.createCookie = function(name,value,days) {
|
2010-07-22 16:54:47 +01:00
|
|
|
var date, expires;
|
2010-07-22 02:34:23 +01:00
|
|
|
if (days) {
|
2010-07-22 16:54:47 +01:00
|
|
|
date = new Date();
|
2010-07-22 02:34:23 +01:00
|
|
|
date.setTime(date.getTime()+(days*24*60*60*1000));
|
2010-07-22 16:54:47 +01:00
|
|
|
expires = "; expires="+date.toGMTString();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
expires = "";
|
2010-07-22 02:34:23 +01:00
|
|
|
}
|
|
|
|
document.cookie = name+"="+value+expires+"; path=/";
|
|
|
|
};
|
|
|
|
|
|
|
|
Util.readCookie = function(name, defaultValue) {
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
var i, c, nameEQ = name + "=", ca = document.cookie.split(';');
|
|
|
|
for(i=0; i < ca.length; i += 1) {
|
|
|
|
c = ca[i];
|
2010-07-22 16:54:47 +01:00
|
|
|
while (c.charAt(0) === ' ') { c = c.substring(1,c.length); }
|
|
|
|
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
|
2010-07-22 02:34:23 +01:00
|
|
|
}
|
|
|
|
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
|
|
|
};
|
|
|
|
|
|
|
|
Util.eraseCookie = function(name) {
|
2010-07-22 16:54:47 +01:00
|
|
|
Util.createCookie(name,"",-1);
|
2010-07-22 02:34:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Alternate stylesheet selection
|
|
|
|
*/
|
|
|
|
Util.getStylesheets = function() { var i, links, sheets = [];
|
2010-07-22 16:54:47 +01:00
|
|
|
links = document.getElementsByTagName("link");
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
for (i = 0; i < links.length; i += 1) {
|
2010-07-22 02:34:23 +01:00
|
|
|
if (links[i].title &&
|
|
|
|
links[i].rel.toUpperCase().indexOf("STYLESHEET") > -1) {
|
|
|
|
sheets.push(links[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sheets;
|
|
|
|
};
|
|
|
|
|
|
|
|
// No sheet means try and use value from cookie, null sheet used to
|
|
|
|
// clear all alternates.
|
|
|
|
Util.selectStylesheet = function(sheet) {
|
|
|
|
var i, link, sheets = Util.getStylesheets();
|
|
|
|
if (typeof sheet === 'undefined') {
|
|
|
|
sheet = 'default';
|
|
|
|
}
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
for (i=0; i < sheets.length; i += 1) {
|
2010-07-22 02:34:23 +01:00
|
|
|
link = sheets[i];
|
|
|
|
if (link.title === sheet) {
|
|
|
|
Util.Debug("Using stylesheet " + sheet);
|
|
|
|
link.disabled = false;
|
|
|
|
} else {
|
New API. Refactor Canvas and RFB objects.
New API:
To use the RFB object, you now must instantiate it (this allows more
than one instance of it on the same page).
rfb = new RFB(settings);
The 'settings' variable is a namespace that contains initial default
settings. These can also be set and read using 'rfb.set_FOO()' and
'rfb.get_FOO()' where FOO is the setting name. The current settings
are (and defaults) are:
- target: the DOM Canvas element to use ('VNC_canvas').
- encrypt: whether to encrypt the connection (false)
- true_color: true_color or palette (true)
- b64encode: base64 encode the WebSockets data (true)
- local_cursor: use local cursor rendering (true if supported)
- connectTimeout: milliseconds to wait for connect (2000)
- updateState: callback when RFB state changes (none)
- clipboardReceive: callback when clipboard data received (none)
The parameters to the updateState callback have also changed. The
function spec is now updateState(rfb, state, oldstate, msg):
- rfb: the RFB object that this state change is for.
- state: the new state
- oldstate: the previous state
- msg: a message associate with the state (not always set).
The clipboardReceive spec is clipboardReceive(rfb, text):
- rfb: the RFB object that this text is from.
- text: the clipboard text received.
Changes:
- The RFB and Canvas namespaces are now more proper objects. Private
implementation is no longer exposed and the public API has been made
explicit. Also, instantiation allows more than one VNC connection
on the same page (to complete this, DefaultControls will also need
this same refactoring).
- Added 'none' logging level.
- Removed automatic stylesheet selection workaround in util.js and
move it to defaultcontrols so that it doesn't interfere with
intergration.
- Also, some major JSLinting.
- Fix input, canvas, and cursor tests to work with new model.
2010-08-02 23:07:27 +01:00
|
|
|
//Util.Debug("Skipping stylesheet " + link.title);
|
2010-07-22 02:34:23 +01:00
|
|
|
link.disabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sheet;
|
|
|
|
};
|