Commit 2c28f229 authored by Karl Swedberg's avatar Karl Swedberg Committed by John Resig

fixed offset(coordinates) returns null when no matching elements in jQuery...

fixed offset(coordinates) returns null when no matching elements in jQuery object (fixes ticket #5888)
parent a63754aa
...@@ -2,16 +2,16 @@ if ( "getBoundingClientRect" in document.documentElement ) { ...@@ -2,16 +2,16 @@ if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0]; var elem = this[0];
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( options ) { if ( options ) {
return this.each(function( i ) { return this.each(function( i ) {
jQuery.offset.setOffset( this, options, i ); jQuery.offset.setOffset( this, options, i );
}); });
} }
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( elem === elem.ownerDocument.body ) { if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem ); return jQuery.offset.bodyOffset( elem );
} }
...@@ -28,16 +28,16 @@ if ( "getBoundingClientRect" in document.documentElement ) { ...@@ -28,16 +28,16 @@ if ( "getBoundingClientRect" in document.documentElement ) {
jQuery.fn.offset = function( options ) { jQuery.fn.offset = function( options ) {
var elem = this[0]; var elem = this[0];
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( options ) { if ( options ) {
return this.each(function( i ) { return this.each(function( i ) {
jQuery.offset.setOffset( this, options, i ); jQuery.offset.setOffset( this, options, i );
}); });
} }
if ( !elem || !elem.ownerDocument ) {
return null;
}
if ( elem === elem.ownerDocument.body ) { if ( elem === elem.ownerDocument.body ) {
return jQuery.offset.bodyOffset( elem ); return jQuery.offset.bodyOffset( elem );
} }
......
...@@ -29,9 +29,8 @@ test("show()", function() { ...@@ -29,9 +29,8 @@ test("show()", function() {
div.hide().show(speed, function() { div.hide().show(speed, function() {
pass = false; pass = false;
}); });
ok( pass, "Show with " + name + " does not call animate callback"); ok( pass, "Show with " + name + " does not call animate callback" );
}); });
jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>'); jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
......
...@@ -305,6 +305,13 @@ testoffset("body", function( jQuery ) { ...@@ -305,6 +305,13 @@ testoffset("body", function( jQuery ) {
equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" ); equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" );
}); });
test("Chaining offset(coords) returns jQuery object", function() {
expect(2);
var coords = { top: 1, left: 1 };
equals( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" );
equals( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" );
});
test("offsetParent", function(){ test("offsetParent", function(){
expect(11); expect(11);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment