Offset: remove ownerDocument check in offset getter

Fixes gh-2115
This commit is contained in:
Timmy Willison 2015-05-05 08:31:39 -07:00
parent 1617479fcf
commit 6176567361
2 changed files with 6 additions and 14 deletions

View File

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

View File

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