Pull include/util.js from noVNC. Add map to arrays for IE9.
IE9 still doesn't support [].map() so add it to the prototype in include/util.js.
This commit is contained in:
parent
b405cdae7b
commit
7d44853da7
120
include/util.js
120
include/util.js
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* from noVNC: HTML5 VNC client
|
* noVNC: HTML5 VNC client
|
||||||
* Copyright (C) 2010 Joel Martin
|
* Copyright (C) 2011 Joel Martin
|
||||||
* Licensed under LGPL-3 (see LICENSE.txt)
|
* Licensed under LGPL-3 (see LICENSE.txt)
|
||||||
*
|
*
|
||||||
* See README.md for usage and integration instructions.
|
* See README.md for usage and integration instructions.
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
/*global window, console, document, navigator, ActiveXObject */
|
/*global window, console, document, navigator, ActiveXObject */
|
||||||
|
|
||||||
// Globals defined here
|
// Globals defined here
|
||||||
var Util = {}, $D;
|
var Util = {};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -33,6 +33,30 @@ Array.prototype.push32 = function (num) {
|
||||||
(num ) & 0xFF );
|
(num ) & 0xFF );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// IE does not support map (even in IE9)
|
||||||
|
//This prototype is provided by the Mozilla foundation and
|
||||||
|
//is distributed under the MIT license.
|
||||||
|
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||||
|
if (!Array.prototype.map)
|
||||||
|
{
|
||||||
|
Array.prototype.map = function(fun /*, thisp*/)
|
||||||
|
{
|
||||||
|
var len = this.length;
|
||||||
|
if (typeof fun != "function")
|
||||||
|
throw new TypeError();
|
||||||
|
|
||||||
|
var res = new Array(len);
|
||||||
|
var thisp = arguments[1];
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (i in this)
|
||||||
|
res[i] = fun.call(thisp, this[i], i, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ------------------------------------------------------
|
* ------------------------------------------------------
|
||||||
* Namespaced in Util
|
* Namespaced in Util
|
||||||
|
|
@ -78,24 +102,27 @@ Util.init_logging = function (level) {
|
||||||
};
|
};
|
||||||
Util.get_logging = function () {
|
Util.get_logging = function () {
|
||||||
return Util._log_level;
|
return Util._log_level;
|
||||||
}
|
};
|
||||||
// Initialize logging level
|
// Initialize logging level
|
||||||
Util.init_logging();
|
Util.init_logging();
|
||||||
|
|
||||||
|
|
||||||
// Set defaults for Crockford style function namespaces
|
// Set configuration default for Crockford style function namespaces
|
||||||
Util.conf_default = function(cfg, api, v, type, defval, desc) {
|
Util.conf_default = function(cfg, api, defaults, v, mode, type, defval, desc) {
|
||||||
// Description
|
var getter, setter;
|
||||||
api['get_' + v + '_desc'] = desc;
|
|
||||||
// Default getter
|
// Default getter function
|
||||||
if (typeof api['get_' + v] === 'undefined') {
|
getter = function (idx) {
|
||||||
api['get_' + v] = function () {
|
if ((type in {'arr':1, 'array':1}) &&
|
||||||
|
(typeof idx !== 'undefined')) {
|
||||||
|
return cfg[v][idx];
|
||||||
|
} else {
|
||||||
return cfg[v];
|
return cfg[v];
|
||||||
};
|
|
||||||
}
|
}
|
||||||
// Default setter
|
};
|
||||||
if (typeof api['set_' + v] === 'undefined') {
|
|
||||||
api['set_' + v] = function (val) {
|
// Default setter function
|
||||||
|
setter = function (val, idx) {
|
||||||
if (type in {'boolean':1, 'bool':1}) {
|
if (type in {'boolean':1, 'bool':1}) {
|
||||||
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
|
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
|
||||||
val = false;
|
val = false;
|
||||||
|
|
@ -104,20 +131,59 @@ Util.conf_default = function(cfg, api, v, type, defval, desc) {
|
||||||
}
|
}
|
||||||
} else if (type in {'integer':1, 'int':1}) {
|
} else if (type in {'integer':1, 'int':1}) {
|
||||||
val = parseInt(val, 10);
|
val = parseInt(val, 10);
|
||||||
|
} else if (type === 'func') {
|
||||||
|
if (!val) {
|
||||||
|
val = function () {};
|
||||||
}
|
}
|
||||||
cfg[v] = val;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
if (typeof idx !== 'undefined') {
|
||||||
if (typeof cfg[v] === 'undefined') {
|
cfg[v][idx] = val;
|
||||||
// Set to default
|
|
||||||
api['set_' + v](defval);
|
|
||||||
} else {
|
} else {
|
||||||
// Coerce existing setting to the right type
|
cfg[v] = val;
|
||||||
api['set_' + v](cfg[v]);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set the description
|
||||||
|
api[v + '_description'] = desc;
|
||||||
|
|
||||||
|
// Set the getter function
|
||||||
|
if (typeof api['get_' + v] === 'undefined') {
|
||||||
|
api['get_' + v] = getter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the setter function with extra sanity checks
|
||||||
|
if (typeof api['set_' + v] === 'undefined') {
|
||||||
|
api['set_' + v] = function (val, idx) {
|
||||||
|
if (mode in {'RO':1, 'ro':1}) {
|
||||||
|
throw(v + " is read-only");
|
||||||
|
} else if ((mode in {'WO':1, 'wo':1}) &&
|
||||||
|
(typeof cfg[v] !== 'undefined')) {
|
||||||
|
throw(v + " can only be set once");
|
||||||
|
}
|
||||||
|
setter(val, idx);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the default value
|
||||||
|
if (typeof defaults[v] !== 'undefined') {
|
||||||
|
defval = defaults[v];
|
||||||
|
} else if ((type in {'arr':1, 'array':1}) &&
|
||||||
|
(! (defval instanceof Array))) {
|
||||||
|
defval = [];
|
||||||
|
}
|
||||||
|
// Coerce existing setting to the right type
|
||||||
|
//Util.Debug("v: " + v + ", defval: " + defval + ", defaults[v]: " + defaults[v]);
|
||||||
|
setter(defval);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set group of configuration defaults
|
||||||
|
Util.conf_defaults = function(cfg, api, defaults, arr) {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < arr.length; i++) {
|
||||||
|
Util.conf_default(cfg, api, defaults, arr[i][0], arr[i][1],
|
||||||
|
arr[i][2], arr[i][3], arr[i][4]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -142,6 +208,7 @@ Util.getEventPosition = function (e, obj, scale) {
|
||||||
var evt, docX, docY, pos;
|
var evt, docX, docY, pos;
|
||||||
//if (!e) evt = window.event;
|
//if (!e) evt = window.event;
|
||||||
evt = (e ? e : window.event);
|
evt = (e ? e : window.event);
|
||||||
|
evt = (evt.changedTouches ? evt.changedTouches[0] : evt.touches ? evt.touches[0] : evt);
|
||||||
if (evt.pageX || evt.pageY) {
|
if (evt.pageX || evt.pageY) {
|
||||||
docX = evt.pageX;
|
docX = evt.pageX;
|
||||||
docY = evt.pageY;
|
docY = evt.pageY;
|
||||||
|
|
@ -197,8 +264,11 @@ Util.stopEvent = function(e) {
|
||||||
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
||||||
|
|
||||||
Util.Engine = {
|
Util.Engine = {
|
||||||
'presto': (function() {
|
// Version detection break in Opera 11.60 (errors on arguments.callee.caller reference)
|
||||||
return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
//'presto': (function() {
|
||||||
|
// return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
||||||
|
'presto': (function() { return (!window.opera) ? false : true; }()),
|
||||||
|
|
||||||
'trident': (function() {
|
'trident': (function() {
|
||||||
return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); }()),
|
return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); }()),
|
||||||
'webkit': (function() {
|
'webkit': (function() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue