Changeset 7792

Show
Ignore:
Timestamp:
03/26/07 02:49:40 (22 months ago)
Author:
alex
Message:

enable the djConfig attribute on <script> tags that pull in Dojo. Simplifies setting config options. Refs #2500

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/_base/_loader/hostenv_browser.js

    r7782 r7792  
    1010                // the URL we were loaded from here. 
    1111 
    12                 // before we get any further with the config options, try to pick them out 
    13                 // of the URL. Most of this code is from NW 
    14                 if( 
    15                         (!djConfig["baseUrl"]) && (document && document.getElementsByTagName) 
    16                 ){ 
     12                // grab the node we were loaded from 
     13                if(document && document.getElementsByTagName){ 
    1714                        var scripts = document.getElementsByTagName("script"); 
    18                         var rePkg = /(dojo|bootstrap)\.js([\?\.]|$)/i; 
    19                         for(var i = 0; i < scripts.length; i++) { 
     15                        var rePkg = /dojo\.js([\?\.]|$)/i; 
     16                        for(var i = 0; i < scripts.length; i++){ 
    2017                                var src = scripts[i].getAttribute("src"); 
    21                                 if(!src) { continue; } 
     18                                if(!src){ continue; } 
    2219                                var m = src.match(rePkg); 
    23                                 if(m) { 
    24                                         var root = src.substring(0, m.index); 
    25                                         if(src.indexOf("bootstrap") > -1) { root += "../"; } 
    26                                         d._baseUrl = root; 
    27                                         console.debug(root); 
    28                                         break; 
     20                                if(m){ 
     21                                        // find out where we came from 
     22                                        if(!djConfig["baseUrl"]){ 
     23                                                djConfig["baseUrl"] = src.substring(0, m.index); 
     24                                        } 
     25                                        // and find out if we need to modify our behavior 
     26                                        var cfg = scripts[i].getAttribute("djConfig"); 
     27                                        if(cfg){ 
     28                                                var cfgo = eval("({ "+cfg+" })"); 
     29                                                for(var x in cfgo){ 
     30                                                        djConfig[x] = cfgo[x]; 
     31                                                } 
     32                                        } 
     33                                        break; // "first Dojo wins" 
    2934                                } 
    3035                        } 
    31                 }else{ 
    32                         d._baseUrl = djConfig["baseUrl"]; 
    33                 } 
     36                } 
     37                d._baseUrl = djConfig["baseUrl"]; 
    3438 
    3539                // fill in the rendering support information in dojo.render.*