From: Oleg Gaidarenko Date: Tue, 22 Dec 2015 13:06:04 +0000 (+0300) Subject: Revert "Offset: allow offset setter to throw for disconnected elements" X-Git-Tag: 1.12.0~58 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c7641e1ffa56c677de167cbdefa7cbea3155c273;p=jquery.git Revert "Offset: allow offset setter to throw for disconnected elements" This reverts commit dc49f62f22a90ba95bbd1b659bfdae905adb4dd8. --- diff --git a/src/offset.js b/src/offset.js index fe9b44192..f3c6b222c 100644 --- a/src/offset.js +++ b/src/offset.js @@ -41,7 +41,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 c0edd3dcd..d1e618c8b 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -40,6 +40,10 @@ QUnit.test( "jQuery()", function( assert ) { expected++; attrObj[ "offset" ] = { "top": 1, "left": 1 }; } + if ( jQuery.fn.offset ) { + expected++; + attrObj["offset"] = { "top": 1, "left": 1 }; + } if ( jQuery.fn.css ) { expected += 2; attrObj[ "css" ] = { "paddingLeft": 1, "paddingRight": 1 }; @@ -105,7 +109,7 @@ QUnit.test( "jQuery()", function( assert ) { elem = jQuery( "\n\nworld" )[ 0 ]; assert.equal( elem.nodeName.toLowerCase(), "em", "leading newlines" ); - elem = jQuery( "
", attrObj ); + elem = jQuery("
", attrObj ); if ( jQuery.fn.width ) { assert.equal( elem[ 0 ].style.width, "10px", "jQuery() quick setter width" ); @@ -115,6 +119,10 @@ QUnit.test( "jQuery()", function( assert ) { assert.equal( elem[ 0 ].style.top, "1px", "jQuery() quick setter offset" ); } + if ( jQuery.fn.offset ) { + equal( elem[0].style.top, "1px", "jQuery() quick setter offset"); + } + if ( jQuery.fn.css ) { assert.equal( elem[ 0 ].style.paddingLeft, "1px", "jQuery quick setter css" ); assert.equal( elem[ 0 ].style.paddingRight, "1px", "jQuery quick setter css" );