jQuery: The Write Less, Do More JavaScript Library

Changeset 4245

Show
Ignore:
Timestamp:
12/20/07 06:00:01 (8 months ago)
Author:
davidserduke
Message:

Changed the $(document).ready() code to try and solve some problems in Safari, Opera, and IE.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/src/event.js

    r4238 r4245  
    490490    readyBound = true; 
    491491 
    492     // Mozilla, Opera and webkit nightlies currently support this event 
    493     if ( document.addEventListener ) 
     492    // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event 
     493    if ( document.addEventListener && !jQuery.browser.opera) 
    494494        // Use the handy event callback 
    495495        document.addEventListener( "DOMContentLoaded", jQuery.ready, false ); 
    496496     
    497     // If Safari or IE is used 
     497    // If IE is used and is not in a frame 
    498498    // Continually check to see if the document is ready 
    499     if (jQuery.browser.msie || jQuery.browser.safari ) (function(){ 
     499    if ( jQuery.browser.msie && window == top ) (function(){ 
     500        if (jQuery.isReady) return; 
    500501        try { 
    501502            // If IE is used, use the trick by Diego Perini 
    502503            // http://javascript.nwbox.com/IEContentLoaded/ 
    503             if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" ) 
    504                 document.documentElement.doScroll("left"); 
     504            document.documentElement.doScroll("left"); 
    505505        } catch( error ) { 
    506             return setTimeout( arguments.callee, 0 ); 
    507         } 
    508  
     506            setTimeout( arguments.callee, 0 ); 
     507            return; 
     508        } 
    509509        // and execute any waiting functions 
    510510        jQuery.ready(); 
    511511    })(); 
     512 
     513    if ( jQuery.browser.opera ) 
     514        document.addEventListener( "DOMContentLoaded", function () { 
     515            if (jQuery.isReady) return; 
     516            for (var i = 0; i < document.styleSheets.length; i++) 
     517                if (document.styleSheets[i].disabled) { 
     518                    setTimeout( arguments.callee, 0 ); 
     519                    return; 
     520                } 
     521            // and execute any waiting functions 
     522            jQuery.ready(); 
     523        }, false); 
     524 
     525    if ( jQuery.browser.safari ) { 
     526        var numStyles; 
     527        (function(){ 
     528            if (jQuery.isReady) return; 
     529            if ( document.readyState != "loaded" && document.readyState != "complete" ) { 
     530                setTimeout( arguments.callee, 0 ); 
     531                return; 
     532            } 
     533            if ( numStyles === undefined ) 
     534                numStyles = jQuery("style, link[rel=stylesheet]").length; 
     535            if ( document.styleSheets.length != numStyles ) { 
     536                setTimeout( arguments.callee, 0 ); 
     537                return; 
     538            } 
     539            // and execute any waiting functions 
     540            jQuery.ready(); 
     541        })(); 
     542    } 
    512543 
    513544    // A fallback to window.onload, that will always work