diff options
author | Rick Waldron <waldron.rick@gmail.com> | 2011-09-19 21:03:41 -0400 |
---|---|---|
committer | timmywil <timmywillisn@gmail.com> | 2011-09-19 21:03:41 -0400 |
commit | f60213648cefa9b53289ad01a55ead22a15e6ee1 (patch) | |
tree | 74f93acaba183bd24a9a8beab1efd7e39e862258 /src/offset.js | |
parent | 9ecdb2472be7661477564e46bce51432d4a5a84e (diff) | |
download | jquery-f60213648cefa9b53289ad01a55ead22a15e6ee1.tar.gz jquery-f60213648cefa9b53289ad01a55ead22a15e6ee1.zip |
Landing pull request 477. 1.7 jQuery.offset.supportsFixedPosition. Fixes #6809.
More Details:
- https://github.com/jquery/jquery/pull/477
- http://bugs.jquery.com/ticket/6809
Diffstat (limited to 'src/offset.js')
-rw-r--r-- | src/offset.js | 45 |
1 files changed, 10 insertions, 35 deletions
diff --git a/src/offset.js b/src/offset.js index 31f2503a4..4cc87acff 100644 --- a/src/offset.js +++ b/src/offset.js @@ -63,8 +63,6 @@ if ( "getBoundingClientRect" in document.documentElement ) { return jQuery.offset.bodyOffset( elem ); } - jQuery.offset.initialize(); - var computedStyle, offsetParent = elem.offsetParent, prevOffsetParent = elem, @@ -120,46 +118,22 @@ if ( "getBoundingClientRect" in document.documentElement ) { }; } -jQuery.offset = { - initialize: function() { - var body = document.body, container = document.createElement("div"), innerDiv, checkDiv, table, td, bodyMarginTop = parseFloat( jQuery.css(body, "marginTop") ) || 0, - 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>"; - - jQuery.extend( container.style, { position: "absolute", top: 0, left: 0, margin: 0, border: 0, width: "1px", height: "1px", visibility: "hidden" } ); - - container.innerHTML = html; - body.insertBefore( container, body.firstChild ); - innerDiv = container.firstChild; - checkDiv = innerDiv.firstChild; - td = innerDiv.nextSibling.firstChild.firstChild; - - this.doesNotAddBorder = (checkDiv.offsetTop !== 5); - this.doesAddBorderForTableAndCells = (td.offsetTop === 5); - - 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 = ""; +jQuery.offset = {}; - innerDiv.style.overflow = "hidden"; - innerDiv.style.position = "relative"; +jQuery.each( + ( "doesAddBorderForTableAndCells doesNotAddBorder " + + "doesNotIncludeMarginInBodyOffset subtractsBorderForOverflowNotVisible " + + "supportsFixedPosition" ).split(" "), function( i, prop ) { - this.subtractsBorderForOverflowNotVisible = (checkDiv.offsetTop === -5); - - this.doesNotIncludeMarginInBodyOffset = (body.offsetTop !== bodyMarginTop); + jQuery.offset[ prop ] = jQuery.support[ prop ]; +}); - body.removeChild( container ); - jQuery.offset.initialize = jQuery.noop; - }, +jQuery.extend( jQuery.offset, { bodyOffset: function( body ) { var top = body.offsetTop, left = body.offsetLeft; - jQuery.offset.initialize(); - if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) { top += parseFloat( jQuery.css(body, "marginTop") ) || 0; left += parseFloat( jQuery.css(body, "marginLeft") ) || 0; @@ -210,10 +184,11 @@ jQuery.offset = { curElem.css( props ); } } -}; +}); jQuery.fn.extend({ + position: function() { if ( !this[0] ) { return null; |