aboutsummaryrefslogtreecommitdiffstats
path: root/src/offset.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2009-12-21 19:58:13 -0500
committerjeresig <jeresig@gmail.com>2009-12-21 19:58:13 -0500
commit61e37d41490aed319a176c6ca7feb95e5505059c (patch)
tree62b7c9bbb5cba5f15c2a134a51dac84b35e0d0ce /src/offset.js
parent36c99dc0c7a745a88488f519b38de811d6d4c8d9 (diff)
downloadjquery-61e37d41490aed319a176c6ca7feb95e5505059c.tar.gz
jquery-61e37d41490aed319a176c6ca7feb95e5505059c.zip
Made a number of spacing changes to bring the code more-inline with the jQuery Core Style Guideline.
Diffstat (limited to 'src/offset.js')
-rw-r--r--src/offset.js43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/offset.js b/src/offset.js
index 8268ce726..692583900 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -1,12 +1,17 @@
if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) {
var elem = this[0];
- if ( !elem || !elem.ownerDocument ) { return null; }
+
+ if ( !elem || !elem.ownerDocument ) {
+ return null;
+ }
+
if ( options ) {
return this.each(function() {
jQuery.offset.setOffset( this, options );
});
}
+
if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem );
}
@@ -15,17 +20,24 @@ if ( "getBoundingClientRect" in document.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;
+
return { top: top, left: left };
};
+
} else {
jQuery.fn.offset = function( options ) {
var elem = this[0];
- if ( !elem || !elem.ownerDocument ) { return null; }
+
+ if ( !elem || !elem.ownerDocument ) {
+ return null;
+ }
+
if ( options ) {
return this.each(function() {
jQuery.offset.setOffset( this, options );
});
}
+
if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem );
}
@@ -39,7 +51,9 @@ if ( "getBoundingClientRect" in document.documentElement ) {
top = elem.offsetTop, left = elem.offsetLeft;
while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
- if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { break; }
+ if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
+ break;
+ }
computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
top -= elem.scrollTop;
@@ -107,7 +121,7 @@ jQuery.offset = {
body.removeChild( container );
body = container = innerDiv = checkDiv = table = td = null;
- jQuery.offset.initialize = function(){};
+ jQuery.offset.initialize = function() {};
},
bodyOffset: function( body ) {
@@ -148,7 +162,9 @@ jQuery.offset = {
jQuery.fn.extend({
position: function() {
- if ( !this[0] ) { return null; }
+ if ( !this[0] ) {
+ return null;
+ }
var elem = this[0],
@@ -177,7 +193,7 @@ jQuery.fn.extend({
},
offsetParent: function() {
- return this.map(function(){
+ return this.map(function() {
var offsetParent = this.offsetParent || document.body;
while ( offsetParent && (!/^body|html$/i.test(offsetParent.nodeName) && jQuery.css(offsetParent, 'position') === 'static') ) {
offsetParent = offsetParent.offsetParent;
@@ -189,25 +205,30 @@ jQuery.fn.extend({
// Create scrollLeft and scrollTop methods
-jQuery.each( ['Left', 'Top'], function(i, name) {
- var method = 'scroll' + name;
+jQuery.each( ["Left", "Top"], function( i, name ) {
+ var method = "scroll" + name;
jQuery.fn[ method ] = function(val) {
var elem = this[0], win;
- if ( !elem ) { return null; }
+ if ( !elem ) {
+ return null;
+ }
if ( val !== undefined ) {
// Set the scroll offset
return this.each(function() {
win = getWindow( this );
- win ?
+ if ( win ) {
win.scrollTo(
!i ? val : jQuery(win).scrollLeft(),
i ? val : jQuery(win).scrollTop()
- ) :
+ );
+
+ } else {
this[ method ] = val;
+ }
});
} else {
win = getWindow( elem );