vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
7.7 KiB

  1. // Internet Explorer 8 and older does not support Array.indexOf, so we define
  2. // it here in that case.
  3. // http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
  4. if(!Array.prototype.indexOf) {
  5. Array.prototype.indexOf = function(obj){
  6. for(var i = 0; i < this.length; i++){
  7. if(this[i] == obj){
  8. return i;
  9. }
  10. }
  11. return -1;
  12. };
  13. try {
  14. console.log("Warning: Ancient browser detected. Please update your browser");
  15. }
  16. catch (err) {
  17. }
  18. }
  19. // Internet Explorer 8 and older does not support Array.forEach, so we define
  20. // it here in that case.
  21. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
  22. if (!Array.prototype.forEach) {
  23. Array.prototype.forEach = function(fn, scope) {
  24. for(var i = 0, len = this.length; i < len; ++i) {
  25. fn.call(scope || this, this[i], i, this);
  26. }
  27. }
  28. }
  29. // Internet Explorer 8 and older does not support Array.map, so we define it
  30. // here in that case.
  31. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
  32. // Production steps of ECMA-262, Edition 5, 15.4.4.19
  33. // Reference: http://es5.github.com/#x15.4.4.19
  34. if (!Array.prototype.map) {
  35. Array.prototype.map = function(callback, thisArg) {
  36. var T, A, k;
  37. if (this == null) {
  38. throw new TypeError(" this is null or not defined");
  39. }
  40. // 1. Let O be the result of calling ToObject passing the |this| value as the argument.
  41. var O = Object(this);
  42. // 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
  43. // 3. Let len be ToUint32(lenValue).
  44. var len = O.length >>> 0;
  45. // 4. If IsCallable(callback) is false, throw a TypeError exception.
  46. // See: http://es5.github.com/#x9.11
  47. if (typeof callback !== "function") {
  48. throw new TypeError(callback + " is not a function");
  49. }
  50. // 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
  51. if (thisArg) {
  52. T = thisArg;
  53. }
  54. // 6. Let A be a new array created as if by the expression new Array(len) where Array is
  55. // the standard built-in constructor with that name and len is the value of len.
  56. A = new Array(len);
  57. // 7. Let k be 0
  58. k = 0;
  59. // 8. Repeat, while k < len
  60. while(k < len) {
  61. var kValue, mappedValue;
  62. // a. Let Pk be ToString(k).
  63. // This is implicit for LHS operands of the in operator
  64. // b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
  65. // This step can be combined with c
  66. // c. If kPresent is true, then
  67. if (k in O) {
  68. // i. Let kValue be the result of calling the Get internal method of O with argument Pk.
  69. kValue = O[ k ];
  70. // ii. Let mappedValue be the result of calling the Call internal method of callback
  71. // with T as the this value and argument list containing kValue, k, and O.
  72. mappedValue = callback.call(T, kValue, k, O);
  73. // iii. Call the DefineOwnProperty internal method of A with arguments
  74. // Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
  75. // and false.
  76. // In browsers that support Object.defineProperty, use the following:
  77. // Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
  78. // For best browser support, use the following:
  79. A[ k ] = mappedValue;
  80. }
  81. // d. Increase k by 1.
  82. k++;
  83. }
  84. // 9. return A
  85. return A;
  86. };
  87. }
  88. // Internet Explorer 8 and older does not support Array.filter, so we define it
  89. // here in that case.
  90. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter
  91. if (!Array.prototype.filter) {
  92. Array.prototype.filter = function(fun /*, thisp */) {
  93. "use strict";
  94. if (this == null) {
  95. throw new TypeError();
  96. }
  97. var t = Object(this);
  98. var len = t.length >>> 0;
  99. if (typeof fun != "function") {
  100. throw new TypeError();
  101. }
  102. var res = [];
  103. var thisp = arguments[1];
  104. for (var i = 0; i < len; i++) {
  105. if (i in t) {
  106. var val = t[i]; // in case fun mutates this
  107. if (fun.call(thisp, val, i, t))
  108. res.push(val);
  109. }
  110. }
  111. return res;
  112. };
  113. }
  114. // Internet Explorer 8 and older does not support Object.keys, so we define it
  115. // here in that case.
  116. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys
  117. if (!Object.keys) {
  118. Object.keys = (function () {
  119. var hasOwnProperty = Object.prototype.hasOwnProperty,
  120. hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
  121. dontEnums = [
  122. 'toString',
  123. 'toLocaleString',
  124. 'valueOf',
  125. 'hasOwnProperty',
  126. 'isPrototypeOf',
  127. 'propertyIsEnumerable',
  128. 'constructor'
  129. ],
  130. dontEnumsLength = dontEnums.length;
  131. return function (obj) {
  132. if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) {
  133. throw new TypeError('Object.keys called on non-object');
  134. }
  135. var result = [];
  136. for (var prop in obj) {
  137. if (hasOwnProperty.call(obj, prop)) result.push(prop);
  138. }
  139. if (hasDontEnumBug) {
  140. for (var i=0; i < dontEnumsLength; i++) {
  141. if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
  142. }
  143. }
  144. return result;
  145. }
  146. })()
  147. }
  148. // Internet Explorer 8 and older does not support Array.isArray,
  149. // so we define it here in that case.
  150. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/isArray
  151. if(!Array.isArray) {
  152. Array.isArray = function (vArg) {
  153. return Object.prototype.toString.call(vArg) === "[object Array]";
  154. };
  155. }
  156. // Internet Explorer 8 and older does not support Function.bind,
  157. // so we define it here in that case.
  158. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
  159. if (!Function.prototype.bind) {
  160. Function.prototype.bind = function (oThis) {
  161. if (typeof this !== "function") {
  162. // closest thing possible to the ECMAScript 5 internal IsCallable function
  163. throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
  164. }
  165. var aArgs = Array.prototype.slice.call(arguments, 1),
  166. fToBind = this,
  167. fNOP = function () {},
  168. fBound = function () {
  169. return fToBind.apply(this instanceof fNOP && oThis
  170. ? this
  171. : oThis,
  172. aArgs.concat(Array.prototype.slice.call(arguments)));
  173. };
  174. fNOP.prototype = this.prototype;
  175. fBound.prototype = new fNOP();
  176. return fBound;
  177. };
  178. }
  179. // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create
  180. if (!Object.create) {
  181. Object.create = function (o) {
  182. if (arguments.length > 1) {
  183. throw new Error('Object.create implementation only accepts the first parameter.');
  184. }
  185. function F() {}
  186. F.prototype = o;
  187. return new F();
  188. };
  189. }
  190. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
  191. if (!Function.prototype.bind) {
  192. Function.prototype.bind = function (oThis) {
  193. if (typeof this !== "function") {
  194. // closest thing possible to the ECMAScript 5 internal IsCallable function
  195. throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
  196. }
  197. var aArgs = Array.prototype.slice.call(arguments, 1),
  198. fToBind = this,
  199. fNOP = function () {},
  200. fBound = function () {
  201. return fToBind.apply(this instanceof fNOP && oThis
  202. ? this
  203. : oThis,
  204. aArgs.concat(Array.prototype.slice.call(arguments)));
  205. };
  206. fNOP.prototype = this.prototype;
  207. fBound.prototype = new fNOP();
  208. return fBound;
  209. };
  210. }