Skip to content
Permalink
Browse files

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

…-bug_7931

Conflicts:
	src/offset.js
  • Loading branch information...
jeresig committed Apr 12, 2011
2 parents 978c065 + 135a384 commit f1d75edec70783d67f0e11459f0a2187d98cc553
Showing with 31 additions and 21 deletions.
  1. +22 −20 src/offset.js
  2. +9 −1 test/unit/offset.js
@@ -261,29 +261,16 @@ jQuery.fn.extend({
jQuery.each( ["Left", "Top"], function( i, name ) {
var method = "scroll" + name;

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

if ( !elem ) {
return null;
}

if ( val !== undefined ) {
// Set the scroll offset
return this.each(function() {
win = getWindow( this );
if ( val === undefined ) {
elem = this[ 0 ];

if ( win ) {
win.scrollTo(
!i ? val : jQuery(win).scrollLeft(),
i ? val : jQuery(win).scrollTop()
);
if ( !elem ) {
return null;
}

} else {
this[ method ] = val;
}
});
} else {
win = getWindow( elem );

// Return the scroll offset
@@ -292,6 +279,21 @@ jQuery.each( ["Left", "Top"], function( i, name ) {
win.document.body[ method ] :
elem[ method ];
}

// Set the scroll offset
return this.each(function() {
win = getWindow( this );

if ( win ) {
win.scrollTo(
!i ? val : jQuery( win ).scrollLeft(),
i ? val : jQuery( win ).scrollTop()
);

} else {
this[ method ] = val;
}
});
};
});

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

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

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(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
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 ) {

0 comments on commit f1d75ed

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