_common.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Generated by CoffeeScript 1.6.3
  2. var common;
  3. module.exports = common = {
  4. /*
  5. Checks to see if o is an object, and it isn't an instance
  6. of some class.
  7. */
  8. isBareObject: function(o) {
  9. if ((o != null) && o.constructor === Object) {
  10. return true;
  11. }
  12. return false;
  13. },
  14. /*
  15. Returns type of an object, including:
  16. undefined, null, string, number, array,
  17. arguments, element, textnode, whitespace, and object
  18. */
  19. typeOf: function(item) {
  20. var _ref;
  21. if (item === null) {
  22. return 'null';
  23. }
  24. if (typeof item !== 'object') {
  25. return typeof item;
  26. }
  27. if (Array.isArray(item)) {
  28. return 'array';
  29. }
  30. if (item.nodeName) {
  31. if (item.nodeType === 1) {
  32. return 'element';
  33. }
  34. if (item.nodeType === 3) {
  35. return (_ref = /\S/.test(item.nodeValue)) != null ? _ref : {
  36. 'textnode': 'whitespace'
  37. };
  38. }
  39. } else if (typeof item.length === 'number') {
  40. if (item.callee) {
  41. return 'arguments';
  42. }
  43. }
  44. return typeof item;
  45. },
  46. clone: function(item, includePrototype) {
  47. if (includePrototype == null) {
  48. includePrototype = false;
  49. }
  50. switch (common.typeOf(item)) {
  51. case 'array':
  52. return common._cloneArray(item, includePrototype);
  53. case 'object':
  54. return common._cloneObject(item, includePrototype);
  55. default:
  56. return item;
  57. }
  58. },
  59. /*
  60. Deep clone of an object.
  61. From MooTools
  62. */
  63. _cloneObject: function(o, includePrototype) {
  64. var clone, key;
  65. if (includePrototype == null) {
  66. includePrototype = false;
  67. }
  68. if (common.isBareObject(o)) {
  69. clone = {};
  70. for (key in o) {
  71. clone[key] = common.clone(o[key], includePrototype);
  72. }
  73. return clone;
  74. } else {
  75. if (!includePrototype) {
  76. return o;
  77. }
  78. if (o instanceof Function) {
  79. return o;
  80. }
  81. clone = Object.create(o.constructor.prototype);
  82. for (key in o) {
  83. if (o.hasOwnProperty(key)) {
  84. clone[key] = common.clone(o[key], includePrototype);
  85. }
  86. }
  87. return clone;
  88. }
  89. },
  90. /*
  91. Deep clone of an array.
  92. From MooTools
  93. */
  94. _cloneArray: function(a, includePrototype) {
  95. var clone, i;
  96. if (includePrototype == null) {
  97. includePrototype = false;
  98. }
  99. i = a.length;
  100. clone = new Array(i);
  101. while (i--) {
  102. clone[i] = common.clone(a[i], includePrototype);
  103. }
  104. return clone;
  105. }
  106. };