Changeset 7947

Show
Ignore:
Timestamp:
04/06/07 03:04:57 (21 months ago)
Author:
alex
Message:

formatting fixes. Correctly detect firefox and IE versions now. Refs #2500

Files:
1 modified

Legend:

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

    r7902 r7947  
    4848                var geckoPos = dua.indexOf("Gecko"); 
    4949                d.isMozilla = d.isMoz = ((geckoPos >= 0)&&(!d.isKhtml)) ? tv : 0; 
    50                 d.isIE = ((document.all)&&(!d.isOpera)) ? tv : 0; 
     50                d.isFF = 0; 
     51                d.isIE = 0; 
     52                try{ 
     53                        if(d.isMoz){ 
     54                                d.isFF = parseFloat(dua.split("Firefox/")[1].split(" ")[0]); 
     55                        } 
     56                        if((document.all)&&(!d.isOpera)){ 
     57                                d.isIE = parseFloat(dav.split("MSIE ")[1].split(";")[0]); 
     58                        } 
     59                }catch(e){} 
    5160 
    5261                var cm = document["compatMode"]; 
     
    5564                // TODO: is the HTML LANG attribute relevant? 
    5665                d.locale = d.locale || (d.isIE ? n.userLanguage : n.language).toLowerCase(); 
    57         })(); 
    58  
    59         dojo._println = console.debug; 
    60  
    61         // These are in order of decreasing likelihood; this will change in time. 
    62         dojo._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; 
    63  
    64         dojo._xhrObj= function(){ 
    65                 // summary:  
    66                 //              does the work of portably generating a new XMLHTTPRequest 
    67                 //              object. 
    68                 var http = null; 
    69                 var last_e = null; 
    70                 try{ http = new XMLHttpRequest(); }catch(e){} 
    71                 if(!http){ 
    72                         for(var i=0; i<3; ++i){ 
    73                                 var progid = dojo._XMLHTTP_PROGIDS[i]; 
    74                                 try{ 
    75                                         http = new ActiveXObject(progid); 
    76                                 }catch(e){ 
    77                                         last_e = e; 
    78                                 } 
    79  
    80                                 if(http){ 
    81                                         dojo._XMLHTTP_PROGIDS = [progid];  // so faster next time 
    82                                         break; 
    83                                 } 
    84                         } 
    85  
    86                         /*if(http && !http.toString) { 
    87                                 http.toString = function() { "[object XMLHttpRequest]"; } 
    88                         }*/ 
    89                 } 
    90  
    91                 if(!http){ 
    92                         throw new Error("XMLHTTP not available: "+last_e); 
    93                 } 
    94  
    95                 return http; // XMLHTTPRequest instance 
    96         } 
    97  
    98         dojo._blockAsync = false; 
    99         dojo._getText = function(uri, async_cb, fail_ok){ 
    100                 // summary: Read the contents of the specified uri and return those contents. 
    101                 // uri: 
    102                 //              A relative or absolute uri. If absolute, it still must be in 
    103                 //              the same "domain" as we are. 
    104                 // async_cb: 
    105                 //              If not specified, load synchronously. If specified, load 
    106                 //              asynchronously, and use async_cb as the progress handler which 
    107                 //              takes the xmlhttp object as its argument. If async_cb, this 
    108                 //              function returns null. 
    109                 // fail_ok: 
    110                 //              Default false. If fail_ok and !async_cb and loading fails, 
    111                 //              return null instead of throwing. 
    112  
    113                 // need to block async callbacks from snatching this thread as the result 
    114                 // of an async callback might call another sync XHR, this hangs khtml forever 
    115                 // hostenv._blockAsync must also be checked in BrowserIO's watchInFlight() 
    116                 // NOTE: must be declared before scope switches ie. this._xhrObj() 
    117                 if(!async_cb){ this._blockAsync = true; } 
    118  
    119                 var http = this._xhrObj(); 
    120  
    121                 function isDocumentOk(http){ 
     66 
     67                d._println = console.debug; 
     68 
     69                // These are in order of decreasing likelihood; this will change in time. 
     70                d._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; 
     71 
     72                d._xhrObj= function(){ 
     73                        // summary:  
     74                        //              does the work of portably generating a new XMLHTTPRequest 
     75                        //              object. 
     76                        var http = null; 
     77                        var last_e = null; 
     78                        try{ http = new XMLHttpRequest(); }catch(e){} 
     79                        if(!http){ 
     80                                for(var i=0; i<3; ++i){ 
     81                                        var progid = dojo._XMLHTTP_PROGIDS[i]; 
     82                                        try{ 
     83                                                http = new ActiveXObject(progid); 
     84                                        }catch(e){ 
     85                                                last_e = e; 
     86                                        } 
     87 
     88                                        if(http){ 
     89                                                dojo._XMLHTTP_PROGIDS = [progid];  // so faster next time 
     90                                                break; 
     91                                        } 
     92                                } 
     93 
     94                                /*if(http && !http.toString) { 
     95                                        http.toString = function() { "[object XMLHttpRequest]"; } 
     96                                }*/ 
     97                        } 
     98 
     99                        if(!http){ 
     100                                throw new Error("XMLHTTP not available: "+last_e); 
     101                        } 
     102 
     103                        return http; // XMLHTTPRequest instance 
     104                } 
     105 
     106                var isDocumentOk = function(http){ 
    122107                        var stat = http["status"]; 
    123108                        // allow a 304 use cache, needed in konq (is this compliant with 
     
    126111                } 
    127112 
    128                 if(async_cb){ 
    129                         var _this = this, timer = null, gbl = dojo.global(); 
    130                         http.onreadystatechange = function(){ 
    131                                 if(timer){ gbl.clearTimeout(timer); timer = null; } 
    132                                 if(_this._blockAsync){ 
    133                                         timer = gbl.setTimeout(function(){ 
    134                                                 http.onreadystatechange.apply(this); 
    135                                         }, 10); 
     113                d._blockAsync = false; 
     114                d._getText = function(uri, async_cb, fail_ok){ 
     115                        // summary: Read the contents of the specified uri and return those contents. 
     116                        // uri: 
     117                        //              A relative or absolute uri. If absolute, it still must be in 
     118                        //              the same "domain" as we are. 
     119                        // async_cb: 
     120                        //              If not specified, load synchronously. If specified, load 
     121                        //              asynchronously, and use async_cb as the progress handler which 
     122                        //              takes the xmlhttp object as its argument. If async_cb, this 
     123                        //              function returns null. 
     124                        // fail_ok: 
     125                        //              Default false. If fail_ok and !async_cb and loading fails, 
     126                        //              return null instead of throwing. 
     127 
     128                        // need to block async callbacks from snatching this thread as the result 
     129                        // of an async callback might call another sync XHR, this hangs khtml forever 
     130                        // hostenv._blockAsync must also be checked in BrowserIO's watchInFlight() 
     131                        // NOTE: must be declared before scope switches ie. this._xhrObj() 
     132                        if(!async_cb){ this._blockAsync = true; } 
     133 
     134                        var http = this._xhrObj(); 
     135 
     136                        if(async_cb){ 
     137                                var _this = this, timer = null, gbl = dojo.global(); 
     138                                http.onreadystatechange = function(){ 
     139                                        if(timer){ gbl.clearTimeout(timer); timer = null; } 
     140                                        if(_this._blockAsync){ 
     141                                                timer = gbl.setTimeout(function(){ 
     142                                                        http.onreadystatechange.apply(this); 
     143                                                }, 10); 
     144                                        }else{ 
     145                                                if(4==http.readyState){ 
     146                                                        if(isDocumentOk(http)){ 
     147                                                                // console.debug("LOADED URI: "+uri); 
     148                                                                async_cb(http.responseText); 
     149                                                        } 
     150                                                } 
     151                                        } 
     152                                } 
     153                        } 
     154 
     155                        http.open('GET', uri, async_cb ? true : false); 
     156                        try{ 
     157                                http.send(null); 
     158                                if(async_cb){ 
     159                                        return null; 
     160                                } 
     161                                if(!isDocumentOk(http)){ 
     162                                        var err = Error("Unable to load "+uri+" status:"+ http.status); 
     163                                        err.status = http.status; 
     164                                        err.responseText = http.responseText; 
     165                                        throw err; 
     166                                } 
     167                        }catch(e){ 
     168                                this._blockAsync = false; 
     169                                if((fail_ok)&&(!async_cb)){ 
     170                                        return null; 
    136171                                }else{ 
    137                                         if(4==http.readyState){ 
    138                                                 if(isDocumentOk(http)){ 
    139                                                         // console.debug("LOADED URI: "+uri); 
    140                                                         async_cb(http.responseText); 
    141                                                 } 
    142                                         } 
    143                                 } 
    144                         } 
    145                 } 
    146  
    147                 http.open('GET', uri, async_cb ? true : false); 
    148                 try{ 
    149                         http.send(null); 
    150                         if(async_cb){ 
    151                                 return null; 
    152                         } 
    153                         if(!isDocumentOk(http)){ 
    154                                 var err = Error("Unable to load "+uri+" status:"+ http.status); 
    155                                 err.status = http.status; 
    156                                 err.responseText = http.responseText; 
    157                                 throw err; 
    158                         } 
    159                 }catch(e){ 
     172                                        throw e; 
     173                                } 
     174                        } 
     175 
    160176                        this._blockAsync = false; 
    161                         if((fail_ok)&&(!async_cb)){ 
    162                                 return null; 
    163                         }else{ 
    164                                 throw e; 
    165                         } 
    166                 } 
    167  
    168                 this._blockAsync = false; 
    169                 return http.responseText; // String 
    170         } 
     177                        return http.responseText; // String 
     178                } 
     179        })(); 
    171180 
    172181        dojo._handleNodeEvent = function(/*DomNode*/node, /*String*/evtName, /*Function*/fp){