Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.lang.common");
12
dojo.lang.inherits = function (subclass, superclass) {
13
	if (!dojo.lang.isFunction(superclass)) {
14
		dojo.raise("dojo.inherits: superclass argument [" + superclass + "] must be a function (subclass: [" + subclass + "']");
15
	}
16
	subclass.prototype = new superclass();
17
	subclass.prototype.constructor = subclass;
18
	subclass.superclass = superclass.prototype;
19
	subclass["super"] = superclass.prototype;
20
};
21
dojo.lang._mixin = function (obj, props) {
22
	var tobj = {};
23
	for (var x in props) {
24
		if ((typeof tobj[x] == "undefined") || (tobj[x] != props[x])) {
25
			obj[x] = props[x];
26
		}
27
	}
28
	if (dojo.render.html.ie && (typeof (props["toString"]) == "function") && (props["toString"] != obj["toString"]) && (props["toString"] != tobj["toString"])) {
29
		obj.toString = props.toString;
30
	}
31
	return obj;
32
};
33
dojo.lang.mixin = function (obj, props) {
34
	for (var i = 1, l = arguments.length; i < l; i++) {
35
		dojo.lang._mixin(obj, arguments[i]);
36
	}
37
	return obj;
38
};
39
dojo.lang.extend = function (constructor, props) {
40
	for (var i = 1, l = arguments.length; i < l; i++) {
41
		dojo.lang._mixin(constructor.prototype, arguments[i]);
42
	}
43
	return constructor;
44
};
45
dojo.inherits = dojo.lang.inherits;
46
dojo.mixin = dojo.lang.mixin;
47
dojo.extend = dojo.lang.extend;
48
dojo.lang.find = function (array, value, identity, findLast) {
49
	if (!dojo.lang.isArrayLike(array) && dojo.lang.isArrayLike(value)) {
50
		dojo.deprecated("dojo.lang.find(value, array)", "use dojo.lang.find(array, value) instead", "0.5");
51
		var temp = array;
52
		array = value;
53
		value = temp;
54
	}
55
	var isString = dojo.lang.isString(array);
56
	if (isString) {
57
		array = array.split("");
58
	}
59
	if (findLast) {
60
		var step = -1;
61
		var i = array.length - 1;
62
		var end = -1;
63
	} else {
64
		var step = 1;
65
		var i = 0;
66
		var end = array.length;
67
	}
68
	if (identity) {
69
		while (i != end) {
70
			if (array[i] === value) {
71
				return i;
72
			}
73
			i += step;
74
		}
75
	} else {
76
		while (i != end) {
77
			if (array[i] == value) {
78
				return i;
79
			}
80
			i += step;
81
		}
82
	}
83
	return -1;
84
};
85
dojo.lang.indexOf = dojo.lang.find;
86
dojo.lang.findLast = function (array, value, identity) {
87
	return dojo.lang.find(array, value, identity, true);
88
};
89
dojo.lang.lastIndexOf = dojo.lang.findLast;
90
dojo.lang.inArray = function (array, value) {
91
	return dojo.lang.find(array, value) > -1;
92
};
93
dojo.lang.isObject = function (it) {
94
	if (typeof it == "undefined") {
95
		return false;
96
	}
97
	return (typeof it == "object" || it === null || dojo.lang.isArray(it) || dojo.lang.isFunction(it));
98
};
99
dojo.lang.isArray = function (it) {
100
	return (it && it instanceof Array || typeof it == "array");
101
};
102
dojo.lang.isArrayLike = function (it) {
103
	if ((!it) || (dojo.lang.isUndefined(it))) {
104
		return false;
105
	}
106
	if (dojo.lang.isString(it)) {
107
		return false;
108
	}
109
	if (dojo.lang.isFunction(it)) {
110
		return false;
111
	}
112
	if (dojo.lang.isArray(it)) {
113
		return true;
114
	}
115
	if ((it.tagName) && (it.tagName.toLowerCase() == "form")) {
116
		return false;
117
	}
118
	if (dojo.lang.isNumber(it.length) && isFinite(it.length)) {
119
		return true;
120
	}
121
	return false;
122
};
123
dojo.lang.isFunction = function (it) {
124
	return (it instanceof Function || typeof it == "function");
125
};
126
(function () {
127
	if ((dojo.render.html.capable) && (dojo.render.html["safari"])) {
128
		dojo.lang.isFunction = function (it) {
129
			if ((typeof (it) == "function") && (it == "[object NodeList]")) {
130
				return false;
131
			}
132
			return (it instanceof Function || typeof it == "function");
133
		};
134
	}
135
})();
136
dojo.lang.isString = function (it) {
137
	return (typeof it == "string" || it instanceof String);
138
};
139
dojo.lang.isAlien = function (it) {
140
	if (!it) {
141
		return false;
142
	}
143
	return !dojo.lang.isFunction(it) && /\{\s*\[native code\]\s*\}/.test(String(it));
144
};
145
dojo.lang.isBoolean = function (it) {
146
	return (it instanceof Boolean || typeof it == "boolean");
147
};
148
dojo.lang.isNumber = function (it) {
149
	return (it instanceof Number || typeof it == "number");
150
};
151
dojo.lang.isUndefined = function (it) {
152
	return ((typeof (it) == "undefined") && (it == undefined));
153
};
154