Changeset 81

Show
Ignore:
Timestamp:
11/08/06 18:22:17 (2 years ago)
Author:
Jan-Klaas Kollhof
Message:

some fixes for IE

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/experimental/jsolait/jsolait.js

    r80 r81  
    7373    mod.moduleSearchURIs = [".", "%(baseURI)s/lib"]; 
    7474    
    75     mod.packagesURI = "%(baseURI)s/packages"; 
     75    mod.packagesURI = "%(baseURI)s/../jsolait-packages"; 
    7676     
    7777    mod.modules={}; 
     
    520520 
    521521    mod.loadURI=function(uri, cb){ 
    522         var errorNotHandled=true; 
    523         try{ 
    524             var xmlhttp = mod.getHTTPRequestObject(); 
    525         }catch(e){ 
    526             cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); 
    527             return; 
    528         } 
    529          
    530         xmlhttp.onreadystatechange=function(){ 
    531             if (xmlhttp.readyState==4) { 
    532                 //todo: the status checking needs testing 
    533                 if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 
    534                     var s= str(xmlhttp.responseText); 
    535                     xmlhttp = null; 
    536                     cb(s); 
    537                 }else{ 
    538                     if(errorNotHandled){ 
    539                         errorNotHandled=false; 
    540                         cb(null, new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status))); 
    541                     } 
    542                 } 
    543                 xmlhttp=null; 
    544             }else if (xmlhttp.readyState==2){ 
    545                 //status property should be available (MS IXMLHTTPRequest documentation) 
    546                 //in Mozilla it is not if the request failed(server not reachable) 
    547                 //in IE it is not available at all ?! 
    548                 try{//see if it is mozilla otherwise don't care. 
    549                     var isNetscape = netscape; 
    550                     try{//if status is not available the request failed. 
    551                         var s=xmlhttp.status; 
    552                     }catch(e){//call the callback because Mozilla will not get to readystate 4 
     522        // IE7 is shite or I am an idiot 
     523        // it looks like it calls onreadystatechange before returning from the send() call 
     524        // for urls that are cached, thus making the call sync and not async. 
     525        // this is clearly wrong !!! 
     526        //so we emulate everything using a setTimeout ... ugh  
     527        setTimeout(function(){ 
     528             
     529            var errorNotHandled=true; 
     530            try{ 
     531                var xmlhttp = mod.getHTTPRequestObject(); 
     532            }catch(e){ 
     533                cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); 
     534                return; 
     535            } 
     536             
     537            xmlhttp.onreadystatechange=function(){ 
     538                if (xmlhttp.readyState==4) { 
     539                    //todo: the status checking needs testing 
     540                    if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ 
     541                        var s= str(xmlhttp.responseText); 
     542                        xmlhttp = null; 
     543                        cb(s); 
     544                    }else{ 
    553545                        if(errorNotHandled){ 
    554                             xmlhttp = null; 
    555546                            errorNotHandled=false; 
    556                             cb(null, new mod.LoadURIFailed(uri, new mod.Exception("url request failed ",e))); 
     547                            cb(null, new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status))); 
    557548                        } 
    558549                    } 
    559                 }catch(e){ 
    560                 } 
    561             } 
    562         }; 
    563          
    564         try{ 
    565             xmlhttp.open("GET", uri, true); 
    566             xmlhttp.send(""); 
    567         }catch(e){ 
    568             if(errorNotHandled){ 
    569                 errorNotHandled=false; 
    570                 xmlhttp=null; 
    571                 cb (null, new mod.LoadURIFailed(uri, e)); 
    572             } 
    573         } 
     550                    xmlhttp=null; 
     551                }else if (xmlhttp.readyState==2){ 
     552                    //status property should be available (MS IXMLHTTPRequest documentation) 
     553                    //in Mozilla it is not if the request failed(server not reachable) 
     554                    //in IE it is not available at all ?! 
     555                    try{//see if it is mozilla otherwise don't care. 
     556                        var isNetscape = netscape; 
     557                        try{//if status is not available the request failed. 
     558                            var s=xmlhttp.status; 
     559                        }catch(e){//call the callback because Mozilla will not get to readystate 4 
     560                            if(errorNotHandled){ 
     561                                xmlhttp = null; 
     562                                errorNotHandled=false; 
     563                                cb(null, new mod.LoadURIFailed(uri, new mod.Exception("url request failed ",e))); 
     564                            } 
     565                        } 
     566                    }catch(e){ 
     567                    } 
     568                } 
     569            } 
     570         
     571         
     572            try{ 
     573                xmlhttp.open("GET", uri, true); 
     574                xmlhttp.send(""); 
     575            }catch(e){ 
     576                if(errorNotHandled){ 
     577                    errorNotHandled=false; 
     578                    xmlhttp=null; 
     579                    cb (null, new mod.LoadURIFailed(uri, e)); 
     580                } 
     581            } 
     582        },0); 
    574583    }; 
    575584     
     
    635644                                when the module is loaded or an error occurs. 
    636645    **/ 
     646     
    637647    mod.loadModule=function(name, loadedCB){ 
    638648 
     
    691701                 
    692702                args.push(newMod); 
    693                 args.push(new Function("","")); 
     703                args.push(new Function("","throw 'imprt not supported';")); 
    694704                args.push(mod); 
    695705                 
     
    989999            if(err){ 
    9901000                if(alertError){ 
    991                     alert(err); 
     1001                    alert('error loading module' + modName + '\n' + err); 
    9921002                } 
    9931003                throw err; 
     
    9971007                }catch(e){ 
    9981008                    if(alertError){ 
    999                         alert(e); 
     1009                        alert('error running ' + modName +'.' + methodName + '\n' + err); 
    10001010                    } 
    10011011                    throw e 
     
    10031013            } 
    10041014        }); 
    1005      
    10061015    }; 
    10071016//---------------------------------------------------String Format ------------------------------------------------------- 
  • branches/experimental/jsolait/jsolait.wsf

    r77 r81  
    3333    <script language="JavaScript"> <![CDATA[ 
    3434        jsolait.__sourceURI__ = 'file://' + WScript.scriptFullName.slice(0,-3) + "js"; 
    35  
     35        setTimeout=function(fn){ 
     36            fn(); 
     37        }; 
    3638 
    3739    jsolait.Module("jsolaitws", function(mod){