From ee69e9c8b8a5b832f2feaf1751ecd804df2d240a Mon Sep 17 00:00:00 2001 From: Timmy Willison Date: Mon, 15 Jun 2015 10:56:29 -0400 Subject: [PATCH] Revert "Offset: allow offset setter to throw for disconnected elements" This reverts commit 0d11c1182f2012cd6eb06ce1e3fa5a495af9bee3. --- src/offset.js | 2 +- test/unit/core.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/offset.js b/src/offset.js index 1d7ce300e..69a414958 100644 --- a/src/offset.js +++ b/src/offset.js @@ -39,7 +39,7 @@ jQuery.offset = { elem.style.position = "relative"; } - curOffset = curElem.offset(); + curOffset = curElem.offset() || { top: 0, left: 0 }; curCSSTop = jQuery.css( elem, "top" ); curCSSLeft = jQuery.css( elem, "left" ); calculatePosition = ( position === "absolute" || position === "fixed" ) && diff --git a/test/unit/core.js b/test/unit/core.js index 07019e86b..848ca2a5f 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -36,6 +36,10 @@ test("jQuery()", function() { expected++; attrObj["width"] = 10; } + if ( jQuery.fn.offset ) { + expected++; + attrObj["offset"] = { "top": 1, "left": 1 }; + } if ( jQuery.fn.css ) { expected += 2; attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 }; @@ -101,12 +105,16 @@ test("jQuery()", function() { elem = jQuery("\n\nworld")[0]; equal( elem.nodeName.toLowerCase(), "em", "leading newlines" ); - elem = jQuery( "
", attrObj ); + elem = jQuery("
", attrObj ); if ( jQuery.fn.width ) { equal( elem[0].style.width, "10px", "jQuery() quick setter width"); } + if ( jQuery.fn.offset ) { + equal( elem[0].style.top, "1px", "jQuery() quick setter offset"); + } + if ( jQuery.fn.css ) { equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css"); equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css"); -- 2.39.5