Changeset 7650

Show
Ignore:
Timestamp:
03/18/07 17:12:40 (22 months ago)
Author:
alex
Message:

fixes onload code, removes TONS of cruft, and slims the built (browser) bootstrap loader to 11K from 21K. Refs #2500

Location:
dojo/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/dojo.js

    r7645 r7650  
    2929                } 
    3030         
    31                 if((this["djConfig"])&&(djConfig["baseScriptUri"])){ 
    32                         var root = djConfig["baseScriptUri"]; 
    33                 }else if((this["djConfig"])&&(djConfig["baseRelativePath"])){ 
    34                         var root = djConfig["baseRelativePath"]; 
     31                if((this["djConfig"])&&(djConfig["baseUrl"])){ 
     32                        var root = djConfig["baseUrl"]; 
    3533                }else{ 
    3634                        var root = "./"; 
     
    4038                        } 
    4139                        if(!this["djConfig"]){ 
    42                                 djConfig = { baseRelativePath: root }; 
     40                                djConfig = { baseUrl: root }; 
    4341                        } 
    4442         
     
    5452                                                root = src.substring(0, m.index); 
    5553                                                if(!this["djConfig"]){ djConfig = {}; } 
    56                                                 djConfig["baseScriptUri"] = djConfig["baseRelativePath"] = root; 
     54                                                djConfig["baseUrl"] = root; 
    5755                                                break; 
    5856                                        } 
     
    6159                } 
    6260         
    63                 var loaderRoot = root; 
    64                 if((this["djConfig"])&&(djConfig["baseLoaderUri"])){ 
    65                         loaderRoot = djConfig["baseLoaderUri"]; 
    66                 } 
    67          
    6861                for(var x=0; x < tmps.length; x++){ 
    69                         var spath = loaderRoot+"_base/_loader/"+tmps[x]; 
     62                        var spath = root+"_base/_loader/"+tmps[x]; 
    7063                        if(isRhino||isSpidermonkey){ 
    7164                                load(spath); 
  • dojo/trunk/tests/runner.js

    r7647 r7650  
    663663 
    664664if(this["dojo"]){ 
    665         dojo.kwCompoundRequire({ 
     665        dojo.platformRequire({ 
    666666                browser: ["tests._browserRunner"], 
    667667                rhino: ["tests._rhinoRunner"], 
  • dojo/trunk/tests/_base.js

    r7631 r7650  
    1 if(this["dojo"]){ 
     1try{ 
    22        dojo.provide("tests._base"); 
    3 } 
     3}catch(e){} 
    44 
    55// the test suite for the bootstrap. Requires hostenv and other base tests at 
  • dojo/trunk/tests/_browserRunner.js

    r7647 r7650  
    1 if(this["dojo"]){ 
     1if(window["dojo"]){ 
    22        dojo.provide("tests._browserRunner"); 
    33} 
  • dojo/trunk/_base/_loader/bootstrap.js

    r7649 r7650  
    66// description:  The variables that can be set are as follows: 
    77//                      - isDebug: false 
    8 //                      - allowQueryConfig: false 
    98//                      - baseScriptUri: "" 
    109//                      - baseRelativePath: "" 
  • dojo/trunk/_base/_loader/hostenv_browser.js

    r7642 r7650  
    11if(typeof window != 'undefined'){ 
     2        dojo.isBrowser = true; 
     3        dojo._name = "browser"; 
    24 
    35        // attempt to figure out the path to dojo if it isn't set in the config 
    46        (function(){ 
     7                var d = dojo; 
     8                // this is a scope protection closure. We set browser versions and grab 
     9                // the URL we were loaded from here. 
     10 
    511                // before we get any further with the config options, try to pick them out 
    612                // of the URL. Most of this code is from NW 
    7                 if(djConfig.allowQueryConfig){ 
    8                         var baseUrl = document.location.toString(); // FIXME: use location.query instead? 
    9                         var params = baseUrl.split("?", 2); 
    10                         if(params.length > 1){ 
    11                                 var paramStr = params[1]; 
    12                                 var pairs = paramStr.split("&"); 
    13                                 for(var x in pairs){ 
    14                                         var sp = pairs[x].split("="); 
    15                                         // FIXME: is this eval dangerous? 
    16                                         if((sp[0].length > 9)&&(sp[0].substr(0, 9) == "djConfig.")){ 
    17                                                 var opt = sp[0].substr(9); 
    18                                                 try{ 
    19                                                         djConfig[opt]=eval(sp[1]); 
    20                                                 }catch(e){ 
    21                                                         djConfig[opt]=sp[1]; 
    22                                                 } 
    23                                         } 
    24                                 } 
    25                         } 
    26                 } 
    27  
    2813                if( 
    29                         ((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&  
    30                         (document && document.getElementsByTagName) 
     14                        (djConfig["baseUrl"] == "") && (document && document.getElementsByTagName) 
    3115                ){ 
    3216                        var scripts = document.getElementsByTagName("script"); 
    33                         var rePkg = /(__package__|dojo|bootstrap1)\.js([\?\.]|$)/i; 
     17                        var rePkg = /(dojo|bootstrap)\.js([\?\.]|$)/i; 
    3418                        for(var i = 0; i < scripts.length; i++) { 
    3519                                var src = scripts[i].getAttribute("src"); 
     
    3822                                if(m) { 
    3923                                        var root = src.substring(0, m.index); 
    40                                         if(src.indexOf("bootstrap1") > -1) { root += "../"; } 
    41                                         if(!this["djConfig"]) { djConfig = {}; } 
    42                                         if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; } 
    43                                         if(djConfig["baseRelativePath"] == "") { djConfig["baseRelativePath"] = root; } 
     24                                        if(src.indexOf("bootstrap") > -1) { root += "../"; } 
     25                                        d._baseUrl = root; 
     26                                        console.debug(root); 
    4427                                        break; 
    4528                                } 
    4629                        } 
     30                }else{ 
     31                        d._baseUrl = djConfig["baseUrl"]; 
    4732                } 
    4833 
    4934                // fill in the rendering support information in dojo.render.* 
    50                 var dr = dojo.render; 
    51                 var drh = dojo.render.html; 
    52                 var drs = dojo.render.svg; 
    53                 var dua = (drh.UA = navigator.userAgent); 
    54                 var dav = (drh.AV = navigator.appVersion); 
    55                 var t = true; 
    56                 var f = false; 
    57                 drh.capable = t; 
    58                 drh.support.builtin = t; 
    59  
    60                 dr.ver = parseFloat(drh.AV); 
    61                 dr.os.mac = dav.indexOf("Macintosh") >= 0; 
    62                 dr.os.win = dav.indexOf("Windows") >= 0; 
    63                 // could also be Solaris or something, but it's the same browser 
    64                 dr.os.linux = dav.indexOf("X11") >= 0; 
    65  
    66                 drh.opera = dua.indexOf("Opera") >= 0; 
    67                 drh.khtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0); 
    68                 drh.safari = dav.indexOf("Safari") >= 0; 
     35                var n = navigator; 
     36                var dua = n.userAgent; 
     37                var dav = n.appVersion; 
     38                var tv = parseFloat(dav); 
     39 
     40                d.isOpera = (dua.indexOf("Opera") >= 0) ? tv : 0; 
     41                d.isKhtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0) ? tv : 0; 
     42                d.isSafari = (dav.indexOf("Safari") >= 0) ? tv : 0; 
    6943                var geckoPos = dua.indexOf("Gecko"); 
    70                 drh.mozilla = drh.moz = (geckoPos >= 0)&&(!drh.khtml); 
    71                 if (drh.mozilla) { 
    72                         // gecko version is YYYYMMDD 
    73                         drh.geckoVersion = dua.substring(geckoPos + 6, geckoPos + 14); 
    74                 } 
    75                 drh.ie = (document.all)&&(!drh.opera); 
    76                 drh.ie50 = drh.ie && dav.indexOf("MSIE 5.0")>=0; 
    77                 drh.ie55 = drh.ie && dav.indexOf("MSIE 5.5")>=0; 
    78                 drh.ie60 = drh.ie && dav.indexOf("MSIE 6.0")>=0; 
    79                 drh.ie70 = drh.ie && dav.indexOf("MSIE 7.0")>=0; 
     44                d.isMozilla = d.isMoz = ((geckoPos >= 0)&&(!d.isKhtml)) ? tv : 0; 
     45                d.isIE = ((document.all)&&(!d.isOpera)) ? tv : 0; 
    8046 
    8147                var cm = document["compatMode"]; 
    82                 drh.quirks = (cm == "BackCompat")||(cm == "QuirksMode")||drh.ie55||drh.ie50; 
     48                d.isQuirks = (cm == "BackCompat")||(cm == "QuirksMode")||(d.isIE < 6); 
    8349 
    8450                // TODO: is the HTML LANG attribute relevant? 
    85                 dojo.locale = dojo.locale || (drh.ie ? navigator.userLanguage : navigator.language).toLowerCase(); 
    86  
    87                 dr.vml.capable=drh.ie; 
    88                 drs.capable = f; 
    89                 drs.support.plugin = f; 
    90                 drs.support.builtin = f; 
    91                 var tdoc = window["document"]; 
    92                 var tdi = tdoc["implementation"]; 
    93  
    94                 if((tdi)&&(tdi["hasFeature"])&&(tdi.hasFeature("org.w3c.dom.svg", "1.0"))){ 
    95                         drs.capable = t; 
    96                         drs.support.builtin = t; 
    97                         drs.support.plugin = f; 
    98                 } 
    99                 // webkits after 420 support SVG natively. The test string is "AppleWebKit/420+" 
    100                 if(drh.safari){ 
    101                         var tmp = dua.split("AppleWebKit/")[1]; 
    102                         var ver = parseFloat(tmp.split(" ")[0]); 
    103                         if(ver >= 420){ 
    104                                 drs.capable = t; 
    105                                 drs.support.builtin = t; 
    106                                 drs.support.plugin = f; 
    107                         } 
    108                 }else{ 
    109                 } 
     51                d.locale = d.locale || (d.isIE ? n.userLanguage : n.language).toLowerCase(); 
    11052        })(); 
    11153 
    112         dojo.hostenv.startPackage("dojo.hostenv"); 
    113  
    114         dojo.render.name = dojo.hostenv.name_ = 'browser'; 
    115         dojo.hostenv.searchIds = []; 
    11654 
    11755        // These are in order of decreasing likelihood; this will change in time. 
    118         dojo.hostenv._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; 
    119  
    120         dojo.hostenv.getXmlhttpObject = function(){ 
    121                 // summary: does the work of portably generating a new XMLHTTPRequest object. 
     56        dojo._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; 
     57 
     58        dojo._xhrObj= function(){ 
     59                // summary:  
     60                //              does the work of portably generating a new XMLHTTPRequest 
     61                //              object. 
    12262                var http = null; 
    12363                var last_e = null; 
     
    12565                if(!http){ 
    12666                        for(var i=0; i<3; ++i){ 
    127                                 var progid = dojo.hostenv._XMLHTTP_PROGIDS[i]; 
     67                                var progid = dojo._XMLHTTP_PROGIDS[i]; 
    12868                                try{ 
    12969                                        http = new ActiveXObject(progid); 
     
    13373 
    13474                                if(http){ 
    135                                         dojo.hostenv._XMLHTTP_PROGIDS = [progid];  // so faster next time 
     75                                        dojo._XMLHTTP_PROGIDS = [progid];  // so faster next time 
    13676                                        break; 
    13777                                } 
     
    14484 
    14585                if(!http){ 
    146                         return dojo.raise("XMLHTTP not available", last_e); 
     86                        throw new Error("XMLHTTP not available: "+last_e); 
    14787                } 
    14888 
     
    15090        } 
    15191 
    152         dojo.hostenv._blockAsync = false; 
    153         dojo.hostenv.getText = function(uri, async_cb, fail_ok){ 
     92        dojo._blockAsync = false; 
     93        dojo._getText = function(uri, async_cb, fail_ok){ 
    15494                // summary: Read the contents of the specified uri and return those contents. 
    15595                // uri: 
     
    168108                // of an async callback might call another sync XHR, this hangs khtml forever 
    169109                // hostenv._blockAsync must also be checked in BrowserIO's watchInFlight() 
    170                 // NOTE: must be declared before scope switches ie. this.getXmlhttpObject() 
     110                // NOTE: must be declared before scope switches ie. this._xhrObj() 
    171111                if(!async_cb){ this._blockAsync = true; } 
    172112 
    173                 var http = this.getXmlhttpObject(); 
     113                var http = this._xhrObj(); 
    174114 
    175115                function isDocumentOk(http){ 
    176116                        var stat = http["status"]; 
    177                         // allow a 304 use cache, needed in konq (is this compliant with the http spec?) 
     117                        // allow a 304 use cache, needed in konq (is this compliant with 
     118                        // the http spec?) 
    178119                        return Boolean((!stat)||((200 <= stat)&&(300 > stat))||(stat==304)); 
    179120                } 
     
    181122                if(async_cb){ 
    182123                        var _this = this, timer = null, gbl = dojo.global(); 
    183                         var xhr = dojo.getObject("dojo.io.XMLHTTPTransport"); 
    184124                        http.onreadystatechange = function(){ 
    185125                                if(timer){ gbl.clearTimeout(timer); timer = null; } 
    186                                 if(_this._blockAsync || (xhr && xhr._blockAsync)){ 
    187                                         timer = gbl.setTimeout(function () { http.onreadystatechange.apply(this); }, 10); 
     126                                if(_this._blockAsync){ 
     127                                        timer = gbl.setTimeout(function(){ 
     128                                                http.onreadystatechange.apply(this); 
     129                                        }, 10); 
    188130                                }else{ 
    189131                                        if(4==http.readyState){ 
     
    222164        } 
    223165 
    224         dojo.hostenv.defaultDebugContainerId = 'dojoDebug'; 
    225         dojo.hostenv._println_buffer = []; 
    226         dojo.hostenv._println_safe = false; 
    227         dojo.hostenv.println = function(/*String*/line){ 
    228                 // summary: 
    229                 //              prints the provided line to whatever logging container is 
    230                 //              available. If the page isn't loaded yet, the line may be added 
    231                 //              to a buffer for printing later. 
    232                 if(!dojo.hostenv._println_safe){ 
    233                         dojo.hostenv._println_buffer.push(line); 
    234                 }else{ 
    235                         try { 
    236                                 var console = document.getElementById(djConfig.debugContainerId ? 
    237                                         djConfig.debugContainerId : dojo.hostenv.defaultDebugContainerId); 
    238                                 if(!console) { console = dojo.body(); } 
    239  
    240                                 var div = document.createElement("div"); 
    241                                 div.appendChild(document.createTextNode(line)); 
    242                                 console.appendChild(div); 
    243                         } catch (e) { 
    244                                 try{ 
    245                                         // safari needs the output wrapped in an element for some reason 
    246                                         document.write("<div>" + line + "</div>"); 
    247                                 }catch(e2){ 
    248                                         window.status = line; 
    249                                 } 
    250                         } 
    251                 } 
    252         } 
    253  
    254         dojo.addOnLoad(function(){ 
    255                 dojo.hostenv._println_safe = true; 
    256                 while(dojo.hostenv._println_buffer.length > 0){ 
    257                         dojo.hostenv.println(dojo.hostenv._println_buffer.shift()); 
    258                 } 
    259         }); 
    260  
    261         function dj_addNodeEvtHdlr(/*DomNode*/node, /*String*/evtName, /*Function*/fp){ 
     166        dojo._println = console.debug; 
     167 
     168        dojo._handleNodeEvent = function(/*DomNode*/node, /*String*/evtName, /*Function*/fp){ 
    262169                // summary: 
    263170                //              non-destructively adds the specified function to the node's 
     
    274181 
    275182        //      BEGIN DOMContentLoaded, from Dean Edwards (http://dean.edwards.name/weblog/2006/06/again/) 
    276         function dj_load_init(e){ 
     183        dojo._loadInit = function(e){ 
    277184                // allow multiple calls, only first one will take effect 
    278185                // A bug in khtml calls events callbacks for document for event which isnt supported 
     
    286193                } 
    287194 
    288                 var initFunc = function(){ 
    289                         //perform initialization 
    290                         if(dojo.render.html.ie){ 
    291                                 dojo.hostenv.makeWidgets(); 
    292                         } 
    293                 }; 
    294  
    295                 if(dojo.hostenv.inFlightCount == 0){ 
    296                         initFunc(); 
    297                         dojo.hostenv.modulesLoaded(); 
    298                 }else{ 
    299                         //This else case should be xdomain loading. 
    300                         //Make sure this is the first thing in the load listener array. 
    301                         //Part of the dojo.addOnLoad guarantee is that when the listeners are notified, 
    302                         //It means the DOM (or page) has loaded and that widgets have been parsed. 
    303                         dojo.hostenv.modulesLoadedListeners.unshift(initFunc); 
     195                if(dojo._inFlightCount == 0){ 
     196                        dojo._modulesLoaded(); 
    304197                } 
    305198        } 
     
    312205                //              DOMContentLoaded on that platform. For more information, see: 
    313206                //              http://trac.dojotoolkit.org/ticket/1704 
    314                 if(dojo.render.html.opera || (dojo.render.html.moz && (djConfig["enableMozDomContentLoaded"] === true))){ 
    315                         document.addEventListener("DOMContentLoaded", dj_load_init, null); 
     207                if(dojo.isOpera|| (dojo.isMoz && (djConfig["enableMozDomContentLoaded"] === true))){ 
     208                        document.addEventListener("DOMContentLoaded", dojo._loadInit, null); 
    316209                } 
    317210 
    318211                //      mainly for Opera 8.5, won't be fired if DOMContentLoaded fired already. 
    319212                //  also used for Mozilla because of trac #1640 
    320                 window.addEventListener("load", dj_load_init, null); 
    321         } 
    322  
    323         //      for Internet Explorer. readyState will not be achieved on init call, but dojo doesn't need it 
    324         //      however, we'll include it because we don't know if there are other functions added that might. 
    325         //      Note that this has changed because the build process strips all comments--including conditional 
    326         //              ones. 
    327         if(dojo.render.html.ie && dojo.render.os.win){ 
     213                window.addEventListener("load", dojo._loadInit, null); 
     214        } 
     215 
     216        //      for Internet Explorer. readyState will not be achieved on init call, 
     217        //      but dojo doesn't need it however, we'll include it because we don't 
     218        //      know if there are other functions added that might.  Note that this has 
     219        //      changed because the build process strips all comments -- including 
     220        //      conditional ones. 
     221        if(dojo.isIE){ 
    328222                document.write('<scr'+'ipt defer src="//:" ' 
    329                         + 'onreadystatechange="if(this.readyState==\'complete\'){dj_load_init();}">' 
     223                        + 'onreadystatechange="if(this.readyState==\'complete\'){dojo._loadInit();}">' 
    330224                        + '</scr'+'ipt>' 
    331225                ); 
    332226        } 
    333227 
    334         if (/(WebKit|khtml)/i.test(navigator.userAgent)) { // sniff 
    335                 var _timer = setInterval(function() { 
    336                         if (/loaded|complete/.test(document.readyState)) { 
    337                                 dj_load_init(); // call the onload handler 
     228        if(/(WebKit|khtml)/i.test(navigator.userAgent)){ // sniff 
     229                var _timer = setInterval(function(){ 
     230                        if(/loaded|complete/.test(document.readyState)){ 
     231                                dojo._loadInit(); // call the onload handler 
    338232                        } 
    339233                }, 10); 
     
    345239        // following code fixes the problem 
    346240        // Reference: http://support.microsoft.com/default.aspx?scid=kb;en-us;199155 
    347         if(dojo.render.html.ie){ 
    348                 dj_addNodeEvtHdlr(window, "beforeunload", function(){ 
    349                         dojo.hostenv._unloading = true; 
     241        if(dojo.isIE){ 
     242                dojo._handleNodeEvent(window, "beforeunload", function(){ 
     243                        dojo._unloading = true; 
    350244                        window.setTimeout(function() { 
    351                                 dojo.hostenv._unloading = false; 
     245                                dojo._unloading = false; 
    352246                        }, 0); 
    353247                }); 
    354248        } 
    355249 
    356         dj_addNodeEvtHdlr(window, "unload", function(){ 
    357                 if((!dojo.render.html.ie)||(dojo.render.html.ie && dojo.hostenv._unloading)){ 
    358                         dojo.hostenv.unloaded(); 
     250        dojo._handleNodeEvent(window, "unload", function(){ 
     251                if((!dojo.isIE)||(dojo.isIE && dojo._unloading)){ 
     252                        dojo.unloaded(); 
    359253                } 
    360254        }); 
    361255 
    362         dojo.hostenv.makeWidgets = function(){ 
    363                 // you can put searchIds in djConfig and dojo.hostenv at the moment 
    364                 // we should probably eventually move to one or the other 
    365                 var sids = []; 
    366                 if(djConfig.searchIds && djConfig.searchIds.length > 0) { 
    367                         sids = sids.concat(djConfig.searchIds); 
    368                 } 
    369                 if(dojo.hostenv.searchIds && dojo.hostenv.searchIds.length > 0) { 
    370                         sids = sids.concat(dojo.hostenv.searchIds); 
    371                 } 
    372  
    373                 if((djConfig.parseWidgets)||(sids.length > 0)){ 
    374                         if(dojo.getObject("dojo.widget.Parse")){ 
    375                                 // we must do this on a delay to avoid: 
    376                                 //      http://www.shaftek.org/blog/archives/000212.html 
    377                                 // (IE bug) 
    378                                         var parser = new dojo.xml.Parse(); 
    379                                         if(sids.length > 0){ 
    380                                                 for(var x=0; x<sids.length; x++){ 
    381                                                         var tmpNode = document.getElementById(sids[x]); 
    382                                                         if(!tmpNode){ continue; } 
    383                                                         var frag = parser.parseElement(tmpNode, null, true); 
    384                                                         dojo.widget.getParser().createComponents(frag); 
    385                                                 } 
    386                                         }else if(djConfig.parseWidgets){ 
    387                                                 var frag  = parser.parseElement(dojo.body(), null, true); 
    388                                                 dojo.widget.getParser().createComponents(frag); 
    389                                         } 
    390                         } 
    391                 } 
    392         } 
    393  
    394         dojo.addOnLoad(function(){ 
    395                 if(!dojo.render.html.ie) { 
    396                         dojo.hostenv.makeWidgets(); 
    397                 } 
    398         }); 
    399  
    400256        try{ 
    401                 if(dojo.render.html.ie){ 
     257                if(dojo.isIE){ 
    402258                        document.namespaces.add("v","urn:schemas-microsoft-com:vml"); 
    403259                        document.createStyleSheet().addRule("v\\:*", "behavior:url(#default#VML)"); 
     
    407263        // stub, over-ridden by debugging code. This will at least keep us from 
    408264        // breaking when it's not included 
    409         dojo.hostenv.writeIncludes = function(){} 
     265        dojo._writeIncludes = function(){} 
    410266 
    411267        //TODOC:  HOW TO DOC THIS? 
    412         // @global: dj_currentDocument 
     268        // @global: dojo._currentDocument 
    413269        // summary: 
    414         //              Current document object. 'dj_currentDocument' can be modified for temporary context shifting. 
     270        //              Current document object. 'dojo._currentDocument' can be modified 
     271        //              for temporary context shifting. 
    415272        // description: 
    416         //    dojo.doc() returns dojo.currentDocument. 
    417         //              Refer to dojo.doc() rather than referring to 'window.document' to ensure your 
    418         //              code runs correctly in managed contexts. 
    419         if(!dj_undef("document", this)){ 
    420                 dj_currentDocument = this.document; 
     273        //    dojo.doc() returns dojo._currentDocument. Refer to dojo.doc() rather 
     274        //    than referring to 'window.document' to ensure your code runs 
     275        //    correctly in managed contexts. 
     276        if(this["document"]){ 
     277                dojo._currentDocument = this.document; 
    421278        } 
    422279 
     
    424281