jquery ajax: misc optimization for $.fn.load().
[jquery.git] / src / offset.js
index a35fed5..1ae3f2e 100644 (file)
@@ -14,7 +14,7 @@ jQuery.fn.offset = function() {
                    fixed        = css(elem, "position") == "fixed";
 
                // Use getBoundingClientRect if available
-               if ( elem.getBoundingClientRect ) {
+               if ( !(mozilla && elem == document.body) && elem.getBoundingClientRect ) {
                        var box = elem.getBoundingClientRect();
 
                        // Add the document scroll offsets
@@ -91,8 +91,8 @@ jQuery.fn.offset = function() {
        }
 
        function add(l, t) {
-               left += parseInt(l) || 0;
-               top += parseInt(t) || 0;
+               left += parseInt(l, 10) || 0;
+               top += parseInt(t, 10) || 0;
        }
 
        return results;
@@ -107,11 +107,13 @@ jQuery.fn.extend({
                        // Get *real* offsetParent
                        var offsetParent = this.offsetParent(),
 
-                               // Get correct offsets
-                               offset       = this.offset(),                           
-                               parentOffset = offsetParent.offset();
+                       // Get correct offsets
+                       offset       = this.offset(),
+                       parentOffset = /^body|html$/i.test(offsetParent[0].tagName) ? { top: 0, left: 0 } : offsetParent.offset();
 
                        // Subtract element margins
+                       // note: when an element has margin: auto the offsetLeft and marginLeft 
+                       // are the same in Safari causing offset.left to incorrectly be 0
                        offset.top  -= num( this, 'marginTop' );
                        offset.left -= num( this, 'marginLeft' );
 
@@ -130,7 +132,7 @@ jQuery.fn.extend({
        },
 
        offsetParent: function() {
-               var offsetParent = this[0].offsetParent;
+               var offsetParent = this[0].offsetParent || document.body;
                while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static') )
                        offsetParent = offsetParent.offsetParent;
                return jQuery(offsetParent);