Merge branch 'bug_7931' of https://github.com/Xavi-/jquery into Xavi--bug_7931

Conflicts:
	src/offset.js
This commit is contained in:
John Resig 2011-04-12 16:13:56 -04:00
commit f1d75edec7
2 changed files with 31 additions and 21 deletions

View file

@ -262,13 +262,24 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
var method = "scroll" + name; var method = "scroll" + name;
jQuery.fn[ method ] = function( val ) { jQuery.fn[ method ] = function( val ) {
var elem = this[0], win; var elem, win;
if ( val === undefined ) {
elem = this[ 0 ];
if ( !elem ) { if ( !elem ) {
return null; return null;
} }
if ( val !== undefined ) { 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 ];
}
// Set the scroll offset // Set the scroll offset
return this.each(function() { return this.each(function() {
win = getWindow( this ); win = getWindow( this );
@ -283,15 +294,6 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
this[ method ] = val; 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 ];
}
}; };
}); });

View file

@ -344,7 +344,7 @@ testoffset("table", function( jQuery ) {
}); });
testoffset("scroll", function( jQuery, win ) { testoffset("scroll", function( jQuery, win ) {
expect(16); expect(22);
var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8; var ie = jQuery.browser.msie && parseInt( jQuery.browser.version, 10 ) < 8;
@ -390,6 +390,14 @@ testoffset("scroll", function( jQuery, win ) {
equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" ); equals( jQuery(window).scrollLeft(), 0, "jQuery(window).scrollLeft() other window" );
equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" ); equals( jQuery(document).scrollTop(), 0, "jQuery(window).scrollTop() other document" );
equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" ); equals( jQuery(document).scrollLeft(), 0, "jQuery(window).scrollLeft() other document" );
// Tests scrollTop/Left with empty jquery objects
notEqual( jQuery().scrollTop(100), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
notEqual( jQuery().scrollLeft(100), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
notEqual( jQuery().scrollTop(null), null, "jQuery().scrollTop(null) testing setter on empty jquery object" );
notEqual( jQuery().scrollLeft(null), null, "jQuery().scrollLeft(null) testing setter on empty jquery object" );
strictEqual( jQuery().scrollTop(), null, "jQuery().scrollTop(100) testing setter on empty jquery object" );
strictEqual( jQuery().scrollLeft(), null, "jQuery().scrollLeft(100) testing setter on empty jquery object" );
}); });
testoffset("body", function( jQuery ) { testoffset("body", function( jQuery ) {