oldie-polyfills.src.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* *
  2. *
  3. * (c) 2010-2019 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * Simple polyfills for array functions in old IE browsers (6, 7 and 8) in
  8. * Highcharts v7+. These polyfills are sufficient for Highcharts to work, but
  9. * for fully compatible polyfills, see MDN.
  10. *
  11. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  12. *
  13. * */
  14. /* global document */
  15. 'use strict';
  16. /* eslint-disable no-extend-native */
  17. if (!Array.prototype.forEach) {
  18. Array.prototype.forEach = function (fn, thisArg) {
  19. var i = 0, len = this.length;
  20. for (; i < len; i++) {
  21. if (typeof this[i] !== 'undefined' && // added check
  22. fn.call(thisArg, this[i], i, this) === false) {
  23. return i;
  24. }
  25. }
  26. };
  27. }
  28. if (!Array.prototype.map) {
  29. Array.prototype.map = function (fn
  30. // @todo support optional ctx
  31. ) {
  32. var results = [], i = 0, len = this.length;
  33. for (; i < len; i++) {
  34. results[i] = fn.call(this[i], this[i], i, this);
  35. }
  36. return results;
  37. };
  38. }
  39. if (!Array.prototype.indexOf) {
  40. Array.prototype.indexOf = function (member, fromIndex) {
  41. var arr = this, // #8874
  42. len, i = fromIndex || 0; // #8346
  43. if (arr) {
  44. len = arr.length;
  45. for (; i < len; i++) {
  46. if (arr[i] === member) {
  47. return i;
  48. }
  49. }
  50. }
  51. return -1;
  52. };
  53. }
  54. if (!Array.prototype.filter) {
  55. Array.prototype.filter = function (fn
  56. // @todo support optional ctx
  57. ) {
  58. var ret = [], i = 0, length = this.length;
  59. for (; i < length; i++) {
  60. if (fn(this[i], i)) {
  61. ret.push(this[i]);
  62. }
  63. }
  64. return ret;
  65. };
  66. }
  67. if (!Array.prototype.some) {
  68. Array.prototype.some = function (fn, thisArg) {
  69. var i = 0, len = this.length;
  70. for (; i < len; i++) {
  71. if (fn.call(thisArg, this[i], i, this) === true) {
  72. return true;
  73. }
  74. }
  75. return false;
  76. };
  77. }
  78. if (!Array.prototype.reduce) {
  79. Array.prototype.reduce = function (func, initialValue) {
  80. var context = this, i = arguments.length > 1 ? 0 : 1, accumulator = arguments.length > 1 ? initialValue : this[0], len = this.length;
  81. for (; i < len; ++i) {
  82. accumulator = func.call(context, accumulator, this[i], i, this);
  83. }
  84. return accumulator;
  85. };
  86. }
  87. if (!Object.keys) {
  88. Object.keys = function (obj) {
  89. var result = [], prop;
  90. for (prop in obj) {
  91. if (Object.hasOwnProperty.call(obj, prop)) {
  92. result.push(prop);
  93. }
  94. }
  95. return result;
  96. };
  97. }
  98. // Add a getElementsByClassName function if the browser doesn't have one
  99. // Limitation: only works with one class name
  100. // Copyright: Eike Send http://eike.se/nd
  101. // License: MIT License
  102. if (!document.getElementsByClassName) {
  103. document.getElementsByClassName = function (search) {
  104. var d = document, elements, pattern, i, results = [];
  105. if (d.querySelectorAll) { // IE8
  106. return d.querySelectorAll('.' + search);
  107. }
  108. if (d.evaluate) { // IE6, IE7
  109. pattern = './/*[contains(concat(\' \', @class, \' \'), \' ' +
  110. search + ' \')]';
  111. elements = d.evaluate(pattern, d, null, 0, null);
  112. while ((i = elements.iterateNext())) {
  113. results.push(i);
  114. }
  115. }
  116. else {
  117. elements = d.getElementsByTagName('*');
  118. pattern = new RegExp('(^|\\s)' + search + '(\\s|$)');
  119. for (i = 0; i < elements.length; i++) {
  120. if (pattern.test(elements[i].className)) {
  121. results.push(elements[i]);
  122. }
  123. }
  124. }
  125. return results;
  126. };
  127. }