123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Generated by CoffeeScript 1.6.3
- var common;
- module.exports = common = {
- /*
- Checks to see if o is an object, and it isn't an instance
- of some class.
- */
- isBareObject: function(o) {
- if ((o != null) && o.constructor === Object) {
- return true;
- }
- return false;
- },
- /*
- Returns type of an object, including:
- undefined, null, string, number, array,
- arguments, element, textnode, whitespace, and object
- */
- typeOf: function(item) {
- var _ref;
- if (item === null) {
- return 'null';
- }
- if (typeof item !== 'object') {
- return typeof item;
- }
- if (Array.isArray(item)) {
- return 'array';
- }
- if (item.nodeName) {
- if (item.nodeType === 1) {
- return 'element';
- }
- if (item.nodeType === 3) {
- return (_ref = /\S/.test(item.nodeValue)) != null ? _ref : {
- 'textnode': 'whitespace'
- };
- }
- } else if (typeof item.length === 'number') {
- if (item.callee) {
- return 'arguments';
- }
- }
- return typeof item;
- },
- clone: function(item, includePrototype) {
- if (includePrototype == null) {
- includePrototype = false;
- }
- switch (common.typeOf(item)) {
- case 'array':
- return common._cloneArray(item, includePrototype);
- case 'object':
- return common._cloneObject(item, includePrototype);
- default:
- return item;
- }
- },
- /*
- Deep clone of an object.
- From MooTools
- */
- _cloneObject: function(o, includePrototype) {
- var clone, key;
- if (includePrototype == null) {
- includePrototype = false;
- }
- if (common.isBareObject(o)) {
- clone = {};
- for (key in o) {
- clone[key] = common.clone(o[key], includePrototype);
- }
- return clone;
- } else {
- if (!includePrototype) {
- return o;
- }
- if (o instanceof Function) {
- return o;
- }
- clone = Object.create(o.constructor.prototype);
- for (key in o) {
- if (o.hasOwnProperty(key)) {
- clone[key] = common.clone(o[key], includePrototype);
- }
- }
- return clone;
- }
- },
- /*
- Deep clone of an array.
- From MooTools
- */
- _cloneArray: function(a, includePrototype) {
- var clone, i;
- if (includePrototype == null) {
- includePrototype = false;
- }
- i = a.length;
- clone = new Array(i);
- while (i--) {
- clone[i] = common.clone(a[i], includePrototype);
- }
- return clone;
- }
- };
|