Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dojox.lang.utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dojox.lang.utils"] = true;
3
dojo.provide("dojox.lang.utils");
4
 
5
(function(){
6
	var empty = {}, du = dojox.lang.utils;
7
 
8
	dojo.mixin(dojox.lang.utils, {
9
		coerceType: function(target, source){
10
			switch(typeof target){
11
				case "number":	return Number(eval("(" + source + ")"));
12
				case "string":	return String(source);
13
				case "boolean":	return Boolean(eval("(" + source + ")"));
14
			}
15
			return eval("(" + source + ")");
16
		},
17
 
18
		updateWithObject: function(target, source, conv){
19
			// summary: updates an existing object in place with properties from an "source" object.
20
			// target: Object: the "target" object to be updated
21
			// source: Object: the "source" object, whose properties will be used to source the existed object.
22
			// conv: Boolean?: force conversion to the original type
23
			if(!source){ return target; }
24
			for(var x in target){
25
				if(x in source && !(x in empty)){
26
					var t = target[x];
27
					if(t && typeof t == "object"){
28
						du.updateObject(t, source[x]);
29
					}else{
30
						target[x] = conv ? du.coerceType(t, source[x]) : dojo.clone(source[x]);
31
					}
32
				}
33
			}
34
			return target;	// Object
35
		},
36
 
37
		updateWithPattern: function(target, source, pattern, conv){
38
			// summary: updates an existing object in place with properties from an "source" object.
39
			// target: Object: the "target" object to be updated
40
			// source: Object: the "source" object, whose properties will be used to source the existed object.
41
			// pattern: Array: an array of properties to be copied
42
			// conv: Boolean?: force conversion to the original type
43
			if(!source || !pattern){ return target; }
44
			for(var x in pattern){
45
				if(x in source && !(x in empty)){
46
					target[x] = conv ? du.coerceType(pattern[x], source[x]) : dojo.clone(source[x]);
47
				}
48
			}
49
			return target;	// Object
50
		}
51
	});
52
})();
53
 
54
}