From 9aca80c3cbec5ec9577835e6b9e8a14d85bcbeab Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 25 May 2012 21:08:29 +0200 Subject: [PATCH] add nodelist type check --- source/Ox/js/Type.js | 53 ++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js index caa785a5..d0f8066b 100644 --- a/source/Ox/js/Type.js +++ b/source/Ox/js/Type.js @@ -337,24 +337,35 @@ Ox.typeOf Returns the type of a value Ox.typeOf = function(value) { return Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); }; -(function() { - // Firefox 3.6 returns 'Object' instead of 'Arguments', - // Internet Explorer 9 returns 'HTMLCollection' instead of 'NodeList', - // Mobile Safari doesn't like null and undefined - var nodelist = Ox.typeOf(document.getElementsByTagName('a')); - if ( - Ox.typeOf(arguments) != 'arguments' - && nodelist != 'nodelist' - || Ox.typeOf() != 'undefined' - ) { - Ox.typeOf = function(value) { - var type = value && Ox.hasOwn(value, 'callee') ? 'arguments' - : value === null ? 'null' - : value === void 0 ? 'undefined' - : Object.prototype.toString.call( - value - ).slice(8, -1).toLowerCase(); - return type == nodelist ? 'nodelist' : type; - }; - } -})(); +// Firefox 3.6 returns 'Object' instead of 'Arguments', +// Internet Explorer 8 returns 'Object' instead of 'NodeList', +// Internet Explorer 9 returns 'HTMLCollection' instead of 'NodeList', +// Mobile Safari doesn't like null and undefined +if ( + Ox.typeOf(arguments) != 'arguments' + || Ox.typeOf(document.getElementsByTagName('a')) != 'nodelist' + || Ox.typeOf(null) != 'null' + || Ox.typeOf() != 'undefined' +) { + Ox.typeOf = function(value) { + var ret = Object.prototype.toString.call( + value + ).slice(8, -1).toLowerCase(); + if (typeof value.callee == 'function') { + ret = arguments; + } else if ( + 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; + }; +}