/** X3DOM Runtime, http://www.x3dom.org/ 1.6.2 - 8f5655cec1951042e852ee9def292c9e0194186b - Sat Dec 20 00:03:52 2014 +0100 *//* * X3DOM JavaScript Library * http://www.x3dom.org * * (C)2009 Fraunhofer IGD, Darmstadt, Germany * Dual licensed under the MIT and GPL * * Based on code originally provided by * Philip Taylor: http://philip.html5.org */ // Add some JS1.6 Array functions: // (This only includes the non-prototype versions, because otherwise it messes up 'for in' loops) if (!Array.forEach) { /* * Function: Array.forEach * * Javascript array forEach() method calls a function for each element in the array. * * Parameters: * * array - The array * fun - Function to test each element of the array * thisp - Object to use as __this__ when executing callback * * Returns: * * The created array */ Array.forEach = function (array, fun, thisp) { var len = array.length; for (var i = 0; i < len; i++) { if (i in array) { fun.call(thisp, array[i], i, array); } } }; } if (!Array.map) { Array.map = function(array, fun, thisp) { var len = array.length; var res = []; for (var i = 0; i < len; i++) { if (i in array) { res[i] = fun.call(thisp, array[i], i, array); } } return res; }; } if (!Array.filter) { Array.filter = function(array, fun, thisp) { var len = array.length; var res = []; for (var i = 0; i < len; i++) { if (i in array) { var val = array[i]; if (fun.call(thisp, val, i, array)) { res.push(val); } } } return res; }; } /* * X3DOM JavaScript Library * http://www.x3dom.org * * (C)2009 Fraunhofer IGD, Darmstadt, Germany * Dual licensed under the MIT and GPL * * Based on code originally provided by * Philip Taylor: http://philip.html5.org */ /** * The Namespace container for x3dom objects. * @namespace x3dom * */ var x3dom = { canvases : [], x3dNS : 'http://www.web3d.org/specifications/x3d-namespace', x3dextNS : 'http://philip.html5.org/x3d/ext', xsltNS : 'http://www.w3.org/1999/XSL/x3dom.Transform', xhtmlNS : 'http://www.w3.org/1999/xhtml' }; /** * The x3dom.nodeTypes namespace. * @namespace x3dom.nodeTypes * */ x3dom.nodeTypes = {}; /** * The x3dom.nodeTypesLC namespace. Stores nodetypes in lowercase * @namespace x3dom.nodeTypesLC * */ x3dom.nodeTypesLC = {}; /** * The x3dom.components namespace. * @namespace x3dom.components * */ x3dom.components = {}; /** Cache for primitive nodes (Box, Sphere, etc.) */ x3dom.geoCache = []; /** Stores information about Browser and hardware capabilities */ x3dom.caps = { PLATFORM: navigator.platform, AGENT: navigator.userAgent, RENDERMODE: "HARDWARE" }; /** Registers the node defined by @p nodeDef. The node is registered with the given @p nodeTypeName and @p componentName. @param nodeTypeName the name of the node type (e.g. Material, Shape, ...) @param componentName the name of the component the node type belongs to @param nodeDef the definition of the node type */ x3dom.registerNodeType = function(nodeTypeName, componentName, nodeDef) { //console.log("Registering nodetype [" + nodeTypeName + "] in component [" + componentName + "]"); if (x3dom.components[componentName] === undefined) { x3dom.components[componentName] = {}; } nodeDef._typeName = nodeTypeName; nodeDef._compName = componentName; x3dom.components[componentName][nodeTypeName] = nodeDef; x3dom.nodeTypes[nodeTypeName] = nodeDef; x3dom.nodeTypesLC[nodeTypeName.toLowerCase()] = nodeDef; }; /** Test if node is registered X3D element */ x3dom.isX3DElement = function(node) { // x3dom.debug.logInfo("node=" + node + "node.nodeType=" + node.nodeType + ", node.localName=" + node.localName + ", "); var name = (node.nodeType === Node.ELEMENT_NODE && node.localName) ? node.localName.toLowerCase() : null; return (name && (x3dom.nodeTypes[node.localName] || x3dom.nodeTypesLC[name] || name == "x3d" || name == "websg" || name == "route")); }; /* * Function: x3dom.extend * * Returns a prototype object suitable for extending the given class * _f_. Rather than constructing a new instance of _f_ to serve as * the prototype (which unnecessarily runs the constructor on the created * prototype object, potentially polluting it), an anonymous function is * generated internally that shares the same prototype: * * Parameters: * f - Method f a constructor * * Returns: * A suitable prototype object * * See Also: * Douglas Crockford's essay on . */ // TODO; unify with defineClass, which does basically the same x3dom.extend = function(f) { function G() {} G.prototype = f.prototype || f; return new G(); }; /** * Function x3dom.getStyle * * Computes the value of the specified CSS property p on the * specified element e. * * Parameters: * oElm - The element on which to compute the CSS property * strCssRule - The name of the CSS property * * Returns: * * The computed value of the CSS property */ x3dom.getStyle = function(oElm, strCssRule) { var strValue = ""; var style = document.defaultView.getComputedStyle ? document.defaultView.getComputedStyle(oElm, null) : null; if (style) { strValue = style.getPropertyValue(strCssRule); } else if(oElm.currentStyle){ strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); }); strValue = oElm.currentStyle[strCssRule]; } return strValue; }; /** Utility function for defining a new class. @param parent the parent class of the new class @param ctor the constructor of the new class @param methods an object literal containing the methods of the new class @return the constructor function of the new class */ function defineClass(parent, ctor, methods) { if (parent) { function Inheritance() {} Inheritance.prototype = parent.prototype; ctor.prototype = new Inheritance(); ctor.prototype.constructor = ctor; ctor.superClass = parent; } if (methods) { for (var m in methods) { ctor.prototype[m] = methods[m]; } } return ctor; } /** Utility function for testing a node type. @param object the object to test @param clazz the type of the class @return true or false */ x3dom.isa = function(object, clazz) { /* if (!object || !object.constructor || object.constructor.superClass === undefined) { return false; } if (object.constructor === clazz) { return true; } function f(c) { if (c === clazz) { return true; } if (c.prototype && c.prototype.constructor && c.prototype.constructor.superClass) { return f(c.prototype.constructor.superClass); } return false; } return f(object.constructor.superClass); */ return (object instanceof clazz); }; /// helper x3dom.getGlobal = function () { return (function () { return this; }).call(null); }; /** * Load javascript file either by performing an synchronous jax request * an eval'ing the response or by dynamically creating a