summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/extended/util.js
diff options
context:
space:
mode:
authorxue <>2005-12-05 01:00:16 +0000
committerxue <>2005-12-05 01:00:16 +0000
commitccf76e430b7703db028966a845a966f50956f490 (patch)
tree9762b746f8b7d432dbe5e5cb8f38f90007e0e1b5 /framework/Web/Javascripts/extended/util.js
parent418baf36d477bcbdd6fb4eaf4037ea6a2d93f21c (diff)
Diffstat (limited to 'framework/Web/Javascripts/extended/util.js')
-rw-r--r--framework/Web/Javascripts/extended/util.js90
1 files changed, 90 insertions, 0 deletions
diff --git a/framework/Web/Javascripts/extended/util.js b/framework/Web/Javascripts/extended/util.js
new file mode 100644
index 00000000..1e1fad69
--- /dev/null
+++ b/framework/Web/Javascripts/extended/util.js
@@ -0,0 +1,90 @@
+/**
+ * Test if it is an object and has no constructors.
+ */
+function isAlien(a) { return isObject(a) && typeof a.constructor != 'function' }
+
+/**
+ * isArray?
+ */
+function isArray(a) { return isObject(a) && a.constructor == Array }
+
+/**
+ * isBoolean?
+ */
+function isBoolean(a) { return typeof a == 'boolean' }
+
+/**
+ * isFunction?
+ */
+function isFunction(a) { return typeof a == 'function' }
+
+/**
+ * isNull?
+ */
+function isNull(a) { return typeof a == 'object' && !a }
+
+/**
+ * isNumber?
+ */
+function isNumber(a) { return typeof a == 'number' && isFinite(a) }
+
+/**
+ * isObject?
+ */
+function isObject(a) { return (a && typeof a == 'object') || isFunction(a) }
+
+/**
+ * isRegexp?
+ * we would prefer to use instanceof, but IE/mac is crippled and will choke at it
+ */
+function isRegexp(a) { return a && a.constructor == RegExp }
+
+/**
+ * isString?
+ */
+function isString(a) { return typeof a == 'string' }
+
+/**
+ * isUndefined?
+ */
+function isUndefined(a) { return typeof a == 'undefined' }
+
+/**
+ * isEmpty?
+ */
+function isEmpty(o) {
+ var i, v;
+ if (isObject(o)) {
+ for (i in o) {
+ v = o[i];
+ if (isUndefined(v) && isFunction(v)) {
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
+/**
+ * alias for isUndefined
+ */
+function undef(v) { return isUndefined(v) }
+
+/**
+ * alias for !isUndefined
+ */
+function isdef(v) { return !isUndefined(v) }
+
+/**
+ * true if o is an Element Node or document or window. The last two because it's used for onload events
+ if you specify strict as true, return false for document or window
+ */
+function isElement(o, strict) {
+ return o && isObject(o) && ((!strict && (o==window || o==document)) || o.nodeType == 1)
+}
+
+/**
+ * true if o is an Array or a NodeList, (NodeList in Opera returns a type of function)
+ */
+function isList(o) { return o && isObject(o) && (isArray(o) || o.item) }
+