diff options
author | timmywil <timmywillisn@gmail.com> | 2011-10-31 12:34:32 -0400 |
---|---|---|
committer | timmywil <timmywillisn@gmail.com> | 2011-10-31 12:34:32 -0400 |
commit | f8a1f7b670df212b2f63064e914952732ac9cf9c (patch) | |
tree | 7f9598ea3ff2ef5dd5fb7722f47fa73a17571b8a | |
parent | 0191e98934b40be5699a85087b5342a149c978ce (diff) | |
parent | 83a355a9a06c03eeb4e601dbe204909d273c91b5 (diff) | |
download | jquery-f8a1f7b670df212b2f63064e914952732ac9cf9c.tar.gz jquery-f8a1f7b670df212b2f63064e914952732ac9cf9c.zip |
Merge branch 'bug_10613_2'
-rw-r--r-- | src/offset.js | 24 | ||||
-rw-r--r-- | src/support.js | 52 | ||||
-rw-r--r-- | test/index.html | 1 |
3 files changed, 36 insertions, 41 deletions
diff --git a/src/offset.js b/src/offset.js index 054869da6..ad10236f6 100644 --- a/src/offset.js +++ b/src/offset.js @@ -75,7 +75,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { left = elem.offsetLeft; while ( (elem = elem.parentNode) && elem !== body && elem !== docElem ) { - if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { + if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) { break; } @@ -87,7 +87,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { top += elem.offsetTop; left += elem.offsetLeft; - if ( jQuery.offset.doesNotAddBorder && !(jQuery.offset.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) { + if ( jQuery.support.doesNotAddBorder && !(jQuery.support.doesAddBorderForTableAndCells && rtable.test(elem.nodeName)) ) { top += parseFloat( computedStyle.borderTopWidth ) || 0; left += parseFloat( computedStyle.borderLeftWidth ) || 0; } @@ -96,7 +96,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { offsetParent = elem.offsetParent; } - if ( jQuery.offset.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) { + if ( jQuery.support.subtractsBorderForOverflowNotVisible && computedStyle.overflow !== "visible" ) { top += parseFloat( computedStyle.borderTopWidth ) || 0; left += parseFloat( computedStyle.borderLeftWidth ) || 0; } @@ -109,7 +109,7 @@ if ( "getBoundingClientRect" in document.documentElement ) { left += body.offsetLeft; } - if ( jQuery.offset.supportsFixedPosition && prevComputedStyle.position === "fixed" ) { + if ( jQuery.support.fixedPosition && prevComputedStyle.position === "fixed" ) { top += Math.max( docElem.scrollTop, body.scrollTop ); left += Math.max( docElem.scrollLeft, body.scrollLeft ); } @@ -118,23 +118,13 @@ if ( "getBoundingClientRect" in document.documentElement ) { }; } -jQuery.offset = {}; - -jQuery.each( - ( "doesAddBorderForTableAndCells doesNotAddBorder " + - "doesNotIncludeMarginInBodyOffset subtractsBorderForOverflowNotVisible " + - "supportsFixedPosition" ).split(" "), function( i, prop ) { - - jQuery.offset[ prop ] = jQuery.support[ prop ]; -}); - -jQuery.extend( jQuery.offset, { +jQuery.offset = { bodyOffset: function( body ) { var top = body.offsetTop, left = body.offsetLeft; - if ( jQuery.offset.doesNotIncludeMarginInBodyOffset ) { + if ( jQuery.support.doesNotIncludeMarginInBodyOffset ) { top += parseFloat( jQuery.css(body, "marginTop") ) || 0; left += parseFloat( jQuery.css(body, "marginLeft") ) || 0; } @@ -184,7 +174,7 @@ jQuery.extend( jQuery.offset, { curElem.css( props ); } } -}); +}; jQuery.fn.extend({ diff --git a/src/support.js b/src/support.js index 20cf2b526..1920e5b87 100644 --- a/src/support.js +++ b/src/support.js @@ -20,8 +20,7 @@ jQuery.support = (function() { events, eventName, i, - isSupported, - offsetSupport; + isSupported; // Preliminary tests div.setAttribute("className", "t"); @@ -231,9 +230,6 @@ jQuery.support = (function() { ( parseInt( ( document.defaultView.getComputedStyle( marginDiv, null ) || { marginRight: 0 } ).marginRight, 10 ) || 0 ) === 0; } - // Remove the body element we added - testElement.innerHTML = ""; - // Technique from Juriy Zaytsev // http://perfectionkills.com/detecting-event-support-without-browser-sniffing/ // We only care about the case where non-standard event systems @@ -256,29 +252,35 @@ jQuery.support = (function() { } } - // Determine fixed-position support early - testElement.style.position = "static"; - testElement.style.top = "0px"; - testElement.style.marginTop = "1px"; - offsetSupport = (function( body, container ) { - - var outer, inner, table, td, supports, - bodyMarginTop = parseFloat( body.style.marginTop ) || 0, + // Run fixed position tests at doc ready to avoid a crash + // related to the invisible body in IE8 + jQuery(function() { + var container, outer, inner, table, td, offsetSupport, + conMarginTop = 1, ptlm = "position:absolute;top:0;left:0;width:1px;height:1px;margin:0;", + vb = "visibility:hidden;border:0;", style = "style='" + ptlm + "border:5px solid #000;padding:0;'", html = "<div " + style + "><div></div></div>" + "<table " + style + " cellpadding='0' cellspacing='0'>" + "<tr><td></td></tr></table>"; - container.style.cssText = ptlm + "border:0;visibility:hidden"; - - container.innerHTML = html; + // Reconstruct a container + body = document.getElementsByTagName("body")[0]; + container = document.createElement("div"); + container.style.cssText = vb + "width:0;height:0;position:static;top:0;marginTop:" + conMarginTop + "px"; body.insertBefore( container, body.firstChild ); - outer = container.firstChild; + + // Construct a test element + testElement = document.createElement("div"); + testElement.style.cssText = ptlm + vb; + + testElement.innerHTML = html; + container.appendChild( testElement ); + outer = testElement.firstChild; inner = outer.firstChild; td = outer.nextSibling.firstChild.firstChild; - supports = { + offsetSupport = { doesNotAddBorder: ( inner.offsetTop !== 5 ), doesAddBorderForTableAndCells: ( td.offsetTop === 5 ) }; @@ -287,20 +289,22 @@ jQuery.support = (function() { inner.style.top = "20px"; // safari subtracts parent border width here which is 5px - supports.supportsFixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 ); + offsetSupport.fixedPosition = ( inner.offsetTop === 20 || inner.offsetTop === 15 ); inner.style.position = inner.style.top = ""; outer.style.overflow = "hidden"; outer.style.position = "relative"; - supports.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 ); - supports.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== bodyMarginTop ); + offsetSupport.subtractsBorderForOverflowNotVisible = ( inner.offsetTop === -5 ); + offsetSupport.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== conMarginTop ); - return supports; + body.removeChild( container ); + testElement = container = null; - })( testElement, div ); + jQuery.extend( support, offsetSupport ); + }); - jQuery.extend( support, offsetSupport ); + testElement.innerHTML = ""; testElementParent.removeChild( testElement ); // Null connected elements to avoid leaks in IE diff --git a/test/index.html b/test/index.html index 40e6803c7..e6cbc013f 100644 --- a/test/index.html +++ b/test/index.html @@ -298,5 +298,6 @@ Z</textarea> <div id="fx-tests"></div> </div> + </body> </html> |