Make sure that document.body exists, at least, in IE before the ready event is fired...
[jquery.git] / src / event.js
index c3c978b..f9c5fae 100644 (file)
@@ -405,7 +405,7 @@ jQuery.event = {
                        add: function( proxy, data, namespaces ) {
                                jQuery.extend( proxy, data || {} );
                                proxy.guid += data.selector + data.live;
-                               jQuery.event.add( this, data.live, liveHandler );
+                               jQuery.event.add( this, data.live, liveHandler, data );
                        },
 
                        remove: function( namespaces ) {
@@ -467,6 +467,7 @@ jQuery.Event.prototype = {
                if ( !e ) {
                        return;
                }
+               
                // if preventDefault exists run it on the original event
                if ( e.preventDefault ) {
                        e.preventDefault();
@@ -533,6 +534,41 @@ jQuery.each({
        };
 });
 
+(function() {
+       
+       var event = jQuery.event,
+               special = event.special,
+               handle  = event.handle;
+
+       special.submit = {
+               setup: function(data, namespaces) {
+                       if(data.selector) {
+                               event.add(this, 'click.specialSubmit', function(e, eventData) {
+                                       if(jQuery(e.target).filter(":submit, :image").closest(data.selector).length) {
+                                               e.type = "submit";
+                                               return handle.call( this, e, eventData );
+                                       }
+                               });
+                               
+                               event.add(this, 'keypress.specialSubmit', function( e, eventData ) {
+                                       if(jQuery(e.target).filter(":text, :password").closest(data.selector).length) {
+                                               e.type = "submit";
+                                               return handle.call( this, e, eventData );
+                                       }
+                               });
+                       } else {
+                               return false;
+                       }
+               },
+               
+               remove: function(namespaces) {
+                       event.remove(this, 'click.specialSubmit');
+                       event.remove(this, 'keypress.specialSubmit');
+               }
+       };
+       
+})();
+
 // Create "bubbling" focus and blur events
 jQuery.each({
        focus: "focusin",
@@ -564,7 +600,16 @@ jQuery.each({
 });
 
 jQuery.fn.extend({
+       // TODO: make bind(), unbind() and one() DRY!
        bind: function( type, data, fn, thisObject ) {
+               // Handle object literals
+               if ( typeof type === "object" ) {
+                       for ( var key in type ) {
+                               this.bind(key, data, type[key], fn);
+                       }
+                       return this;
+               }
+               
                if ( jQuery.isFunction( data ) ) {
                        thisObject = fn;
                        fn = data;
@@ -577,6 +622,14 @@ jQuery.fn.extend({
        },
 
        one: function( type, data, fn, thisObject ) {
+               // Handle object literals
+               if ( typeof type === "object" ) {
+                       for ( var key in type ) {
+                               this.one(key, data, type[key], fn);
+                       }
+                       return this;
+               }
+               
                if ( jQuery.isFunction( data ) ) {
                        thisObject = fn;
                        fn = data;
@@ -593,6 +646,14 @@ jQuery.fn.extend({
        },
 
        unbind: function( type, fn ) {
+               // Handle object literals
+               if ( typeof type === "object" && !type.preventDefault ) {
+                       for ( var key in type ) {
+                               this.unbind(key, type[key]);
+                       }
+                       return this;
+               }
+               
                return this.each(function() {
                        jQuery.event.remove( this, type, fn );
                });
@@ -761,7 +822,8 @@ function bindReady() {
                // ensure firing before onload,
                // maybe late but safe also for iframes
                document.attachEvent("onreadystatechange", function() {
-                       if ( document.readyState === "complete" ) {
+                       // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
+                       if ( document.readyState === "complete" && document.body ) {
                                document.detachEvent( "onreadystatechange", arguments.callee );
                                jQuery.ready();
                        }
@@ -769,7 +831,8 @@ function bindReady() {
 
                // If IE and not an iframe
                // continually check to see if the document is ready
-               if ( document.documentElement.doScroll && window === window.top ) (function() {
+               // NOTE: DO NOT CHANGE TO ===, FAILS IN IE.
+               if ( document.documentElement.doScroll && window == window.top ) (function() {
                        if ( jQuery.isReady ) {
                                return;
                        }
@@ -792,9 +855,9 @@ function bindReady() {
        jQuery.event.add( window, "load", jQuery.ready );
 }
 
-jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
-       "mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +
-       "change,select,submit,keydown,keypress,keyup,error").split(","), function( i, name ) {
+jQuery.each( ("blur focus load resize scroll unload click dblclick " +
+       "mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
+       "change select submit keydown keypress keyup error").split(" "), function( i, name ) {
 
        // Handle event binding
        jQuery.fn[ name ] = function( fn ) {