Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | 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
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.lang.extras");
14
dojo.require("dojo.lang.common");
15
dojo.lang.setTimeout = function (func, delay) {
16
	var context = window, argsStart = 2;
17
	if (!dojo.lang.isFunction(func)) {
18
		context = func;
19
		func = delay;
20
		delay = arguments[2];
21
		argsStart++;
22
	}
23
	if (dojo.lang.isString(func)) {
24
		func = context[func];
25
	}
26
	var args = [];
27
	for (var i = argsStart; i < arguments.length; i++) {
28
		args.push(arguments[i]);
29
	}
30
	return dojo.global().setTimeout(function () {
31
		func.apply(context, args);
32
	}, delay);
33
};
34
dojo.lang.clearTimeout = function (timer) {
35
	dojo.global().clearTimeout(timer);
36
};
37
dojo.lang.getNameInObj = function (ns, item) {
38
	if (!ns) {
39
		ns = dj_global;
40
	}
41
	for (var x in ns) {
42
		if (ns[x] === item) {
43
			return new String(x);
44
		}
45
	}
46
	return null;
47
};
48
dojo.lang.shallowCopy = function (obj, deep) {
49
	var i, ret;
50
	if (obj === null) {
51
		return null;
52
	}
53
	if (dojo.lang.isObject(obj)) {
54
		ret = new obj.constructor();
55
		for (i in obj) {
56
			if (dojo.lang.isUndefined(ret[i])) {
57
				ret[i] = deep ? dojo.lang.shallowCopy(obj[i], deep) : obj[i];
58
			}
59
		}
60
	} else {
61
		if (dojo.lang.isArray(obj)) {
62
			ret = [];
63
			for (i = 0; i < obj.length; i++) {
64
				ret[i] = deep ? dojo.lang.shallowCopy(obj[i], deep) : obj[i];
65
			}
66
		} else {
67
			ret = obj;
68
		}
69
	}
70
	return ret;
71
};
72
dojo.lang.firstValued = function () {
73
	for (var i = 0; i < arguments.length; i++) {
74
		if (typeof arguments[i] != "undefined") {
75
			return arguments[i];
76
		}
77
	}
78
	return undefined;
79
};
80
dojo.lang.getObjPathValue = function (objpath, context, create) {
81
	with (dojo.parseObjPath(objpath, context, create)) {
82
		return dojo.evalProp(prop, obj, create);
83
	}
84
};
85
dojo.lang.setObjPathValue = function (objpath, value, context, create) {
86
	dojo.deprecated("dojo.lang.setObjPathValue", "use dojo.parseObjPath and the '=' operator", "0.6");
87
	if (arguments.length < 4) {
88
		create = true;
89
	}
90
	with (dojo.parseObjPath(objpath, context, create)) {
91
		if (obj && (create || (prop in obj))) {
92
			obj[prop] = value;
93
		}
94
	}
95
};
96