diff options
| author | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
|---|---|---|
| committer | Tristan Zur <tzur@web.web.ccwn.org> | 2014-03-27 22:27:47 +0100 |
| commit | b62676ca5d3d6f6ba3f019ea3f99722e165a98d8 (patch) | |
| tree | 86722cb80f07d4569f90088eeaea2fc2f6e2ef94 /js/dojo-1.6/dojox/lang/utils.js | |
Diffstat (limited to 'js/dojo-1.6/dojox/lang/utils.js')
| -rw-r--r-- | js/dojo-1.6/dojox/lang/utils.js | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojox/lang/utils.js b/js/dojo-1.6/dojox/lang/utils.js new file mode 100644 index 0000000..7d42f41 --- /dev/null +++ b/js/dojo-1.6/dojox/lang/utils.js @@ -0,0 +1,114 @@ +/*
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
+ Available via Academic Free License >= 2.1 OR the modified BSD license.
+ see: http://dojotoolkit.org/license for details
+*/
+
+
+if(!dojo._hasResource["dojox.lang.utils"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.lang.utils"] = true;
+dojo.provide("dojox.lang.utils");
+
+(function(){
+ var empty = {}, du = dojox.lang.utils, opts = Object.prototype.toString;
+
+ var clone = function(o){
+ if(o){
+ switch(opts.call(o)){
+ case "[object Array]":
+ return o.slice(0);
+ case "[object Object]":
+ return dojo.delegate(o);
+ }
+ }
+ return o;
+ }
+
+ dojo.mixin(du, {
+ coerceType: function(target, source){
+ // summary: Coerces one object to the type of another.
+ // target: Object: object, which typeof result is used to coerce "source" object.
+ // source: Object: object, which will be forced to change type.
+ switch(typeof target){
+ case "number": return Number(eval("(" + source + ")"));
+ case "string": return String(source);
+ case "boolean": return Boolean(eval("(" + source + ")"));
+ }
+ return eval("(" + source + ")");
+ },
+
+ updateWithObject: function(target, source, conv){
+ // summary: Updates an existing object in place with properties from an "source" object.
+ // target: Object: the "target" object to be updated
+ // source: Object: the "source" object, whose properties will be used to source the existed object.
+ // conv: Boolean?: force conversion to the original type
+ if(!source){ return target; }
+ for(var x in target){
+ if(x in source && !(x in empty)){
+ var t = target[x];
+ if(t && typeof t == "object"){
+ du.updateWithObject(t, source[x], conv);
+ }else{
+ target[x] = conv ? du.coerceType(t, source[x]) : clone(source[x]);
+ }
+ }
+ }
+ return target; // Object
+ },
+
+ updateWithPattern: function(target, source, pattern, conv){
+ // summary: Updates an existing object in place with properties from an "source" object.
+ // target: Object: the "target" object to be updated
+ // source: Object: the "source" object, whose properties will be used to source the existed object.
+ // pattern: Object: object, whose properties will be used to pull values from the "source"
+ // conv: Boolean?: force conversion to the original type
+ if(!source || !pattern){ return target; }
+ for(var x in pattern){
+ if(x in source && !(x in empty)){
+ target[x] = conv ? du.coerceType(pattern[x], source[x]) : clone(source[x]);
+ }
+ }
+ return target; // Object
+ },
+
+ merge: function(object, mixin){
+ // summary: Merge two objects structurally, mixin properties will override object's properties.
+ // object: Object: original object.
+ // mixin: Object: additional object, which properties will override object's properties.
+ if(mixin){
+ var otype = opts.call(object), mtype = opts.call(mixin), t, i, l, m;
+ switch(mtype){
+ case "[object Array]":
+ if(mtype == otype){
+ t = new Array(Math.max(object.length, mixin.length));
+ for(i = 0, l = t.length; i < l; ++i){
+ t[i] = du.merge(object[i], mixin[i]);
+ }
+ return t;
+ }
+ return mixin.slice(0);
+ case "[object Object]":
+ if(mtype == otype && object){
+ t = dojo.delegate(object);
+ for(i in mixin){
+ if(i in object){
+ l = object[i];
+ m = mixin[i];
+ if(m !== l){
+ t[i] = du.merge(l, m);
+ }
+ }else{
+ t[i] = dojo.clone(mixin[i]);
+ }
+ }
+ return t;
+ }
+ return dojo.clone(mixin);
+ }
+ }
+ return mixin;
+ }
+ });
+})();
+
+}
|
