Permalink
Browse files

Offset: remove ownerDocument check in offset getter

Fixes gh-2115
  • Loading branch information...
timmywil committed May 5, 2015
1 parent 1617479 commit 6176567361e9d05d4f5eb7e98735a678f2cd7ea9
Showing with 6 additions and 14 deletions.
  1. +5 −4 src/offset.js
  2. +1 −10 test/unit/offset.js
View
@@ -74,6 +74,7 @@ jQuery.offset = {
jQuery.fn.extend({
offset: function( options ) {
// Preserve chaining for setter
if ( arguments.length ) {
return options === undefined ?
this :
@@ -82,18 +83,18 @@ jQuery.fn.extend({
});
}
var docElem, win, rect,
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
var docElem, win, rect, doc,
elem = this[ 0 ];
if ( !doc ) {
if ( !elem ) {
return;
}
rect = elem.getBoundingClientRect();
// Make sure element is not hidden (display: none) or disconnected
if ( rect.width || rect.height || elem.getClientRects().length ) {
doc = elem.ownerDocument;
win = getWindow( doc );
docElem = doc.documentElement;
View
@@ -42,20 +42,11 @@ module("offset", { setup: function(){
*/
test("empty set", function() {
expect(2);
expect( 2 );
strictEqual( jQuery().offset(), undefined, "offset() 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() {
expect(1);

0 comments on commit 6176567

Please sign in to comment.