Revert "Offset: remove ownerDocument check in offset getter"

This reverts commit 6176567361.
This commit is contained in:
Oleg Gaidarenko 2015-11-13 14:54:25 +03:00
parent 0169459d5d
commit e4218ca10b
2 changed files with 14 additions and 7 deletions

View File

@ -74,8 +74,6 @@ jQuery.offset = {
jQuery.fn.extend( {
offset: function( options ) {
// Preserve chaining for setter
if ( arguments.length ) {
return options === undefined ?
this :
@ -84,8 +82,9 @@ jQuery.fn.extend( {
} );
}
var docElem, win, rect, doc,
elem = this[ 0 ];
var docElem, win, rect,
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
if ( !elem ) {
return;
@ -100,9 +99,8 @@ jQuery.fn.extend( {
rect = elem.getBoundingClientRect();
// Make sure element is not hidden (display: none)
if ( rect.width || rect.height ) {
doc = elem.ownerDocument;
// Make sure element is not hidden (display: none) or disconnected
if ( rect.width || rect.height || elem.getClientRects().length ) {
win = getWindow( doc );
docElem = doc.documentElement;

View File

@ -48,6 +48,15 @@ QUnit.test( "empty set", function( assert ) {
assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
} );
QUnit.test( "object without getBoundingClientRect", function( assert ) {
assert.expect( 2 );
// Simulates a browser without gBCR on elements, we just want to return 0,0
var result = jQuery({ ownerDocument: document }).offset();
assert.equal( result.top, 0, "Check top" );
assert.equal( result.left, 0, "Check left" );
});
QUnit.test( "disconnected element", function( assert ) {
assert.expect( 2 );