Made it so that you no longer need to build jQuery in order to run the test suite...
[jquery.git] / src / offset.js
index c318374..365b35a 100644 (file)
@@ -2,24 +2,31 @@ if ( "getBoundingClientRect" in document.documentElement ) {
        jQuery.fn.offset = function( options ) {
                var elem = this[0];
 
-               if ( !elem || !elem.ownerDocument ) {
-                       return null;
-               }
-
                if ( options ) { 
                        return this.each(function( i ) {
                                jQuery.offset.setOffset( this, options, i );
                        });
                }
 
+               if ( !elem || !elem.ownerDocument ) {
+                       return null;
+               }
+
                if ( elem === elem.ownerDocument.body ) {
                        return jQuery.offset.bodyOffset( elem );
                }
 
-               var box = elem.getBoundingClientRect(), doc = elem.ownerDocument, body = doc.body, docElem = doc.documentElement,
-                       clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0,
-                       top  = box.top  + (self.pageYOffset || jQuery.support.boxModel && docElem.scrollTop  || body.scrollTop ) - clientTop,
-                       left = box.left + (self.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft) - clientLeft;
+               var box = elem.getBoundingClientRect(),
+                       doc = elem.ownerDocument,
+                       body = doc.body,
+                       docElem = doc.documentElement,
+                       win = getWindow(doc),
+                       clientTop  = docElem.clientTop  || body.clientTop  || 0,
+                       clientLeft = docElem.clientLeft || body.clientLeft || 0,
+                       scrollTop  = (win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop  || body.scrollTop ),
+                       scrollLeft = (win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft),
+                       top  = box.top  + scrollTop  - clientTop,
+                       left = box.left + scrollLeft - clientLeft;
 
                return { top: top, left: left };
        };
@@ -28,16 +35,16 @@ if ( "getBoundingClientRect" in document.documentElement ) {
        jQuery.fn.offset = function( options ) {
                var elem = this[0];
 
-               if ( !elem || !elem.ownerDocument ) {
-                       return null;
-               }
-
                if ( options ) { 
                        return this.each(function( i ) {
                                jQuery.offset.setOffset( this, options, i );
                        });
                }
 
+               if ( !elem || !elem.ownerDocument ) {
+                       return null;
+               }
+
                if ( elem === elem.ownerDocument.body ) {
                        return jQuery.offset.bodyOffset( elem );
                }
@@ -68,7 +75,8 @@ if ( "getBoundingClientRect" in document.documentElement ) {
                                        left += parseFloat( computedStyle.borderLeftWidth ) || 0;
                                }
 
-                               prevOffsetParent = offsetParent, offsetParent = elem.offsetParent;
+                               prevOffsetParent = offsetParent;
+                               offsetParent = elem.offsetParent;
                        }
 
                        if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
@@ -109,12 +117,16 @@ jQuery.offset = {
                this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
                this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
 
-               checkDiv.style.position = "fixed", checkDiv.style.top = "20px";
+               checkDiv.style.position = "fixed";
+               checkDiv.style.top = "20px";
+
                // safari subtracts parent border width here which is 5px
                this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15);
                checkDiv.style.position = checkDiv.style.top = "";
 
-               innerDiv.style.overflow = "hidden", innerDiv.style.position = "relative";
+               innerDiv.style.overflow = "hidden";
+               innerDiv.style.position = "relative";
+
                this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);
 
                this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);