source: Dev/trunk/src/client/dojox/app/utils/config.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.2 KB
Line 
1define(["dojo/sniff"], function(has){
2
3// module:
4//              dojox/app/utils/config
5
6return {
7        // summary:
8        //              This module contains the config
9
10        configProcessHas: function(/*Object*/ source){
11                // summary:
12                //              scan the source config for has checks and call configMerge to merge has sections, and remove the has sections from the source.
13                // description:
14                //              configProcessHas will scan the source config for has checks.
15                //              For each has section the items inside the has section will be tested with has (sniff)
16                //              If the has test is true it will call configMerge to merge has sections back into the source config.
17                //              It will always remove the has section from the source after processing it.
18                //              The names in the has section can be separated by a comma, indicating that any of those being true will satisfy the test.
19                // source:
20                //              an object representing the config to be processed.
21                // returns:
22                //              the updated source object.
23                for(var name in source){
24                        var     sval = source[name];
25                        if(name == "has"){ // found a "has" section in source
26                                for(var hasname in sval){ // get the hasnames from the has section
27                                        if(!(hasname.charAt(0) == '_' && hasname.charAt(1) == '_') && sval && typeof sval === 'object'){
28                                                // need to handle multiple has checks separated by a ",".
29                                                var parts = hasname.split(',');
30                                                if(parts.length > 0){
31                                                        while(parts.length > 0){       
32                                                                var haspart = parts.shift();
33                                                                // check for has(haspart) or if haspart starts with ! check for !(has(haspart))
34                                                                if((has(haspart)) || (haspart.charAt(0) == '!' && !(has(haspart.substring(1))))){ // if true this one should be merged
35                                                                        var hasval = sval[hasname];
36                                                                        this.configMerge(source, hasval); // merge this has section into the source config
37                                                                        break;  // found a match for this multiple has test, so go to the next one
38                                                                }
39                                                        }
40                                                }
41                                        }
42                                }
43                                delete source["has"];   // after merge remove this has section from the config
44                        }else{
45                                if(!(name.charAt(0) == '_' && name.charAt(1) == '_') && sval && typeof sval === 'object'){
46                                                this.configProcessHas(sval);
47                                }
48                        }
49                }
50                return source;
51        },
52
53        configMerge: function(/*Object*/ target, /*Object*/ source){
54                // summary:
55                //              does a deep copy of the source into the target to merge the config from the source into the target
56                // description:
57                //              configMerge will merge the source config into the target config with a deep copy.
58                //              anything starting with __ will be skipped and if the target is an array the source items will be pushed into the target.
59                // target:
60                //              an object representing the config which will be updated by merging in the source.
61                // source:
62                //              an object representing the config to be merged into the target.
63                // returns:
64                //              the updated target object.
65
66                for(var name in source){
67                        var tval = target[name];
68                        var     sval = source[name];
69                        if(tval !== sval && !(name.charAt(0) == '_' && name.charAt(1) == '_')){
70                                if(tval && typeof tval === 'object' && sval && typeof sval === 'object'){
71                                        this.configMerge(tval, sval);
72                                }else{
73                                        if(target instanceof Array){
74                                                target.push(sval);
75                                        }else{
76                                                target[name] = sval;
77                                        }
78                                }
79                        }
80                }
81                return target;
82        }
83};
84
85});
Note: See TracBrowser for help on using the repository browser.