Simplifying the DOM ready code, no longer attempting to handle stylesheet loading...
[jquery.git] / src / event.js
index f082e7e..5be849f 100644 (file)
@@ -21,7 +21,7 @@ jQuery.event = {
                        handler.guid = this.guid++;
 
                // if data is passed, bind to handler
-               if( data != undefined ) {
+               if ( data !== undefined ) {
                        // Create temporary function pointer to original handler
                        var fn = handler;
 
@@ -40,7 +40,7 @@ jQuery.event = {
                        handle = jQuery.data(elem, "handle") || jQuery.data(elem, "handle", function(){
                                // Handle the second event of a trigger and when
                                // an event is called after a page has unloaded
-                               if ( typeof jQuery != "undefined" && !jQuery.event.triggered )
+                               if ( typeof jQuery !== "undefined" && !jQuery.event.triggered )
                                        return jQuery.event.handle.apply(arguments.callee.elem, arguments);
                        });
                // Add elem as a property of the handle function
@@ -99,7 +99,7 @@ jQuery.event = {
 
                if ( events ) {
                        // Unbind all events for the element
-                       if ( types == undefined || (typeof types == "string" && types.charAt(0) == ".") )
+                       if ( types === undefined || (typeof types === "string" && types.charAt(0) == ".") )
                                for ( var type in events )
                                        this.remove( elem, type + (types || "") );
                        else {
@@ -219,7 +219,7 @@ jQuery.event = {
                                // call the extra function and tack the current return value on the end for possible inspection
                                ret = extra.apply( elem, val == null ? data : data.concat( val ) );
                                // if anything is returned, give it precedence and have it overwrite the previous value
-                               if (ret !== undefined)
+                               if ( ret !== undefined )
                                        val = ret;
                        }
 
@@ -521,27 +521,30 @@ function bindReady(){
        if ( readyBound ) return;
        readyBound = true;
 
-       // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
-       if ( document.addEventListener && !jQuery.browser.opera)
+       // Mozilla, Opera and webkit nightlies currently support this event
+       if ( document.addEventListener ) {
                // Use the handy event callback
-               document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
+               document.addEventListener( "DOMContentLoaded", function(){
+                       document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
+                       jQuery.ready();
+               }, false );
 
        // If IE event model is used
-       if ( document.attachEvent )
+       } else if ( document.attachEvent ) {
                // ensure firing before onload,
                // maybe late but safe also for iframes
-               document.attachEvent("onreadystatechange", function(e) {
-                       if ( document.readyState == "complete" ) {
-                               document.detachEvent("onreadystatechange", arguments.callee );
+               document.attachEvent("onreadystatechange", function(){
+                       if ( document.readyState === "complete" ) {
+                               document.detachEvent( "onreadystatechange", arguments.callee );
                                jQuery.ready();
                        }
                });
 
-       // If IE and not an iframe
-       if ( document.documentElement.doScroll && !window.frameElement )
+               // If IE and not an iframe
                // continually check to see if the document is ready
-               (function(){
-                       if (jQuery.isReady) return;
+               if ( document.documentElement.doScroll && !window.frameElement ) (function(){
+                       if ( jQuery.isReady ) return;
+
                        try {
                                // If IE is used, use the trick by Diego Perini
                                // http://javascript.nwbox.com/IEContentLoaded/
@@ -550,36 +553,7 @@ function bindReady(){
                                setTimeout( arguments.callee, 0 );
                                return;
                        }
-                       // and execute any waiting functions
-                       jQuery.ready();
-               })();
 
-       if ( jQuery.browser.opera )
-               document.addEventListener( "DOMContentLoaded", function () {
-                       if (jQuery.isReady) return;
-                       for (var i = 0; i < document.styleSheets.length; i++)
-                               if (document.styleSheets[i].disabled) {
-                                       setTimeout( arguments.callee, 0 );
-                                       return;
-                               }
-                       // and execute any waiting functions
-                       jQuery.ready();
-               }, false);
-
-       if ( jQuery.browser.safari ) {
-               var numStyles;
-               (function(){
-                       if (jQuery.isReady) return;
-                       if ( document.readyState != "loaded" && document.readyState != "complete" ) {
-                               setTimeout( arguments.callee, 0 );
-                               return;
-                       }
-                       if ( numStyles === undefined )
-                               numStyles = jQuery("style, link[rel=stylesheet]").length;
-                       if ( document.styleSheets.length != numStyles ) {
-                               setTimeout( arguments.callee, 0 );
-                               return;
-                       }
                        // and execute any waiting functions
                        jQuery.ready();
                })();