add nodelist type check

This commit is contained in:
rolux 2012-05-25 21:08:29 +02:00
parent b0000b5169
commit 9aca80c3cb

View file

@ -337,24 +337,35 @@ Ox.typeOf <f> Returns the type of a value
Ox.typeOf = function(value) { Ox.typeOf = function(value) {
return Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); return Object.prototype.toString.call(value).slice(8, -1).toLowerCase();
}; };
(function() { // Firefox 3.6 returns 'Object' instead of 'Arguments',
// Firefox 3.6 returns 'Object' instead of 'Arguments', // Internet Explorer 8 returns 'Object' instead of 'NodeList',
// Internet Explorer 9 returns 'HTMLCollection' instead of 'NodeList', // Internet Explorer 9 returns 'HTMLCollection' instead of 'NodeList',
// Mobile Safari doesn't like null and undefined // Mobile Safari doesn't like null and undefined
var nodelist = Ox.typeOf(document.getElementsByTagName('a')); if (
if ( Ox.typeOf(arguments) != 'arguments'
Ox.typeOf(arguments) != 'arguments' || Ox.typeOf(document.getElementsByTagName('a')) != 'nodelist'
&& nodelist != 'nodelist' || Ox.typeOf(null) != 'null'
|| Ox.typeOf() != 'undefined' || Ox.typeOf() != 'undefined'
) { ) {
Ox.typeOf = function(value) { Ox.typeOf = function(value) {
var type = value && Ox.hasOwn(value, 'callee') ? 'arguments' var ret = Object.prototype.toString.call(
: value === null ? 'null' value
: value === void 0 ? 'undefined' ).slice(8, -1).toLowerCase();
: Object.prototype.toString.call( if (typeof value.callee == 'function') {
value ret = arguments;
).slice(8, -1).toLowerCase(); } else if (
return type == nodelist ? 'nodelist' : type; ret == 'htmlcollection' || (
}; typeof value == 'object'
} && typeof value.item != 'undefined'
})(); && typeof value.length == 'number'
)
) {
ret = 'nodelist'
} else if (value === null) {
ret = 'null';
} else if (value === void 0) {
ret = 'undefined'
}
return ret;
};
}