fix the long standing 2px offset issue in QuirksMode in IE
[jquery.git] / src / event.js
index 324024f..f082e7e 100644 (file)
@@ -190,6 +190,7 @@ jQuery.event = {
                                        target: elem,
                                        preventDefault: function(){},
                                        stopPropagation: function(){},
+                                       stopImmediatePropagation:stopImmediatePropagation,
                                        timeStamp: now()
                                });
                                data[0][expando] = true; // no need to fix fake event
@@ -271,6 +272,10 @@ jQuery.event = {
                                        event.preventDefault();
                                        event.stopPropagation();
                                }
+
+                               if( event._sip )
+                                       break;
+
                        }
                }
 
@@ -280,7 +285,7 @@ jQuery.event = {
        props: "altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target timeStamp toElement type view wheelDelta which".split(" "),
 
        fix: function(event) {
-               if ( event[expando] == true )
+               if ( event[expando] )
                        return event;
 
                // store a copy of the original event object
@@ -313,6 +318,8 @@ jQuery.event = {
                        originalEvent.cancelBubble = true;
                };
 
+               event.stopImmediatePropagation = stopImmediatePropagation;
+
                // Fix timeStamp
                event.timeStamp = event.timeStamp || now();
 
@@ -367,6 +374,11 @@ jQuery.event = {
        }
 };
 
+function stopImmediatePropagation(){
+       this._sip = 1;
+       this.stopPropagation();
+}
+
 if ( !jQuery.browser.msie ){   
        // Checks if an event happened on an element within another element
        // Used in jQuery.event.special.mouseenter and mouseleave handlers
@@ -455,7 +467,7 @@ jQuery.fn.extend({
        },
 
        hover: function(fnOver, fnOut) {
-               return this.bind('mouseenter', fnOver).bind('mouseleave', fnOut);
+               return this.mouseenter(fnOver).mouseleave(fnOut);
        },
 
        ready: function(fn) {
@@ -514,21 +526,33 @@ function bindReady(){
                // Use the handy event callback
                document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
 
-       // If IE is used and is not in a frame
-       // Continually check to see if the document is ready
-       if ( jQuery.browser.msie && window == top ) (function(){
-               if (jQuery.isReady) return;
-               try {
-                       // If IE is used, use the trick by Diego Perini
-                       // http://javascript.nwbox.com/IEContentLoaded/
-                       document.documentElement.doScroll("left");
-               } catch( error ) {
-                       setTimeout( arguments.callee, 0 );
-                       return;
-               }
-               // and execute any waiting functions
-               jQuery.ready();
-       })();
+       // If IE event model is used
+       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 );
+                               jQuery.ready();
+                       }
+               });
+
+       // If IE and not an iframe
+       if ( document.documentElement.doScroll && !window.frameElement )
+               // continually check to see if the document is ready
+               (function(){
+                       if (jQuery.isReady) return;
+                       try {
+                               // If IE is used, use the trick by Diego Perini
+                               // http://javascript.nwbox.com/IEContentLoaded/
+                               document.documentElement.doScroll("left");
+                       } catch( error ) {
+                               setTimeout( arguments.callee, 0 );
+                               return;
+                       }
+                       // and execute any waiting functions
+                       jQuery.ready();
+               })();
 
        if ( jQuery.browser.opera )
                document.addEventListener( "DOMContentLoaded", function () {
@@ -566,8 +590,8 @@ function bindReady(){
 }
 
 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
-       "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," +
-       "submit,keydown,keypress,keyup,error").split(","), function(i, name){
+       "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){