Skip to content

Commit b0a352b

Browse files
committed
Fix #12534. Don't die on browsers lacking getBoundingClientRect.
1 parent 74cdd78 commit b0a352b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/offset.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jQuery.fn.offset = function( options ) {
2323

2424
docElem = doc.documentElement;
2525

26-
// Make sure we're not dealing with a disconnected DOM node
27-
if ( !jQuery.contains( docElem, elem ) ) {
26+
// Make sure we have the API and we're it's not a disconnected DOM node
27+
if ( typeof elem.getBoundingClientRect === "undefined" || !jQuery.contains( docElem, elem ) ) {
2828
return { top: 0, left: 0 };
2929
}
3030

test/unit/offset.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ test("empty set", function() {
1515
strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
1616
});
1717

18+
test("object without getBoundingClientRect", function() {
19+
expect(2);
20+
21+
// Simulates a browser without gBCR on elements, we just want to return 0,0
22+
var result = jQuery({ ownerDocument: document }).offset();
23+
equal( result.top, 0, "Check top" );
24+
equal( result.left, 0, "Check left" );
25+
});
26+
1827
test("disconnected node", function() {
1928
expect(2);
2029

0 commit comments

Comments
 (0)