remove box global var from offset
[jquery.git] / src / offset.js
index 6289ad2..f59fb9b 100644 (file)
@@ -1,16 +1,19 @@
+// The Offset Method
+// Originally By Brandon Aaron, part of the Dimension Plugin
+// http://jquery.com/plugins/project/dimensions
 jQuery.fn.offset = function() {
        var left = 0, top = 0, elem = this[0], results;
        
        if ( elem ) with ( jQuery.browser ) {
-               var     absolute        = jQuery.css(elem, "position") == "absolute", 
-                       parent          = elem.parentNode, 
-                       offsetParent    = elem.offsetParent, 
-                       doc             = elem.ownerDocument,
-                       safari2         = safari && !absolute && parseInt(version) < 522;
+               var     absolute     = jQuery.css(elem, "position") == "absolute", 
+                   parent       = elem.parentNode, 
+                   offsetParent = elem.offsetParent, 
+                   doc          = elem.ownerDocument,
+                   safari2      = safari && parseInt(version) < 522;
        
                // Use getBoundingClientRect if available
                if ( elem.getBoundingClientRect ) {
-                       box = elem.getBoundingClientRect();
+                       var box = elem.getBoundingClientRect();
                
                        // Add the document scroll offsets
                        add(
@@ -52,9 +55,9 @@ jQuery.fn.offset = function() {
                        }
                
                        // Get parent scroll offsets
-                       while ( parent.tagName && /^body|html$/i.test(parent.tagName) ) {
+                       while ( parent.tagName && !/^body|html$/i.test(parent.tagName) ) {
                                // Work around opera inline/table scrollLeft/Top bug
-                               if ( /^inline|table-row.*$/i.test(jQuery.css(parent, "display")) )
+                               if ( !/^inline|table-row.*$/i.test(jQuery.css(parent, "display")) )
                                        // Subtract parent scroll offsets
                                        add( -parent.scrollLeft, -parent.scrollTop );
                        
@@ -67,7 +70,7 @@ jQuery.fn.offset = function() {
                        }
                
                        // Safari doubles body offsets with an absolutely positioned element or parent
-                       if ( safari && absolute )
+                       if ( safari2 && absolute )
                                add( -doc.body.offsetLeft, -doc.body.offsetTop );
                }