mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Make sure that .offset() doesn't fail against disconnected DOM nodes. Fixes #4996.
This commit is contained in:
parent
7be11207b9
commit
cf672a2e7a
@ -5,7 +5,7 @@ var rtable = /^t(?:able|d|h)$/i,
|
|||||||
|
|
||||||
if ( "getBoundingClientRect" in document.documentElement ) {
|
if ( "getBoundingClientRect" in document.documentElement ) {
|
||||||
jQuery.fn.offset = function( options ) {
|
jQuery.fn.offset = function( options ) {
|
||||||
var elem = this[0];
|
var elem = this[0], box;
|
||||||
|
|
||||||
if ( options ) {
|
if ( options ) {
|
||||||
return this.each(function( i ) {
|
return this.each(function( i ) {
|
||||||
@ -21,8 +21,14 @@ if ( "getBoundingClientRect" in document.documentElement ) {
|
|||||||
return jQuery.offset.bodyOffset( elem );
|
return jQuery.offset.bodyOffset( elem );
|
||||||
}
|
}
|
||||||
|
|
||||||
var box = elem.getBoundingClientRect(),
|
try {
|
||||||
doc = elem.ownerDocument,
|
box = elem.getBoundingClientRect();
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
box = { top: elem.offsetTop, left: elem.offsetLeft };
|
||||||
|
}
|
||||||
|
|
||||||
|
var doc = elem.ownerDocument,
|
||||||
body = doc.body,
|
body = doc.body,
|
||||||
docElem = doc.documentElement,
|
docElem = doc.documentElement,
|
||||||
win = getWindow(doc),
|
win = getWindow(doc),
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
module("offset");
|
module("offset");
|
||||||
|
|
||||||
|
test("disconnected node", function() {
|
||||||
|
expect(2);
|
||||||
|
|
||||||
|
var result = jQuery( document.createElement("div") ).offset();
|
||||||
|
|
||||||
|
equals( result.top, 0, "Check top" );
|
||||||
|
equals( result.left, 0, "Check left" );
|
||||||
|
});
|
||||||
|
|
||||||
var supportsScroll = false;
|
var supportsScroll = false;
|
||||||
|
|
||||||
testoffset("absolute"/* in iframe */, function($, iframe) {
|
testoffset("absolute"/* in iframe */, function($, iframe) {
|
||||||
|
Loading…
Reference in New Issue
Block a user