2010-09-08 16:00:29 +00:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
var getOffset,
|
2010-09-22 13:16:28 +00:00
|
|
|
rroot = /^(?:body|html)$/i;
|
|
|
|
|
2009-07-25 16:04:30 +00:00
|
|
|
if ( "getBoundingClientRect" in document.documentElement ) {
|
2012-04-06 01:51:27 +00:00
|
|
|
getOffset = function( elem, doc, docElem ) {
|
|
|
|
var box;
|
|
|
|
|
2010-09-28 14:55:48 +00:00
|
|
|
try {
|
|
|
|
box = elem.getBoundingClientRect();
|
2010-10-14 18:52:31 +00:00
|
|
|
} catch(e) {}
|
2010-09-28 14:55:48 +00:00
|
|
|
|
2010-10-14 18:52:31 +00:00
|
|
|
// Make sure we're not dealing with a disconnected DOM node
|
|
|
|
if ( !box || !jQuery.contains( docElem, elem ) ) {
|
2010-11-22 23:26:46 +00:00
|
|
|
return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
|
2010-09-28 14:55:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-14 18:52:31 +00:00
|
|
|
var body = doc.body,
|
2011-12-06 20:25:38 +00:00
|
|
|
win = getWindow( doc ),
|
2010-02-28 01:43:23 +00:00
|
|
|
clientTop = docElem.clientTop || body.clientTop || 0,
|
|
|
|
clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
2011-03-31 06:55:16 +00:00
|
|
|
scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
|
|
|
|
scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
|
2010-02-28 01:43:23 +00:00
|
|
|
top = box.top + scrollTop - clientTop,
|
|
|
|
left = box.left + scrollLeft - clientLeft;
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2008-11-10 02:39:03 +00:00
|
|
|
return { top: top, left: left };
|
|
|
|
};
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2009-07-25 16:04:30 +00:00
|
|
|
} else {
|
2011-12-06 20:25:38 +00:00
|
|
|
getOffset = function( elem, doc, docElem ) {
|
2012-04-06 01:51:27 +00:00
|
|
|
if ( !jQuery.contains( docElem, elem ) ) {
|
|
|
|
return { top: 0, left: 0 };
|
2009-07-25 16:04:30 +00:00
|
|
|
}
|
2012-04-06 01:51:27 +00:00
|
|
|
var point = getWindow( doc ).webkitConvertPointFromNodeToPage( elem, new WebKitPoint( 0, 0 ) );
|
|
|
|
return { top: point.y, left: point.x };
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-11-10 02:39:03 +00:00
|
|
|
};
|
2009-07-25 16:04:30 +00:00
|
|
|
}
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2011-12-06 20:25:38 +00:00
|
|
|
jQuery.fn.offset = function( options ) {
|
|
|
|
if ( arguments.length ) {
|
|
|
|
return options === undefined ?
|
|
|
|
this :
|
|
|
|
this.each(function( i ) {
|
|
|
|
jQuery.offset.setOffset( this, options, i );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var elem = this[0],
|
|
|
|
doc = elem && elem.ownerDocument;
|
|
|
|
|
|
|
|
if ( !doc ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( elem === doc.body ) {
|
|
|
|
return jQuery.offset.bodyOffset( elem );
|
|
|
|
}
|
|
|
|
|
|
|
|
return getOffset( elem, doc, doc.documentElement );
|
|
|
|
};
|
|
|
|
|
2011-10-31 16:33:55 +00:00
|
|
|
jQuery.offset = {
|
2008-11-10 02:39:03 +00:00
|
|
|
|
2009-09-15 19:15:04 +00:00
|
|
|
bodyOffset: function( body ) {
|
2010-11-09 16:09:07 +00:00
|
|
|
var top = body.offsetTop,
|
|
|
|
left = body.offsetLeft;
|
2009-07-25 16:04:30 +00:00
|
|
|
|
2011-10-31 16:33:55 +00:00
|
|
|
if ( jQuery.support.doesNotIncludeMarginInBodyOffset ) {
|
2010-09-16 14:00:56 +00:00
|
|
|
top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
|
|
|
|
left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
|
2009-07-25 16:04:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 02:39:03 +00:00
|
|
|
return { top: top, left: left };
|
2009-09-15 19:15:04 +00:00
|
|
|
},
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2010-01-07 19:08:32 +00:00
|
|
|
setOffset: function( elem, options, i ) {
|
2010-09-05 14:17:18 +00:00
|
|
|
var position = jQuery.css( elem, "position" );
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2009-09-15 19:15:04 +00:00
|
|
|
// set position first, in-case top/left are set even on static elem
|
2010-03-23 00:11:37 +00:00
|
|
|
if ( position === "static" ) {
|
2009-12-22 01:13:16 +00:00
|
|
|
elem.style.position = "relative";
|
2009-09-15 19:15:04 +00:00
|
|
|
}
|
2010-03-23 00:11:37 +00:00
|
|
|
|
2010-09-05 14:17:18 +00:00
|
|
|
var curElem = jQuery( elem ),
|
|
|
|
curOffset = curElem.offset(),
|
2010-09-16 14:00:56 +00:00
|
|
|
curCSSTop = jQuery.css( elem, "top" ),
|
|
|
|
curCSSLeft = jQuery.css( elem, "left" ),
|
2011-10-27 19:33:21 +00:00
|
|
|
calculatePosition = ( position === "absolute" || position === "fixed" ) && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
|
2010-03-23 00:11:37 +00:00
|
|
|
props = {}, curPosition = {}, curTop, curLeft;
|
|
|
|
|
2011-03-24 23:02:38 +00:00
|
|
|
// need to be able to calculate position if either top or left is auto and position is either absolute or fixed
|
2010-03-23 00:11:37 +00:00
|
|
|
if ( calculatePosition ) {
|
|
|
|
curPosition = curElem.position();
|
2011-01-15 12:56:20 +00:00
|
|
|
curTop = curPosition.top;
|
|
|
|
curLeft = curPosition.left;
|
|
|
|
} else {
|
|
|
|
curTop = parseFloat( curCSSTop ) || 0;
|
|
|
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
2010-03-23 00:11:37 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 19:07:21 +00:00
|
|
|
if ( jQuery.isFunction( options ) ) {
|
|
|
|
options = options.call( elem, i, curOffset );
|
|
|
|
}
|
|
|
|
|
2011-10-27 19:33:21 +00:00
|
|
|
if ( options.top != null ) {
|
|
|
|
props.top = ( options.top - curOffset.top ) + curTop;
|
2010-03-23 00:05:08 +00:00
|
|
|
}
|
2011-10-27 19:33:21 +00:00
|
|
|
if ( options.left != null ) {
|
|
|
|
props.left = ( options.left - curOffset.left ) + curLeft;
|
2010-03-23 00:05:08 +00:00
|
|
|
}
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2009-12-22 01:13:16 +00:00
|
|
|
if ( "using" in options ) {
|
2009-09-15 19:15:04 +00:00
|
|
|
options.using.call( elem, props );
|
|
|
|
} else {
|
|
|
|
curElem.css( props );
|
|
|
|
}
|
2008-11-10 02:39:03 +00:00
|
|
|
}
|
2011-10-31 16:33:55 +00:00
|
|
|
};
|
2008-03-15 18:53:40 +00:00
|
|
|
|
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
jQuery.fn.extend({
|
2011-09-20 01:03:41 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
position: function() {
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( !this[0] ) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-03-17 20:50:17 +00:00
|
|
|
|
2009-04-21 19:19:28 +00:00
|
|
|
var elem = this[0],
|
2009-03-17 20:50:17 +00:00
|
|
|
|
|
|
|
// Get *real* offsetParent
|
|
|
|
offsetParent = this.offsetParent(),
|
|
|
|
|
|
|
|
// Get correct offsets
|
|
|
|
offset = this.offset(),
|
2010-09-22 13:16:28 +00:00
|
|
|
parentOffset = rroot.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset();
|
2009-03-17 20:50:17 +00:00
|
|
|
|
|
|
|
// Subtract element margins
|
2009-03-23 01:55:17 +00:00
|
|
|
// note: when an element has margin: auto the offsetLeft and marginLeft
|
2009-03-17 20:50:17 +00:00
|
|
|
// are the same in Safari causing offset.left to incorrectly be 0
|
2010-09-16 14:00:56 +00:00
|
|
|
offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0;
|
|
|
|
offset.left -= parseFloat( jQuery.css(elem, "marginLeft") ) || 0;
|
2009-03-17 20:50:17 +00:00
|
|
|
|
|
|
|
// Add offsetParent borders
|
2010-09-16 14:00:56 +00:00
|
|
|
parentOffset.top += parseFloat( jQuery.css(offsetParent[0], "borderTopWidth") ) || 0;
|
|
|
|
parentOffset.left += parseFloat( jQuery.css(offsetParent[0], "borderLeftWidth") ) || 0;
|
2009-03-17 20:50:17 +00:00
|
|
|
|
|
|
|
// Subtract the two offsets
|
2009-04-21 19:19:28 +00:00
|
|
|
return {
|
2009-03-17 20:50:17 +00:00
|
|
|
top: offset.top - parentOffset.top,
|
|
|
|
left: offset.left - parentOffset.left
|
|
|
|
};
|
2008-04-29 03:26:06 +00:00
|
|
|
},
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
offsetParent: function() {
|
2009-12-22 00:58:13 +00:00
|
|
|
return this.map(function() {
|
2009-07-25 16:04:30 +00:00
|
|
|
var offsetParent = this.offsetParent || document.body;
|
2010-09-22 13:16:28 +00:00
|
|
|
while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
|
2009-07-25 16:04:30 +00:00
|
|
|
offsetParent = offsetParent.offsetParent;
|
|
|
|
}
|
|
|
|
return offsetParent;
|
|
|
|
});
|
2008-04-29 03:26:06 +00:00
|
|
|
}
|
2008-03-15 18:53:40 +00:00
|
|
|
});
|
|
|
|
|
2008-04-29 03:26:06 +00:00
|
|
|
|
|
|
|
// Create scrollLeft and scrollTop methods
|
2011-12-06 20:25:38 +00:00
|
|
|
jQuery.each( {scrollLeft: "pageXOffset", scrollTop: "pageYOffset"}, function( method, prop ) {
|
|
|
|
var top = /Y/.test( prop );
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2011-01-18 17:40:07 +00:00
|
|
|
jQuery.fn[ method ] = function( val ) {
|
2011-12-06 20:25:38 +00:00
|
|
|
return jQuery.access( this, function( elem, method, val ) {
|
|
|
|
var win = getWindow( elem );
|
|
|
|
|
|
|
|
if ( val === undefined ) {
|
|
|
|
return win ? (prop in win) ? win[ prop ] :
|
|
|
|
jQuery.support.boxModel && win.document.documentElement[ method ] ||
|
|
|
|
win.document.body[ method ] :
|
|
|
|
elem[ method ];
|
2011-01-10 01:51:20 +00:00
|
|
|
}
|
2009-12-22 00:58:13 +00:00
|
|
|
|
2011-01-10 01:51:20 +00:00
|
|
|
if ( win ) {
|
|
|
|
win.scrollTo(
|
2011-12-06 20:25:38 +00:00
|
|
|
!top ? val : jQuery( win ).scrollLeft(),
|
2012-01-20 02:47:23 +00:00
|
|
|
top ? val : jQuery( win ).scrollTop()
|
2011-01-10 01:51:20 +00:00
|
|
|
);
|
2011-04-12 20:13:56 +00:00
|
|
|
|
2011-01-10 01:51:20 +00:00
|
|
|
} else {
|
2011-12-06 20:25:38 +00:00
|
|
|
elem[ method ] = val;
|
2011-01-10 01:51:20 +00:00
|
|
|
}
|
2011-12-06 20:25:38 +00:00
|
|
|
}, method, val, arguments.length, null );
|
2008-04-29 03:26:06 +00:00
|
|
|
};
|
2008-04-30 19:35:17 +00:00
|
|
|
});
|
2009-07-24 22:32:53 +00:00
|
|
|
|
|
|
|
function getWindow( elem ) {
|
2010-09-22 20:41:51 +00:00
|
|
|
return jQuery.isWindow( elem ) ?
|
2009-07-25 16:04:30 +00:00
|
|
|
elem :
|
|
|
|
elem.nodeType === 9 ?
|
|
|
|
elem.defaultView || elem.parentWindow :
|
2009-07-24 22:32:53 +00:00
|
|
|
false;
|
|
|
|
}
|
2010-09-08 16:00:29 +00:00
|
|
|
|
|
|
|
})( jQuery );
|