Add profiling with Remotery
This commit is contained in:
parent
c37be6798f
commit
6331a2bf79
50 changed files with 16864 additions and 11 deletions
65
vis/extern/BrowserLib/Core/Code/Animation.js
vendored
Normal file
65
vis/extern/BrowserLib/Core/Code/Animation.js
vendored
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
|
||||
//
|
||||
// Very basic linear value animation system, for now.
|
||||
//
|
||||
|
||||
|
||||
namespace("Anim");
|
||||
|
||||
|
||||
Anim.Animation = (function()
|
||||
{
|
||||
var anim_hz = 60;
|
||||
|
||||
|
||||
function Animation(anim_func, start_value, end_value, time, end_callback)
|
||||
{
|
||||
// Setup initial parameters
|
||||
this.StartValue = start_value;
|
||||
this.EndValue = end_value;
|
||||
this.ValueInc = (end_value - start_value) / (time * anim_hz);
|
||||
this.Value = start_value;
|
||||
this.Complete = false;
|
||||
this.EndCallback = end_callback;
|
||||
|
||||
// Cache the update function to prevent recreating the closure
|
||||
var self = this;
|
||||
this.AnimFunc = anim_func;
|
||||
this.AnimUpdate = function() { Update(self); }
|
||||
|
||||
// Call for the start value
|
||||
this.AnimUpdate();
|
||||
}
|
||||
|
||||
|
||||
function Update(self)
|
||||
{
|
||||
// Queue up the next frame immediately
|
||||
var id = window.setTimeout(self.AnimUpdate, 1000 / anim_hz);
|
||||
|
||||
// Linear step the value and check for completion
|
||||
self.Value += self.ValueInc;
|
||||
if (Math.abs(self.Value - self.EndValue) < 0.01)
|
||||
{
|
||||
self.Value = self.EndValue;
|
||||
self.Complete = true;
|
||||
|
||||
if (self.EndCallback)
|
||||
self.EndCallback();
|
||||
|
||||
window.clearTimeout(id);
|
||||
}
|
||||
|
||||
// Pass to the animation function
|
||||
self.AnimFunc(self.Value);
|
||||
}
|
||||
|
||||
|
||||
return Animation;
|
||||
})();
|
||||
|
||||
|
||||
Anim.Animate = function(anim_func, start_value, end_value, time, end_callback)
|
||||
{
|
||||
return new Anim.Animation(anim_func, start_value, end_value, time, end_callback);
|
||||
}
|
||||
92
vis/extern/BrowserLib/Core/Code/Bind.js
vendored
Normal file
92
vis/extern/BrowserLib/Core/Code/Bind.js
vendored
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
//
|
||||
// This will generate a closure for the given function and optionally bind an arbitrary number of
|
||||
// its initial arguments to specific values.
|
||||
//
|
||||
// Parameters:
|
||||
//
|
||||
// 0: Either the function scope or the function.
|
||||
// 1: If 0 is the function scope, this is the function.
|
||||
// Otherwise it's the start of the optional bound argument list.
|
||||
// 2: Start of the optional bound argument list if 1 is the function.
|
||||
//
|
||||
// Examples:
|
||||
//
|
||||
// function GlobalFunction(p0, p1, p2) { }
|
||||
// function ThisFunction(p0, p1, p2) { }
|
||||
//
|
||||
// var a = Bind("GlobalFunction");
|
||||
// var b = Bind(this, "ThisFunction");
|
||||
// var c = Bind("GlobalFunction", BoundParam0, BoundParam1);
|
||||
// var d = Bind(this, "ThisFunction", BoundParam0, BoundParam1);
|
||||
// var e = Bind(GlobalFunction);
|
||||
// var f = Bind(this, ThisFunction);
|
||||
// var g = Bind(GlobalFunction, BoundParam0, BoundParam1);
|
||||
// var h = Bind(this, ThisFunction, BoundParam0, BoundParam1);
|
||||
//
|
||||
// a(0, 1, 2);
|
||||
// b(0, 1, 2);
|
||||
// c(2);
|
||||
// d(2);
|
||||
// e(0, 1, 2);
|
||||
// f(0, 1, 2);
|
||||
// g(2);
|
||||
// h(2);
|
||||
//
|
||||
function Bind()
|
||||
{
|
||||
// No closure to define?
|
||||
if (arguments.length == 0)
|
||||
return null;
|
||||
|
||||
// Figure out which of the 4 call types is being used to bind
|
||||
// Locate scope, function and bound parameter start index
|
||||
|
||||
if (typeof(arguments[0]) == "string")
|
||||
{
|
||||
var scope = window;
|
||||
var func = window[arguments[0]];
|
||||
var start = 1;
|
||||
}
|
||||
|
||||
else if (typeof(arguments[0]) == "function")
|
||||
{
|
||||
var scope = window;
|
||||
var func = arguments[0];
|
||||
var start = 1;
|
||||
}
|
||||
|
||||
else if (typeof(arguments[1]) == "string")
|
||||
{
|
||||
var scope = arguments[0];
|
||||
var func = scope[arguments[1]];
|
||||
var start = 2;
|
||||
}
|
||||
|
||||
else if (typeof(arguments[1]) == "function")
|
||||
{
|
||||
var scope = arguments[0];
|
||||
var func = arguments[1];
|
||||
var start = 2;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// unknown
|
||||
console.log("Bind() ERROR: Unknown bind parameter configuration");
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the arguments list to an array
|
||||
var arg_array = Array.prototype.slice.call(arguments, start);
|
||||
start = arg_array.length;
|
||||
|
||||
return function()
|
||||
{
|
||||
// Concatenate incoming arguments
|
||||
for (var i = 0; i < arguments.length; i++)
|
||||
arg_array[start + i] = arguments[i];
|
||||
|
||||
// Call the function in the given scope with the new arguments
|
||||
return func.apply(scope, arg_array);
|
||||
}
|
||||
}
|
||||
218
vis/extern/BrowserLib/Core/Code/Convert.js
vendored
Normal file
218
vis/extern/BrowserLib/Core/Code/Convert.js
vendored
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
|
||||
namespace("Convert");
|
||||
|
||||
|
||||
//
|
||||
// Convert between utf8 and b64 without raising character out of range exceptions with unicode strings
|
||||
// Technique described here: http://monsur.hossa.in/2012/07/20/utf-8-in-javascript.html
|
||||
//
|
||||
Convert.utf8string_to_b64string = function(str)
|
||||
{
|
||||
return btoa(unescape(encodeURIComponent(str)));
|
||||
}
|
||||
Convert.b64string_to_utf8string = function(str)
|
||||
{
|
||||
return decodeURIComponent(escape(atob(str)));
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// More general approach, converting between byte arrays and b64
|
||||
// Info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
||||
//
|
||||
Convert.b64string_to_Uint8Array = function(sBase64, nBlocksSize)
|
||||
{
|
||||
function b64ToUint6 (nChr)
|
||||
{
|
||||
return nChr > 64 && nChr < 91 ?
|
||||
nChr - 65
|
||||
: nChr > 96 && nChr < 123 ?
|
||||
nChr - 71
|
||||
: nChr > 47 && nChr < 58 ?
|
||||
nChr + 4
|
||||
: nChr === 43 ?
|
||||
62
|
||||
: nChr === 47 ?
|
||||
63
|
||||
:
|
||||
0;
|
||||
}
|
||||
|
||||
var
|
||||
sB64Enc = sBase64.replace(/[^A-Za-z0-9\+\/]/g, ""),
|
||||
nInLen = sB64Enc.length,
|
||||
nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2,
|
||||
taBytes = new Uint8Array(nOutLen);
|
||||
|
||||
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++)
|
||||
{
|
||||
nMod4 = nInIdx & 3;
|
||||
nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 18 - 6 * nMod4;
|
||||
if (nMod4 === 3 || nInLen - nInIdx === 1)
|
||||
{
|
||||
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++)
|
||||
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return taBytes;
|
||||
}
|
||||
Convert.Uint8Array_to_b64string = function(aBytes)
|
||||
{
|
||||
function uint6ToB64 (nUint6)
|
||||
{
|
||||
return nUint6 < 26 ?
|
||||
nUint6 + 65
|
||||
: nUint6 < 52 ?
|
||||
nUint6 + 71
|
||||
: nUint6 < 62 ?
|
||||
nUint6 - 4
|
||||
: nUint6 === 62 ?
|
||||
43
|
||||
: nUint6 === 63 ?
|
||||
47
|
||||
:
|
||||
65;
|
||||
}
|
||||
|
||||
var nMod3, sB64Enc = "";
|
||||
|
||||
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++)
|
||||
{
|
||||
nMod3 = nIdx % 3;
|
||||
if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0)
|
||||
sB64Enc += "\r\n";
|
||||
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
|
||||
if (nMod3 === 2 || aBytes.length - nIdx === 1)
|
||||
{
|
||||
sB64Enc += String.fromCharCode(uint6ToB64(nUint24 >>> 18 & 63), uint6ToB64(nUint24 >>> 12 & 63), uint6ToB64(nUint24 >>> 6 & 63), uint6ToB64(nUint24 & 63));
|
||||
nUint24 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return sB64Enc.replace(/A(?=A$|$)/g, "=");
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Unicode and arbitrary value safe conversion between strings and Uint8Arrays
|
||||
//
|
||||
Convert.Uint8Array_to_string = function(aBytes)
|
||||
{
|
||||
var sView = "";
|
||||
|
||||
for (var nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++)
|
||||
{
|
||||
nPart = aBytes[nIdx];
|
||||
sView += String.fromCharCode(
|
||||
nPart > 251 && nPart < 254 && nIdx + 5 < nLen ? /* six bytes */
|
||||
/* (nPart - 252 << 32) is not possible in ECMAScript! So...: */
|
||||
(nPart - 252) * 1073741824 + (aBytes[++nIdx] - 128 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
|
||||
: nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /* five bytes */
|
||||
(nPart - 248 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
|
||||
: nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /* four bytes */
|
||||
(nPart - 240 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
|
||||
: nPart > 223 && nPart < 240 && nIdx + 2 < nLen ? /* three bytes */
|
||||
(nPart - 224 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
|
||||
: nPart > 191 && nPart < 224 && nIdx + 1 < nLen ? /* two bytes */
|
||||
(nPart - 192 << 6) + aBytes[++nIdx] - 128
|
||||
: /* nPart < 127 ? */ /* one byte */
|
||||
nPart
|
||||
);
|
||||
}
|
||||
|
||||
return sView;
|
||||
}
|
||||
Convert.string_to_Uint8Array = function(sDOMStr)
|
||||
{
|
||||
var aBytes, nChr, nStrLen = sDOMStr.length, nArrLen = 0;
|
||||
|
||||
/* mapping... */
|
||||
|
||||
for (var nMapIdx = 0; nMapIdx < nStrLen; nMapIdx++)
|
||||
{
|
||||
nChr = sDOMStr.charCodeAt(nMapIdx);
|
||||
nArrLen += nChr < 0x80 ? 1 : nChr < 0x800 ? 2 : nChr < 0x10000 ? 3 : nChr < 0x200000 ? 4 : nChr < 0x4000000 ? 5 : 6;
|
||||
}
|
||||
|
||||
aBytes = new Uint8Array(nArrLen);
|
||||
|
||||
/* transcription... */
|
||||
|
||||
for (var nIdx = 0, nChrIdx = 0; nIdx < nArrLen; nChrIdx++)
|
||||
{
|
||||
nChr = sDOMStr.charCodeAt(nChrIdx);
|
||||
if (nChr < 128)
|
||||
{
|
||||
/* one byte */
|
||||
aBytes[nIdx++] = nChr;
|
||||
}
|
||||
else if (nChr < 0x800)
|
||||
{
|
||||
/* two bytes */
|
||||
aBytes[nIdx++] = 192 + (nChr >>> 6);
|
||||
aBytes[nIdx++] = 128 + (nChr & 63);
|
||||
}
|
||||
else if (nChr < 0x10000)
|
||||
{
|
||||
/* three bytes */
|
||||
aBytes[nIdx++] = 224 + (nChr >>> 12);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr & 63);
|
||||
}
|
||||
else if (nChr < 0x200000)
|
||||
{
|
||||
/* four bytes */
|
||||
aBytes[nIdx++] = 240 + (nChr >>> 18);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr & 63);
|
||||
}
|
||||
else if (nChr < 0x4000000)
|
||||
{
|
||||
/* five bytes */
|
||||
aBytes[nIdx++] = 248 + (nChr >>> 24);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr & 63);
|
||||
}
|
||||
else /* if (nChr <= 0x7fffffff) */
|
||||
{
|
||||
/* six bytes */
|
||||
aBytes[nIdx++] = 252 + /* (nChr >>> 32) is not possible in ECMAScript! So...: */ (nChr / 1073741824);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 24 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 18 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 12 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr >>> 6 & 63);
|
||||
aBytes[nIdx++] = 128 + (nChr & 63);
|
||||
}
|
||||
}
|
||||
|
||||
return aBytes;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Converts all characters in a string that have equivalent entities to their ampersand/entity names.
|
||||
// Based on https://gist.github.com/jonathantneal/6093551
|
||||
//
|
||||
Convert.string_to_html_entities = (function()
|
||||
{
|
||||
'use strict';
|
||||
|
||||
var data = '34quot38amp39apos60lt62gt160nbsp161iexcl162cent163pound164curren165yen166brvbar167sect168uml169copy170ordf171laquo172not173shy174reg175macr176deg177plusmn178sup2179sup3180acute181micro182para183middot184cedil185sup1186ordm187raquo188frac14189frac12190frac34191iquest192Agrave193Aacute194Acirc195Atilde196Auml197Aring198AElig199Ccedil200Egrave201Eacute202Ecirc203Euml204Igrave205Iacute206Icirc207Iuml208ETH209Ntilde210Ograve211Oacute212Ocirc213Otilde214Ouml215times216Oslash217Ugrave218Uacute219Ucirc220Uuml221Yacute222THORN223szlig224agrave225aacute226acirc227atilde228auml229aring230aelig231ccedil232egrave233eacute234ecirc235euml236igrave237iacute238icirc239iuml240eth241ntilde242ograve243oacute244ocirc245otilde246ouml247divide248oslash249ugrave250uacute251ucirc252uuml253yacute254thorn255yuml402fnof913Alpha914Beta915Gamma916Delta917Epsilon918Zeta919Eta920Theta921Iota922Kappa923Lambda924Mu925Nu926Xi927Omicron928Pi929Rho931Sigma932Tau933Upsilon934Phi935Chi936Psi937Omega945alpha946beta947gamma948delta949epsilon950zeta951eta952theta953iota954kappa955lambda956mu957nu958xi959omicron960pi961rho962sigmaf963sigma964tau965upsilon966phi967chi968psi969omega977thetasym978upsih982piv8226bull8230hellip8242prime8243Prime8254oline8260frasl8472weierp8465image8476real8482trade8501alefsym8592larr8593uarr8594rarr8595darr8596harr8629crarr8656lArr8657uArr8658rArr8659dArr8660hArr8704forall8706part8707exist8709empty8711nabla8712isin8713notin8715ni8719prod8721sum8722minus8727lowast8730radic8733prop8734infin8736ang8743and8744or8745cap8746cup8747int8756there48764sim8773cong8776asymp8800ne8801equiv8804le8805ge8834sub8835sup8836nsub8838sube8839supe8853oplus8855otimes8869perp8901sdot8968lceil8969rceil8970lfloor8971rfloor9001lang9002rang9674loz9824spades9827clubs9829hearts9830diams338OElig339oelig352Scaron353scaron376Yuml710circ732tilde8194ensp8195emsp8201thinsp8204zwnj8205zwj8206lrm8207rlm8211ndash8212mdash8216lsquo8217rsquo8218sbquo8220ldquo8221rdquo8222bdquo8224dagger8225Dagger8240permil8249lsaquo8250rsaquo8364euro';
|
||||
var charCodes = data.split(/[A-z]+/);
|
||||
var entities = data.split(/\d+/).slice(1);
|
||||
|
||||
return function encodeHTMLEntities(text)
|
||||
{
|
||||
return text.replace(/[\u00A0-\u2666<>"'&]/g, function (match)
|
||||
{
|
||||
var charCode = String(match.charCodeAt(0));
|
||||
var index = charCodes.indexOf(charCode);
|
||||
return '&' + (entities[index] ? entities[index] : '#' + charCode) + ';';
|
||||
});
|
||||
};
|
||||
})();
|
||||
26
vis/extern/BrowserLib/Core/Code/Core.js
vendored
Normal file
26
vis/extern/BrowserLib/Core/Code/Core.js
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
// TODO: requires function for checking existence of dependencies
|
||||
|
||||
|
||||
function namespace(name)
|
||||
{
|
||||
// Ensure all nested namespaces are created only once
|
||||
|
||||
var ns_list = name.split(".");
|
||||
var parent_ns = window;
|
||||
|
||||
for (var i in ns_list)
|
||||
{
|
||||
var ns_name = ns_list[i];
|
||||
if (!(ns_name in parent_ns))
|
||||
parent_ns[ns_name] = { };
|
||||
|
||||
parent_ns = parent_ns[ns_name];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function multiline(fn)
|
||||
{
|
||||
return fn.toString().split(/\n/).slice(1, -1).join("\n");
|
||||
}
|
||||
526
vis/extern/BrowserLib/Core/Code/DOM.js
vendored
Normal file
526
vis/extern/BrowserLib/Core/Code/DOM.js
vendored
Normal file
|
|
@ -0,0 +1,526 @@
|
|||
|
||||
namespace("DOM.Node");
|
||||
namespace("DOM.Event");
|
||||
namespace("DOM.Applet");
|
||||
|
||||
|
||||
|
||||
//
|
||||
// =====================================================================================================================
|
||||
// ----- DOCUMENT NODE/ELEMENT EXTENSIONS ------------------------------------------------------------------------------
|
||||
// =====================================================================================================================
|
||||
//
|
||||
|
||||
|
||||
|
||||
DOM.Node.Get = function(id)
|
||||
{
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Set node position
|
||||
//
|
||||
DOM.Node.SetPosition = function(node, position)
|
||||
{
|
||||
node.style.left = position[0];
|
||||
node.style.top = position[1];
|
||||
}
|
||||
DOM.Node.SetX = function(node, x)
|
||||
{
|
||||
node.style.left = x;
|
||||
}
|
||||
DOM.Node.SetY = function(node, y)
|
||||
{
|
||||
node.style.top = y;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get the absolute position of a HTML element on the page
|
||||
//
|
||||
DOM.Node.GetPosition = function(element, account_for_scroll)
|
||||
{
|
||||
// Recurse up through parents, summing offsets from their parent
|
||||
var x = 0, y = 0;
|
||||
for (var node = element; node != null; node = node.offsetParent)
|
||||
{
|
||||
x += node.offsetLeft;
|
||||
y += node.offsetTop;
|
||||
}
|
||||
|
||||
if (account_for_scroll)
|
||||
{
|
||||
// Walk up the hierarchy subtracting away any scrolling
|
||||
for (var node = element; node != document.body; node = node.parentNode)
|
||||
{
|
||||
x -= node.scrollLeft;
|
||||
y -= node.scrollTop;
|
||||
}
|
||||
}
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Set node size
|
||||
//
|
||||
DOM.Node.SetSize = function(node, size)
|
||||
{
|
||||
node.style.width = size[0];
|
||||
node.style.height = size[1];
|
||||
}
|
||||
DOM.Node.SetWidth = function(node, width)
|
||||
{
|
||||
node.style.width = width;
|
||||
}
|
||||
DOM.Node.SetHeight = function(node, height)
|
||||
{
|
||||
node.style.height = height;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get node OFFSET size:
|
||||
// clientX includes padding
|
||||
// offsetX includes padding and borders
|
||||
// scrollX includes padding, borders and size of contained node
|
||||
//
|
||||
DOM.Node.GetSize = function(node)
|
||||
{
|
||||
return [ node.offsetWidth, node.offsetHeight ];
|
||||
}
|
||||
DOM.Node.GetWidth = function(node)
|
||||
{
|
||||
return node.offsetWidth;
|
||||
}
|
||||
DOM.Node.GetHeight = function(node)
|
||||
{
|
||||
return node.offsetHeight;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Set node opacity
|
||||
//
|
||||
DOM.Node.SetOpacity = function(node, value)
|
||||
{
|
||||
node.style.opacity = value;
|
||||
}
|
||||
|
||||
|
||||
DOM.Node.SetColour = function(node, colour)
|
||||
{
|
||||
node.style.color = colour;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Hide a node by completely disabling its rendering (it no longer contributes to document layout)
|
||||
//
|
||||
DOM.Node.Hide = function(node)
|
||||
{
|
||||
node.style.display = "none";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Show a node by restoring its influcen in document layout
|
||||
//
|
||||
DOM.Node.Show = function(node)
|
||||
{
|
||||
node.style.display = "block";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Add a CSS class to a HTML element, specified last
|
||||
//
|
||||
DOM.Node.AddClass = function(node, class_name)
|
||||
{
|
||||
// Ensure the class hasn't already been added
|
||||
DOM.Node.RemoveClass(node, class_name);
|
||||
node.className += " " + class_name;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Remove a CSS class from a HTML element
|
||||
//
|
||||
DOM.Node.RemoveClass = function(node, class_name)
|
||||
{
|
||||
// Remove all variations of where the class name can be in the string list
|
||||
var regexp = new RegExp("\\b" + class_name + "\\b");
|
||||
node.className = node.className.replace(regexp, "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Check to see if a HTML element contains a class
|
||||
//
|
||||
DOM.Node.HasClass = function(node, class_name)
|
||||
{
|
||||
var regexp = new RegExp("\\b" + class_name + "\\b");
|
||||
return regexp.test(node.className);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Recursively search for a node with the given class name
|
||||
//
|
||||
DOM.Node.FindWithClass = function(parent_node, class_name, index)
|
||||
{
|
||||
// Search the children looking for a node with the given class name
|
||||
for (var i in parent_node.childNodes)
|
||||
{
|
||||
var node = parent_node.childNodes[i];
|
||||
if (DOM.Node.HasClass(node, class_name))
|
||||
{
|
||||
if (index === undefined || index-- == 0)
|
||||
return node;
|
||||
}
|
||||
|
||||
// Recurse into children
|
||||
node = DOM.Node.FindWithClass(node, class_name);
|
||||
if (node != null)
|
||||
return node;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Check to see if one node logically contains another
|
||||
//
|
||||
DOM.Node.Contains = function(node, container_node)
|
||||
{
|
||||
while (node != null && node != container_node)
|
||||
node = node.parentNode;
|
||||
return node != null;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Create the HTML nodes specified in the text passed in
|
||||
// Assumes there is only one root node in the text
|
||||
//
|
||||
DOM.Node.CreateHTML = function(html)
|
||||
{
|
||||
var div = document.createElement("div");
|
||||
div.innerHTML = html;
|
||||
|
||||
// First child may be a text node, followed by the created HTML
|
||||
var child = div.firstChild;
|
||||
if (child != null && child.nodeType == 3)
|
||||
child = child.nextSibling;
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Make a copy of a HTML element, making it visible and clearing its ID to ensure it's not a duplicate
|
||||
//
|
||||
DOM.Node.Clone = function(name)
|
||||
{
|
||||
// Get the template element and clone it, making sure it's renderable
|
||||
var node = DOM.Node.Get(name);
|
||||
node = node.cloneNode(true);
|
||||
node.id = null;
|
||||
node.style.display = "block";
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Append an arbitrary block of HTML to an existing node
|
||||
//
|
||||
DOM.Node.AppendHTML = function(node, html)
|
||||
{
|
||||
var child = DOM.Node.CreateHTML(html);
|
||||
node.appendChild(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Append a div that clears the float style
|
||||
//
|
||||
DOM.Node.AppendClearFloat = function(node)
|
||||
{
|
||||
var div = document.createElement("div");
|
||||
div.style.clear = "both";
|
||||
node.appendChild(div);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Check to see that the object passed in is an instance of a DOM node
|
||||
//
|
||||
DOM.Node.IsNode = function(object)
|
||||
{
|
||||
return object instanceof Element;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Create an "iframe shim" so that elements within it render over a Java Applet
|
||||
// http://web.archive.org/web/20110707212850/http://www.oratransplant.nl/2007/10/26/using-iframe-shim-to-partly-cover-a-java-applet/
|
||||
//
|
||||
DOM.Node.CreateShim = function(parent)
|
||||
{
|
||||
var shimmer = document.createElement("iframe");
|
||||
|
||||
// Position the shimmer so that it's the same location/size as its parent
|
||||
shimmer.style.position = "fixed";
|
||||
shimmer.style.left = parent.style.left;
|
||||
shimmer.style.top = parent.style.top;
|
||||
shimmer.style.width = parent.offsetWidth;
|
||||
shimmer.style.height = parent.offsetHeight;
|
||||
|
||||
// We want the shimmer to be one level below its contents
|
||||
shimmer.style.zIndex = parent.style.zIndex - 1;
|
||||
|
||||
// Ensure its empty
|
||||
shimmer.setAttribute("frameborder", "0");
|
||||
shimmer.setAttribute("src", "");
|
||||
|
||||
// Add to the document and the parent
|
||||
document.body.appendChild(shimmer);
|
||||
parent.Shimmer = shimmer;
|
||||
return shimmer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// =====================================================================================================================
|
||||
// ----- EVENT HANDLING EXTENSIONS -------------------------------------------------------------------------------------
|
||||
// =====================================================================================================================
|
||||
//
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Retrieves the event from the first parameter passed into an HTML event
|
||||
//
|
||||
DOM.Event.Get = function(evt)
|
||||
{
|
||||
// Internet explorer doesn't pass the event
|
||||
return window.event || evt;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Retrieves the element that triggered an event from the event object
|
||||
//
|
||||
DOM.Event.GetNode = function(evt)
|
||||
{
|
||||
evt = DOM.Event.Get(evt);
|
||||
|
||||
// Get the target element
|
||||
var element;
|
||||
if (evt.target)
|
||||
element = evt.target;
|
||||
else if (e.srcElement)
|
||||
element = evt.srcElement;
|
||||
|
||||
// Default Safari bug
|
||||
if (element.nodeType == 3)
|
||||
element = element.parentNode;
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Stop default action for an event
|
||||
//
|
||||
DOM.Event.StopDefaultAction = function(evt)
|
||||
{
|
||||
if (evt && evt.preventDefault)
|
||||
evt.preventDefault();
|
||||
else if (window.event && window.event.returnValue)
|
||||
window.event.returnValue = false;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Stops events bubbling up to parent event handlers
|
||||
//
|
||||
DOM.Event.StopPropagation = function(evt)
|
||||
{
|
||||
evt = DOM.Event.Get(evt);
|
||||
if (evt)
|
||||
{
|
||||
evt.cancelBubble = true;
|
||||
if (evt.stopPropagation)
|
||||
evt.stopPropagation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Stop both event default action and propagation
|
||||
//
|
||||
DOM.Event.StopAll = function(evt)
|
||||
{
|
||||
DOM.Event.StopDefaultAction(evt);
|
||||
DOM.Event.StopPropagation(evt);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Adds an event handler to an event
|
||||
//
|
||||
DOM.Event.AddHandler = function(obj, evt, func)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
if (obj.addEventListener)
|
||||
obj.addEventListener(evt, func, false);
|
||||
else if (obj.attachEvent)
|
||||
obj.attachEvent("on" + evt, func);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Removes an event handler from an event
|
||||
//
|
||||
DOM.Event.RemoveHandler = function(obj, evt, func)
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
if (obj.removeEventListener)
|
||||
obj.removeEventListener(evt, func, false);
|
||||
else if (obj.detachEvent)
|
||||
obj.detachEvent("on" + evt, func);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get the position of the mouse cursor, page relative
|
||||
//
|
||||
DOM.Event.GetMousePosition = function(evt)
|
||||
{
|
||||
evt = DOM.Event.Get(evt);
|
||||
|
||||
var px = 0;
|
||||
var py = 0;
|
||||
if (evt.pageX || evt.pageY)
|
||||
{
|
||||
px = evt.pageX;
|
||||
py = evt.pageY;
|
||||
}
|
||||
else if (evt.clientX || evt.clientY)
|
||||
{
|
||||
px = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
|
||||
py = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
|
||||
}
|
||||
|
||||
return [px, py];
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Get the list of files attached to a drop event
|
||||
//
|
||||
DOM.Event.GetDropFiles = function(evt)
|
||||
{
|
||||
let files = [];
|
||||
if (evt.dataTransfer.items)
|
||||
{
|
||||
for (let i = 0; i < evt.dataTransfer.items.length; i++)
|
||||
{
|
||||
if (evt.dataTransfer.items[i].kind === 'file')
|
||||
{
|
||||
files.push(evt.dataTransfer.items[i].getAsFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (let i = 0; i < evt.dataTransfer.files.length; i++)
|
||||
{
|
||||
files.push(evt.dataTransfer.files[i]);
|
||||
}
|
||||
}
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// =====================================================================================================================
|
||||
// ----- JAVA APPLET EXTENSIONS ----------------------------------------------------------------------------------------
|
||||
// =====================================================================================================================
|
||||
//
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Create an applet element for loading a Java applet, attaching it to the specified node
|
||||
//
|
||||
DOM.Applet.Load = function(dest_id, id, code, archive)
|
||||
{
|
||||
// Lookup the applet destination
|
||||
var dest = DOM.Node.Get(dest_id);
|
||||
if (!dest)
|
||||
return;
|
||||
|
||||
// Construct the applet element and add it to the destination
|
||||
Debug.Log("Injecting applet DOM code");
|
||||
var applet = "<applet id='" + id + "' code='" + code + "' archive='" + archive + "'";
|
||||
applet += " width='" + dest.offsetWidth + "' height='" + dest.offsetHeight + "'>";
|
||||
applet += "</applet>";
|
||||
dest.innerHTML = applet;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Moves and resizes a named applet so that it fits in the destination div element.
|
||||
// The applet must be contained by a div element itself. This container div is moved along
|
||||
// with the applet.
|
||||
//
|
||||
DOM.Applet.Move = function(dest_div, applet, z_index, hide)
|
||||
{
|
||||
if (!applet || !dest_div)
|
||||
return;
|
||||
|
||||
// Before modifying any location information, hide the applet so that it doesn't render over
|
||||
// any newly visible elements that appear while the location information is being modified.
|
||||
if (hide)
|
||||
applet.style.visibility = "hidden";
|
||||
|
||||
// Get its view rect
|
||||
var pos = DOM.Node.GetPosition(dest_div);
|
||||
var w = dest_div.offsetWidth;
|
||||
var h = dest_div.offsetHeight;
|
||||
|
||||
// It needs to be embedded in a <div> for correct scale/position adjustment
|
||||
var container = applet.parentNode;
|
||||
if (!container || container.localName != "div")
|
||||
{
|
||||
Debug.Log("ERROR: Couldn't find source applet's div container");
|
||||
return;
|
||||
}
|
||||
|
||||
// Reposition and resize the containing div element
|
||||
container.style.left = pos[0];
|
||||
container.style.top = pos[1];
|
||||
container.style.width = w;
|
||||
container.style.height = h;
|
||||
container.style.zIndex = z_index;
|
||||
|
||||
// Resize the applet itself
|
||||
applet.style.width = w;
|
||||
applet.style.height = h;
|
||||
|
||||
// Everything modified, safe to show
|
||||
applet.style.visibility = "visible";
|
||||
}
|
||||
149
vis/extern/BrowserLib/Core/Code/Keyboard.js
vendored
Normal file
149
vis/extern/BrowserLib/Core/Code/Keyboard.js
vendored
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
|
||||
namespace("Keyboard")
|
||||
|
||||
|
||||
// =====================================================================================================================
|
||||
// Key codes copied from closure-library
|
||||
// https://code.google.com/p/closure-library/source/browse/closure/goog/events/keycodes.js
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
// Copyright 2006 The Closure Library Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS-IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
Keyboard.Codes = {
|
||||
WIN_KEY_FF_LINUX : 0,
|
||||
MAC_ENTER : 3,
|
||||
BACKSPACE : 8,
|
||||
TAB : 9,
|
||||
NUM_CENTER : 12, // NUMLOCK on FF/Safari Mac
|
||||
ENTER : 13,
|
||||
SHIFT : 16,
|
||||
CTRL : 17,
|
||||
ALT : 18,
|
||||
PAUSE : 19,
|
||||
CAPS_LOCK : 20,
|
||||
ESC : 27,
|
||||
SPACE : 32,
|
||||
PAGE_UP : 33, // also NUM_NORTH_EAST
|
||||
PAGE_DOWN : 34, // also NUM_SOUTH_EAST
|
||||
END : 35, // also NUM_SOUTH_WEST
|
||||
HOME : 36, // also NUM_NORTH_WEST
|
||||
LEFT : 37, // also NUM_WEST
|
||||
UP : 38, // also NUM_NORTH
|
||||
RIGHT : 39, // also NUM_EAST
|
||||
DOWN : 40, // also NUM_SOUTH
|
||||
PRINT_SCREEN : 44,
|
||||
INSERT : 45, // also NUM_INSERT
|
||||
DELETE : 46, // also NUM_DELETE
|
||||
ZERO : 48,
|
||||
ONE : 49,
|
||||
TWO : 50,
|
||||
THREE : 51,
|
||||
FOUR : 52,
|
||||
FIVE : 53,
|
||||
SIX : 54,
|
||||
SEVEN : 55,
|
||||
EIGHT : 56,
|
||||
NINE : 57,
|
||||
FF_SEMICOLON : 59, // Firefox (Gecko) fires this for semicolon instead of 186
|
||||
FF_EQUALS : 61, // Firefox (Gecko) fires this for equals instead of 187
|
||||
FF_DASH : 173, // Firefox (Gecko) fires this for dash instead of 189
|
||||
QUESTION_MARK : 63, // needs localization
|
||||
A : 65,
|
||||
B : 66,
|
||||
C : 67,
|
||||
D : 68,
|
||||
E : 69,
|
||||
F : 70,
|
||||
G : 71,
|
||||
H : 72,
|
||||
I : 73,
|
||||
J : 74,
|
||||
K : 75,
|
||||
L : 76,
|
||||
M : 77,
|
||||
N : 78,
|
||||
O : 79,
|
||||
P : 80,
|
||||
Q : 81,
|
||||
R : 82,
|
||||
S : 83,
|
||||
T : 84,
|
||||
U : 85,
|
||||
V : 86,
|
||||
W : 87,
|
||||
X : 88,
|
||||
Y : 89,
|
||||
Z : 90,
|
||||
META : 91, // WIN_KEY_LEFT
|
||||
WIN_KEY_RIGHT : 92,
|
||||
CONTEXT_MENU : 93,
|
||||
NUM_ZERO : 96,
|
||||
NUM_ONE : 97,
|
||||
NUM_TWO : 98,
|
||||
NUM_THREE : 99,
|
||||
NUM_FOUR : 100,
|
||||
NUM_FIVE : 101,
|
||||
NUM_SIX : 102,
|
||||
NUM_SEVEN : 103,
|
||||
NUM_EIGHT : 104,
|
||||
NUM_NINE : 105,
|
||||
NUM_MULTIPLY : 106,
|
||||
NUM_PLUS : 107,
|
||||
NUM_MINUS : 109,
|
||||
NUM_PERIOD : 110,
|
||||
NUM_DIVISION : 111,
|
||||
F1 : 112,
|
||||
F2 : 113,
|
||||
F3 : 114,
|
||||
F4 : 115,
|
||||
F5 : 116,
|
||||
F6 : 117,
|
||||
F7 : 118,
|
||||
F8 : 119,
|
||||
F9 : 120,
|
||||
F10 : 121,
|
||||
F11 : 122,
|
||||
F12 : 123,
|
||||
NUMLOCK : 144,
|
||||
SCROLL_LOCK : 145,
|
||||
|
||||
// OS-specific media keys like volume controls and browser controls.
|
||||
FIRST_MEDIA_KEY : 166,
|
||||
LAST_MEDIA_KEY : 183,
|
||||
|
||||
SEMICOLON : 186, // needs localization
|
||||
DASH : 189, // needs localization
|
||||
EQUALS : 187, // needs localization
|
||||
COMMA : 188, // needs localization
|
||||
PERIOD : 190, // needs localization
|
||||
SLASH : 191, // needs localization
|
||||
APOSTROPHE : 192, // needs localization
|
||||
TILDE : 192, // needs localization
|
||||
SINGLE_QUOTE : 222, // needs localization
|
||||
OPEN_SQUARE_BRACKET : 219, // needs localization
|
||||
BACKSLASH : 220, // needs localization
|
||||
CLOSE_SQUARE_BRACKET: 221, // needs localization
|
||||
WIN_KEY : 224,
|
||||
MAC_FF_META : 224, // Firefox (Gecko) fires this for the meta key instead of 91
|
||||
MAC_WK_CMD_LEFT : 91, // WebKit Left Command key fired, same as META
|
||||
MAC_WK_CMD_RIGHT : 93, // WebKit Right Command key fired, different from META
|
||||
WIN_IME : 229,
|
||||
|
||||
// We've seen users whose machines fire this keycode at regular one
|
||||
// second intervals. The common thread among these users is that
|
||||
// they're all using Dell Inspiron laptops, so we suspect that this
|
||||
// indicates a hardware/bios problem.
|
||||
// http://en.community.dell.com/support-forums/laptop/f/3518/p/19285957/19523128.aspx
|
||||
PHANTOM : 255
|
||||
};
|
||||
// =====================================================================================================================
|
||||
40
vis/extern/BrowserLib/Core/Code/LocalStore.js
vendored
Normal file
40
vis/extern/BrowserLib/Core/Code/LocalStore.js
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
namespace("LocalStore");
|
||||
|
||||
|
||||
LocalStore.Set = function(class_name, class_id, variable_id, data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(Storage) != "undefined")
|
||||
{
|
||||
var name = class_name + "_" + class_id + "_" + variable_id;
|
||||
localStorage[name] = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
console.log("Local Storage Set Error: " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LocalStore.Get = function(class_name, class_id, variable_id, default_data)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(Storage) != "undefined")
|
||||
{
|
||||
var name = class_name + "_" + class_id + "_" + variable_id;
|
||||
var data = localStorage[name]
|
||||
if (data)
|
||||
return JSON.parse(data);
|
||||
}
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
console.log("Local Storage Get Error: " + e.message);
|
||||
}
|
||||
|
||||
return default_data;
|
||||
}
|
||||
83
vis/extern/BrowserLib/Core/Code/Mouse.js
vendored
Normal file
83
vis/extern/BrowserLib/Core/Code/Mouse.js
vendored
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
|
||||
namespace("Mouse");
|
||||
|
||||
|
||||
Mouse.State =(function()
|
||||
{
|
||||
function State(event)
|
||||
{
|
||||
// Get button press states
|
||||
if (typeof event.buttons != "undefined")
|
||||
{
|
||||
// Firefox
|
||||
this.Left = (event.buttons & 1) != 0;
|
||||
this.Right = (event.buttons & 2) != 0;
|
||||
this.Middle = (event.buttons & 4) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Chrome
|
||||
this.Left = (event.button == 0);
|
||||
this.Middle = (event.button == 1);
|
||||
this.Right = (event.button == 2);
|
||||
}
|
||||
|
||||
// Get page-relative mouse position
|
||||
this.Position = DOM.Event.GetMousePosition(event);
|
||||
|
||||
// Get wheel delta
|
||||
var delta = 0;
|
||||
if (event.wheelDelta)
|
||||
delta = event.wheelDelta / 120; // IE/Opera
|
||||
else if (event.detail)
|
||||
delta = -event.detail / 3; // Mozilla
|
||||
this.WheelDelta = delta;
|
||||
|
||||
// Get the mouse position delta
|
||||
// Requires Pointer Lock API support
|
||||
this.PositionDelta = [
|
||||
event.movementX || event.mozMovementX || event.webkitMovementX || 0,
|
||||
event.movementY || event.mozMovementY || event.webkitMovementY || 0
|
||||
];
|
||||
}
|
||||
|
||||
return State;
|
||||
})();
|
||||
|
||||
|
||||
//
|
||||
// Basic Pointer Lock API support
|
||||
// https://developer.mozilla.org/en-US/docs/WebAPI/Pointer_Lock
|
||||
// http://www.chromium.org/developers/design-documents/mouse-lock
|
||||
//
|
||||
// Note that API has not been standardised yet so browsers can implement functions with prefixes
|
||||
//
|
||||
|
||||
|
||||
Mouse.PointerLockSupported = function()
|
||||
{
|
||||
return 'pointerLockElement' in document || 'mozPointerLockElement' in document || 'webkitPointerLockElement' in document;
|
||||
}
|
||||
|
||||
|
||||
Mouse.RequestPointerLock = function(element)
|
||||
{
|
||||
element.requestPointerLock = element.requestPointerLock || element.mozRequestPointerLock || element.webkitRequestPointerLock;
|
||||
if (element.requestPointerLock)
|
||||
element.requestPointerLock();
|
||||
}
|
||||
|
||||
|
||||
Mouse.ExitPointerLock = function()
|
||||
{
|
||||
document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock;
|
||||
if (document.exitPointerLock)
|
||||
document.exitPointerLock();
|
||||
}
|
||||
|
||||
|
||||
// Can use this element to detect whether pointer lock is enabled (returns non-null)
|
||||
Mouse.PointerLockElement = function()
|
||||
{
|
||||
return document.pointerLockElement || document.mozPointerLockElement || document.webkitPointerLockElement;
|
||||
}
|
||||
68
vis/extern/BrowserLib/Core/Code/MurmurHash3.js
vendored
Normal file
68
vis/extern/BrowserLib/Core/Code/MurmurHash3.js
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
namespace("Hash");
|
||||
|
||||
/**
|
||||
* JS Implementation of MurmurHash3 (r136) (as of May 20, 2011)
|
||||
*
|
||||
* @author <a href="mailto:gary.court@gmail.com">Gary Court</a>
|
||||
* @see http://github.com/garycourt/murmurhash-js
|
||||
* @author <a href="mailto:aappleby@gmail.com">Austin Appleby</a>
|
||||
* @see http://sites.google.com/site/murmurhash/
|
||||
*
|
||||
* @param {string} key ASCII only
|
||||
* @param {number} seed Positive integer only
|
||||
* @return {number} 32-bit positive integer hash
|
||||
*/
|
||||
|
||||
Hash.Murmur3 = function(key, seed)
|
||||
{
|
||||
var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i;
|
||||
|
||||
remainder = key.length & 3; // key.length % 4
|
||||
bytes = key.length - remainder;
|
||||
h1 = seed;
|
||||
c1 = 0xcc9e2d51;
|
||||
c2 = 0x1b873593;
|
||||
i = 0;
|
||||
|
||||
while (i < bytes) {
|
||||
k1 =
|
||||
((key.charCodeAt(i) & 0xff)) |
|
||||
((key.charCodeAt(++i) & 0xff) << 8) |
|
||||
((key.charCodeAt(++i) & 0xff) << 16) |
|
||||
((key.charCodeAt(++i) & 0xff) << 24);
|
||||
++i;
|
||||
|
||||
k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff;
|
||||
k1 = (k1 << 15) | (k1 >>> 17);
|
||||
k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff;
|
||||
|
||||
h1 ^= k1;
|
||||
h1 = (h1 << 13) | (h1 >>> 19);
|
||||
h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff;
|
||||
h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16));
|
||||
}
|
||||
|
||||
k1 = 0;
|
||||
|
||||
switch (remainder) {
|
||||
case 3: k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
|
||||
case 2: k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
|
||||
case 1: k1 ^= (key.charCodeAt(i) & 0xff);
|
||||
|
||||
k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
|
||||
k1 = (k1 << 15) | (k1 >>> 17);
|
||||
k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
|
||||
h1 ^= k1;
|
||||
}
|
||||
|
||||
h1 ^= key.length;
|
||||
|
||||
h1 ^= h1 >>> 16;
|
||||
h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff;
|
||||
h1 ^= h1 >>> 13;
|
||||
h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff;
|
||||
h1 ^= h1 >>> 16;
|
||||
|
||||
return h1 >>> 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue