2010-09-08 18:00:29 +02:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2010-09-22 15:16:28 +02:00
|
|
|
var rtable = /^t(?:able|d|h)$/i,
|
|
|
|
rroot = /^(?:body|html)$/i;
|
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
if ( "getBoundingClientRect" in document.documentElement ) {
|
2009-09-15 21:15:04 +02:00
|
|
|
jQuery.fn.offset = function( options ) {
|
2010-09-28 16:55:48 +02:00
|
|
|
var elem = this[0], box;
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2010-12-30 07:34:48 +01:00
|
|
|
if ( options ) {
|
2010-01-07 20:07:21 +01:00
|
|
|
return this.each(function( i ) {
|
2010-01-07 20:08:32 +01:00
|
|
|
jQuery.offset.setOffset( this, options, i );
|
2009-09-15 21:15:04 +02:00
|
|
|
});
|
|
|
|
}
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2010-01-21 16:18:54 +01:00
|
|
|
if ( !elem || !elem.ownerDocument ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
if ( elem === elem.ownerDocument.body ) {
|
|
|
|
return jQuery.offset.bodyOffset( elem );
|
|
|
|
}
|
|
|
|
|
2010-09-28 16:55:48 +02:00
|
|
|
try {
|
|
|
|
box = elem.getBoundingClientRect();
|
2010-10-14 20:52:31 +02:00
|
|
|
} catch(e) {}
|
2010-09-28 16:55:48 +02:00
|
|
|
|
2010-10-14 20:52:31 +02:00
|
|
|
var doc = elem.ownerDocument,
|
|
|
|
docElem = doc.documentElement;
|
|
|
|
|
|
|
|
// Make sure we're not dealing with a disconnected DOM node
|
|
|
|
if ( !box || !jQuery.contains( docElem, elem ) ) {
|
2010-11-23 00:26:46 +01:00
|
|
|
return box ? { top: box.top, left: box.left } : { top: 0, left: 0 };
|
2010-09-28 16:55:48 +02:00
|
|
|
}
|
|
|
|
|
2010-10-14 20:52:31 +02:00
|
|
|
var body = doc.body,
|
2010-02-28 02:43:23 +01:00
|
|
|
win = getWindow(doc),
|
|
|
|
clientTop = docElem.clientTop || body.clientTop || 0,
|
|
|
|
clientLeft = docElem.clientLeft || body.clientLeft || 0,
|
2011-03-31 08:55:16 +02:00
|
|
|
scrollTop = win.pageYOffset || jQuery.support.boxModel && docElem.scrollTop || body.scrollTop,
|
|
|
|
scrollLeft = win.pageXOffset || jQuery.support.boxModel && docElem.scrollLeft || body.scrollLeft,
|
2010-02-28 02:43:23 +01:00
|
|
|
top = box.top + scrollTop - clientTop,
|
|
|
|
left = box.left + scrollLeft - clientLeft;
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
return { top: top, left: left };
|
|
|
|
};
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
} else {
|
2009-09-15 21:15:04 +02:00
|
|
|
jQuery.fn.offset = function( options ) {
|
2009-03-17 21:43:46 +01:00
|
|
|
var elem = this[0];
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2010-12-30 07:34:48 +01:00
|
|
|
if ( options ) {
|
2010-01-07 20:07:21 +01:00
|
|
|
return this.each(function( i ) {
|
2010-01-07 20:08:32 +01:00
|
|
|
jQuery.offset.setOffset( this, options, i );
|
2009-09-15 21:15:04 +02:00
|
|
|
});
|
|
|
|
}
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2010-01-21 16:18:54 +01:00
|
|
|
if ( !elem || !elem.ownerDocument ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
if ( elem === elem.ownerDocument.body ) {
|
|
|
|
return jQuery.offset.bodyOffset( elem );
|
|
|
|
}
|
|
|
|
|
2009-03-19 04:17:38 +01:00
|
|
|
jQuery.offset.initialize();
|
2008-11-10 03:39:03 +01:00
|
|
|
|
2010-11-09 17:09:07 +01:00
|
|
|
var computedStyle,
|
|
|
|
offsetParent = elem.offsetParent,
|
|
|
|
prevOffsetParent = elem,
|
|
|
|
doc = elem.ownerDocument,
|
|
|
|
docElem = doc.documentElement,
|
|
|
|
body = doc.body,
|
|
|
|
defaultView = doc.defaultView,
|
2009-11-07 14:57:27 +01:00
|
|
|
prevComputedStyle = defaultView ? defaultView.getComputedStyle( elem, null ) : elem.currentStyle,
|
2010-11-09 17:09:07 +01:00
|
|
|
top = elem.offsetTop,
|
|
|
|
left = elem.offsetLeft;
|
2008-11-10 03:39:03 +01:00
|
|
|
|
|
|
|
while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) {
|
2009-12-22 01:58:13 +01:00
|
|
|
if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
|
|
|
|
break;
|
|
|
|
}
|
2009-07-25 18:04:30 +02:00
|
|
|
|
2009-11-07 14:57:27 +01:00
|
|
|
computedStyle = defaultView ? defaultView.getComputedStyle(elem, null) : elem.currentStyle;
|
2009-09-15 21:15:04 +02:00
|
|
|
top -= elem.scrollTop;
|
2009-07-25 18:04:30 +02:00
|
|
|
left -= elem.scrollLeft;
|
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
if ( elem === offsetParent ) {
|
2009-09-15 21:15:04 +02:00
|
|
|
top += elem.offsetTop;
|
2009-07-25 18:04:30 +02:00
|
|
|
left += elem.offsetLeft;
|
|
|
|
|
2010-09-22 15:16:28 +02:00
|
|
|
if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) {
|
2009-07-25 18:04:30 +02:00
|
|
|
top += parseFloat( computedStyle.borderTopWidth ) || 0;
|
2009-04-22 03:34:13 +02:00
|
|
|
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
|
|
|
|
2010-03-01 22:26:57 +01:00
|
|
|
prevOffsetParent = offsetParent;
|
|
|
|
offsetParent = elem.offsetParent;
|
2007-09-08 16:44:29 +02:00
|
|
|
}
|
2009-07-25 18:04:30 +02:00
|
|
|
|
|
|
|
if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) {
|
|
|
|
top += parseFloat( computedStyle.borderTopWidth ) || 0;
|
2009-04-22 03:34:13 +02:00
|
|
|
left += parseFloat( computedStyle.borderLeftWidth ) || 0;
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
prevComputedStyle = computedStyle;
|
|
|
|
}
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
if ( prevComputedStyle.position === "relative" || prevComputedStyle.position === "static" ) {
|
|
|
|
top += body.offsetTop;
|
2008-11-10 03:39:03 +01:00
|
|
|
left += body.offsetLeft;
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) {
|
|
|
|
top += Math.max( docElem.scrollTop, body.scrollTop );
|
2009-04-21 21:19:28 +02:00
|
|
|
left += Math.max( docElem.scrollLeft, body.scrollLeft );
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
return { top: top, left: left };
|
|
|
|
};
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
jQuery.offset = {
|
|
|
|
initialize: function() {
|
2010-09-16 16:00:56 +02:00
|
|
|
var body = document.body, container = document.createElement("div"), innerDiv, checkDiv, table, td, bodyMarginTop = parseFloat( jQuery.css(body, "marginTop") ) || 0,
|
2009-12-22 02:13:16 +01:00
|
|
|
html = "<div style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;'><div></div></div><table style='position:absolute;top:0;left:0;margin:0;border:5px solid #000;padding:0;width:1px;height:1px;' cellpadding='0' cellspacing='0'><tr><td></td></tr></table>";
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2009-12-22 02:13:16 +01:00
|
|
|
jQuery.extend( container.style, { position: "absolute", top: 0, left: 0, margin: 0, border: 0, width: "1px", height: "1px", visibility: "hidden" } );
|
2007-09-08 16:44:29 +02:00
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
container.innerHTML = html;
|
2009-04-21 21:19:28 +02:00
|
|
|
body.insertBefore( container, body.firstChild );
|
2009-07-25 18:04:30 +02:00
|
|
|
innerDiv = container.firstChild;
|
|
|
|
checkDiv = innerDiv.firstChild;
|
|
|
|
td = innerDiv.nextSibling.firstChild.firstChild;
|
2007-09-08 16:44:29 +02:00
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
this.doesNotAddBorder = (checkDiv.offsetTop !== 5);
|
|
|
|
this.doesAddBorderForTableAndCells = (td.offsetTop === 5);
|
2007-09-08 16:44:29 +02:00
|
|
|
|
2010-03-01 22:26:57 +01:00
|
|
|
checkDiv.style.position = "fixed";
|
|
|
|
checkDiv.style.top = "20px";
|
|
|
|
|
2009-07-25 18:04:30 +02:00
|
|
|
// safari subtracts parent border width here which is 5px
|
|
|
|
this.supportsFixedPosition = (checkDiv.offsetTop === 20 || checkDiv.offsetTop === 15);
|
2009-12-22 02:13:16 +01:00
|
|
|
checkDiv.style.position = checkDiv.style.top = "";
|
2009-03-19 03:54:57 +01:00
|
|
|
|
2010-03-01 22:26:57 +01:00
|
|
|
innerDiv.style.overflow = "hidden";
|
|
|
|
innerDiv.style.position = "relative";
|
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5);
|
|
|
|
|
2009-03-30 09:59:31 +02:00
|
|
|
this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop);
|
2007-12-16 02:03:50 +01:00
|
|
|
|
2009-04-21 21:19:28 +02:00
|
|
|
body.removeChild( container );
|
2009-12-31 15:50:49 +01:00
|
|
|
jQuery.offset.initialize = jQuery.noop;
|
2008-11-10 03:39:03 +01:00
|
|
|
},
|
|
|
|
|
2009-09-15 21:15:04 +02:00
|
|
|
bodyOffset: function( body ) {
|
2010-11-09 17:09:07 +01:00
|
|
|
var top = body.offsetTop,
|
|
|
|
left = body.offsetLeft;
|
2009-07-25 18:04:30 +02:00
|
|
|
|
|
|
|
jQuery.offset.initialize();
|
|
|
|
|
|
|
|
if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) {
|
2010-09-16 16:00:56 +02:00
|
|
|
top += parseFloat( jQuery.css(body, "marginTop") ) || 0;
|
|
|
|
left += parseFloat( jQuery.css(body, "marginLeft") ) || 0;
|
2009-07-25 18:04:30 +02:00
|
|
|
}
|
|
|
|
|
2008-11-10 03:39:03 +01:00
|
|
|
return { top: top, left: left };
|
2009-09-15 21:15:04 +02:00
|
|
|
},
|
2010-12-30 07:34:48 +01:00
|
|
|
|
2010-01-07 20:08:32 +01:00
|
|
|
setOffset: function( elem, options, i ) {
|
2010-09-05 16:17:18 +02:00
|
|
|
var position = jQuery.css( elem, "position" );
|
2010-03-23 01:11:37 +01:00
|
|
|
|
2009-09-15 21:15:04 +02:00
|
|
|
// set position first, in-case top/left are set even on static elem
|
2010-03-23 01:11:37 +01:00
|
|
|
if ( position === "static" ) {
|
2009-12-22 02:13:16 +01:00
|
|
|
elem.style.position = "relative";
|
2009-09-15 21:15:04 +02:00
|
|
|
}
|
2010-03-23 01:11:37 +01:00
|
|
|
|
2010-09-05 16:17:18 +02:00
|
|
|
var curElem = jQuery( elem ),
|
|
|
|
curOffset = curElem.offset(),
|
2010-09-16 16:00:56 +02:00
|
|
|
curCSSTop = jQuery.css( elem, "top" ),
|
|
|
|
curCSSLeft = jQuery.css( elem, "left" ),
|
2011-04-11 22:33:29 +02:00
|
|
|
calculatePosition = (position === "absolute" || position === "fixed") && jQuery.inArray("auto", [curCSSTop, curCSSLeft]) > -1,
|
2010-03-23 01:11:37 +01:00
|
|
|
props = {}, curPosition = {}, curTop, curLeft;
|
|
|
|
|
2011-03-25 00:02:38 +01: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 01:11:37 +01:00
|
|
|
if ( calculatePosition ) {
|
|
|
|
curPosition = curElem.position();
|
2011-01-15 13:56:20 +01:00
|
|
|
curTop = curPosition.top;
|
|
|
|
curLeft = curPosition.left;
|
|
|
|
} else {
|
|
|
|
curTop = parseFloat( curCSSTop ) || 0;
|
|
|
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
2010-03-23 01:11:37 +01:00
|
|
|
}
|
|
|
|
|
2010-01-07 20:07:21 +01:00
|
|
|
if ( jQuery.isFunction( options ) ) {
|
|
|
|
options = options.call( elem, i, curOffset );
|
|
|
|
}
|
|
|
|
|
2010-03-23 01:05:08 +01:00
|
|
|
if (options.top != null) {
|
|
|
|
props.top = (options.top - curOffset.top) + curTop;
|
|
|
|
}
|
|
|
|
if (options.left != null) {
|
|
|
|
props.left = (options.left - curOffset.left) + curLeft;
|
|
|
|
}
|
2010-12-30 07:34:48 +01:00
|
|
|
|
2009-12-22 02:13:16 +01:00
|
|
|
if ( "using" in options ) {
|
2009-09-15 21:15:04 +02:00
|
|
|
options.using.call( elem, props );
|
|
|
|
} else {
|
|
|
|
curElem.css( props );
|
|
|
|
}
|
2008-11-10 03:39:03 +01:00
|
|
|
}
|
2007-09-08 16:44:29 +02:00
|
|
|
};
|
2008-03-15 19:53:40 +01:00
|
|
|
|
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
jQuery.fn.extend({
|
|
|
|
position: function() {
|
2009-12-22 01:58:13 +01:00
|
|
|
if ( !this[0] ) {
|
|
|
|
return null;
|
|
|
|
}
|
2009-03-17 21:50:17 +01:00
|
|
|
|
2009-04-21 21:19:28 +02:00
|
|
|
var elem = this[0],
|
2009-03-17 21:50:17 +01:00
|
|
|
|
|
|
|
// Get *real* offsetParent
|
|
|
|
offsetParent = this.offsetParent(),
|
|
|
|
|
|
|
|
// Get correct offsets
|
|
|
|
offset = this.offset(),
|
2010-09-22 15:16:28 +02:00
|
|
|
parentOffset = rroot.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset();
|
2009-03-17 21:50:17 +01:00
|
|
|
|
|
|
|
// Subtract element margins
|
2009-03-23 02:55:17 +01:00
|
|
|
// note: when an element has margin: auto the offsetLeft and marginLeft
|
2009-03-17 21:50:17 +01:00
|
|
|
// are the same in Safari causing offset.left to incorrectly be 0
|
2010-09-16 16:00:56 +02:00
|
|
|
offset.top -= parseFloat( jQuery.css(elem, "marginTop") ) || 0;
|
|
|
|
offset.left -= parseFloat( jQuery.css(elem, "marginLeft") ) || 0;
|
2009-03-17 21:50:17 +01:00
|
|
|
|
|
|
|
// Add offsetParent borders
|
2010-09-16 16:00:56 +02:00
|
|
|
parentOffset.top += parseFloat( jQuery.css(offsetParent[0], "borderTopWidth") ) || 0;
|
|
|
|
parentOffset.left += parseFloat( jQuery.css(offsetParent[0], "borderLeftWidth") ) || 0;
|
2009-03-17 21:50:17 +01:00
|
|
|
|
|
|
|
// Subtract the two offsets
|
2009-04-21 21:19:28 +02:00
|
|
|
return {
|
2009-03-17 21:50:17 +01:00
|
|
|
top: offset.top - parentOffset.top,
|
|
|
|
left: offset.left - parentOffset.left
|
|
|
|
};
|
2008-04-29 05:26:06 +02:00
|
|
|
},
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
offsetParent: function() {
|
2009-12-22 01:58:13 +01:00
|
|
|
return this.map(function() {
|
2009-07-25 18:04:30 +02:00
|
|
|
var offsetParent = this.offsetParent || document.body;
|
2010-09-22 15:16:28 +02:00
|
|
|
while ( offsetParent && (!rroot.test(offsetParent.nodeName) && jQuery.css(offsetParent, "position") === "static") ) {
|
2009-07-25 18:04:30 +02:00
|
|
|
offsetParent = offsetParent.offsetParent;
|
|
|
|
}
|
|
|
|
return offsetParent;
|
|
|
|
});
|
2008-04-29 05:26:06 +02:00
|
|
|
}
|
2008-03-15 19:53:40 +01:00
|
|
|
});
|
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
|
|
|
|
// Create scrollLeft and scrollTop methods
|
2009-12-22 01:58:13 +01:00
|
|
|
jQuery.each( ["Left", "Top"], function( i, name ) {
|
|
|
|
var method = "scroll" + name;
|
2009-03-23 02:55:17 +01:00
|
|
|
|
2011-01-18 18:40:07 +01:00
|
|
|
jQuery.fn[ method ] = function( val ) {
|
2011-01-10 01:11:05 +01:00
|
|
|
var elem, win;
|
2010-12-30 07:34:48 +01:00
|
|
|
|
2011-04-12 22:13:56 +02:00
|
|
|
if ( val === undefined ) {
|
2011-01-18 18:40:07 +01:00
|
|
|
elem = this[ 0 ];
|
2009-07-17 23:08:13 +02:00
|
|
|
|
2011-04-12 22:13:56 +02:00
|
|
|
if ( !elem ) {
|
2011-01-10 02:51:20 +01:00
|
|
|
return null;
|
|
|
|
}
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2009-07-25 00:32:53 +02:00
|
|
|
win = getWindow( elem );
|
2008-05-13 03:45:58 +02:00
|
|
|
|
2008-04-29 05:26:06 +02:00
|
|
|
// Return the scroll offset
|
2009-12-22 02:13:16 +01:00
|
|
|
return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] :
|
2009-07-25 00:32:53 +02:00
|
|
|
jQuery.support.boxModel && win.document.documentElement[ method ] ||
|
2009-04-22 02:55:44 +02:00
|
|
|
win.document.body[ method ] :
|
|
|
|
elem[ method ];
|
2009-07-17 23:08:13 +02:00
|
|
|
}
|
2011-01-18 18:40:07 +01:00
|
|
|
|
2011-01-10 02:51:20 +01:00
|
|
|
// Set the scroll offset
|
|
|
|
return this.each(function() {
|
|
|
|
win = getWindow( this );
|
|
|
|
|
|
|
|
if ( win ) {
|
|
|
|
win.scrollTo(
|
2011-01-18 18:40:07 +01:00
|
|
|
!i ? val : jQuery( win ).scrollLeft(),
|
|
|
|
i ? val : jQuery( win ).scrollTop()
|
2011-01-10 02:51:20 +01:00
|
|
|
);
|
2011-04-12 22:13:56 +02:00
|
|
|
|
2011-01-10 02:51:20 +01:00
|
|
|
} else {
|
|
|
|
this[ method ] = val;
|
|
|
|
}
|
|
|
|
});
|
2008-04-29 05:26:06 +02:00
|
|
|
};
|
2008-04-30 21:35:17 +02:00
|
|
|
});
|
2009-07-25 00:32:53 +02:00
|
|
|
|
|
|
|
function getWindow( elem ) {
|
2010-09-22 22:41:51 +02:00
|
|
|
return jQuery.isWindow( elem ) ?
|
2009-07-25 18:04:30 +02:00
|
|
|
elem :
|
|
|
|
elem.nodeType === 9 ?
|
|
|
|
elem.defaultView || elem.parentWindow :
|
2009-07-25 00:32:53 +02:00
|
|
|
false;
|
|
|
|
}
|
2010-09-08 18:00:29 +02:00
|
|
|
|
|
|
|
})( jQuery );
|