From 560c178c82da95b2f88ae518552463d87fe5adbf Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Fri, 14 Sep 2012 10:14:40 -0400 Subject: [PATCH] Fix #12536. Start at .offset() 0,0 if no getBoundingClientRect. This lets us still add the other offset components to the number so they're less wrong. Affects BlackBerry 5 and iOS 3, everyone else has gBCR. --- src/offset.js | 23 ++++++++++++++--------- src/sizzle | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/offset.js b/src/offset.js index 14cd1a629..381a42da2 100644 --- a/src/offset.js +++ b/src/offset.js @@ -9,7 +9,8 @@ jQuery.fn.offset = function( options ) { }); } - var box, docElem, body, win, clientTop, clientLeft, scrollTop, scrollLeft, top, left, + var docElem, body, win, clientTop, clientLeft, scrollTop, scrollLeft, + box = { top: 0, left: 0 }, elem = this[ 0 ], doc = elem && elem.ownerDocument; @@ -23,21 +24,25 @@ jQuery.fn.offset = function( options ) { docElem = doc.documentElement; - // Make sure we have the API and we're it's not a disconnected DOM node - if ( typeof elem.getBoundingClientRect === "undefined" || !jQuery.contains( docElem, elem ) ) { - return { top: 0, left: 0 }; + // Make sure it's not a disconnected DOM node + if ( !jQuery.contains( docElem, elem ) ) { + return box; } - box = elem.getBoundingClientRect(); + // If we don't have gBCR, just use 0,0 rather than error + // BlackBerry 5, iOS 3 (original iPhone) + if ( typeof elem.getBoundingClientRect !== "undefined" ) { + box = elem.getBoundingClientRect(); + } win = getWindow( doc ); clientTop = docElem.clientTop || body.clientTop || 0; clientLeft = docElem.clientLeft || body.clientLeft || 0; scrollTop = win.pageYOffset || docElem.scrollTop; scrollLeft = win.pageXOffset || docElem.scrollLeft; - top = box.top + scrollTop - clientTop; - left = box.left + scrollLeft - clientLeft; - - return { top: top, left: left }; + return { + top: box.top + scrollTop - clientTop, + left: box.left + scrollLeft - clientLeft + }; }; jQuery.offset = { diff --git a/src/sizzle b/src/sizzle index 9fb909e71..0a488ce5f 160000 --- a/src/sizzle +++ b/src/sizzle @@ -1 +1 @@ -Subproject commit 9fb909e71fe0e152f80bf04198cc2b2098756c81 +Subproject commit 0a488ce5fa817bfa371658fc6cf0bd3214c5f3d5 -- 2.39.5