hue.utils.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. if (!('clean' in Array.prototype)) {
  17. Array.prototype.clean = function (deleteValue) {
  18. for (var i = 0; i < this.length; i++) {
  19. if (this[i] == deleteValue) {
  20. this.splice(i, 1);
  21. i--;
  22. }
  23. }
  24. return this;
  25. };
  26. }
  27. if (!('move' in Array.prototype)) {
  28. Array.prototype.move = function (old_index, new_index) {
  29. if (new_index >= this.length) {
  30. var k = new_index - this.length;
  31. while ((k--) + 1) {
  32. this.push(undefined);
  33. }
  34. }
  35. this.splice(new_index, 0, this.splice(old_index, 1)[0]);
  36. return this;
  37. };
  38. }
  39. if (!('indexOf' in Array.prototype)) {
  40. Array.prototype.indexOf = function (needle) {
  41. for (var i = 0; i < this.length; i++) {
  42. if (this[i] === needle) {
  43. return i;
  44. }
  45. }
  46. return -1;
  47. };
  48. }
  49. // adding missing .filter for IE8
  50. if (!('filter' in Array.prototype)) {
  51. Array.prototype.filter = function (filter, that /*opt*/) {
  52. var other = [], v;
  53. for (var i = 0, n = this.length; i < n; i++)
  54. if (i in this && filter.call(that, v = this[i], i, this))
  55. other.push(v);
  56. return other;
  57. };
  58. }