Skip to content
Permalink
Browse files

Bug 7931; Fixed bug that caused scrollTop and scrollLeft setters to r…

…eturn null when called on an empty jquery object
  • Loading branch information...
xavi- committed Jan 10, 2011
1 parent fcf6237 commit d03d2e9f26f85366ad2e91b9e2c76a249d7bf7be
Showing with 21 additions and 15 deletions.
  1. +14 −14 src/offset.js
  2. +7 −1 test/unit/offset.js
@@ -261,13 +261,9 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
var method = "scroll" + name;

jQuery.fn[ method ] = function(val) {
var elem = this[0], win;
var elem, win;

if ( !elem ) {
return null;
}

if ( val !== undefined ) {
if ( val != undefined ) {
// Set the scroll offset
return this.each(function() {
win = getWindow( this );
@@ -282,15 +278,19 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
this[ method ] = val;
}
});
} else {
win = getWindow( elem );

// Return the scroll offset
return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] :
jQuery.support.boxModel && win.document.documentElement[ method ] ||
win.document.body[ method ] :
elem[ method ];
}

elem = this[0];
if( !elem ) {
return null
}

win = getWindow( elem );
// Return the scroll offset
return win ? ("pageXOffset" in win) ? win[ i ? "pageYOffset" : "pageXOffset" ] :
jQuery.support.boxModel && win.document.documentElement[ method ] ||
win.document.body[ method ] :
elem[ method ];
};
});

@@ -333,7 +333,7 @@ testoffset("table", function( jQuery ) {
});

testoffset("scroll", function( jQuery, win ) {
expect(16);
expect(20);

var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;

@@ -379,6 +379,12 @@ testoffset("scroll", function( jQuery, win ) {
equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );

// Tests scrollTop/Left with empty jquery objects
ok( jQuery().scrollTop(100) != null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
ok( jQuery().scrollLeft(100) != null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
ok( jQuery().scrollTop() === null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
ok( jQuery().scrollLeft() === null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
});

testoffset("body", function( jQuery ) {

0 comments on commit d03d2e9

Please sign in to comment.
You can’t perform that action at this time.