X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Foffset.js;h=61dd93ac80a122f78d75644d3a9c8bd339451352;hb=bca82254137a161094377b2d8189c2d9d5906a0f;hp=b6c50ff71d334fdaa9c68a8a60a15d737f7ec4e4;hpb=d828ff75a45bc1f232e607806c930e98d7256fc6;p=jquery.git diff --git a/test/unit/offset.js b/test/unit/offset.js index b6c50ff..61dd93a 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -128,7 +128,7 @@ testoffset("table", function( jQuery ) { // equals( jQuery('#td-3').offset().left, 222, "jQuery('#td-3').offset().left" ); }); -testoffset("scroll", function( jQuery ) { +testoffset("scroll", function( jQuery, win ) { var ie = jQuery.browser.msie && parseInt( jQuery.browser.version ) < 8; // IE is collapsing the top margin of 1px @@ -138,6 +138,25 @@ testoffset("scroll", function( jQuery ) { // IE is collapsing the top margin of 1px equals( jQuery('#scroll-1-1').offset().top, ie ? 9 : 11, "jQuery('#scroll-1-1').offset().top" ); equals( jQuery('#scroll-1-1').offset().left, 11, "jQuery('#scroll-1-1').offset().left" ); + + + // scroll offset tests .scrollTop/Left + equals( jQuery('#scroll-1').scrollTop(), 5, "jQuery('#scroll-1').scrollTop()" ); + equals( jQuery('#scroll-1').scrollLeft(), 5, "jQuery('#scroll-1').scrollLeft()" ); + + equals( jQuery('#scroll-1-1').scrollTop(), 0, "jQuery('#scroll-1-1').scrollTop()" ); + equals( jQuery('#scroll-1-1').scrollLeft(), 0, "jQuery('#scroll-1-1').scrollLeft()" ); + + // equals( jQuery('body').scrollTop(), 0, "jQuery('body').scrollTop()" ); + // equals( jQuery('body').scrollLeft(), 0, "jQuery('body').scrollTop()" ); + + win.name = "test"; + + equals( jQuery(win).scrollTop(), 1000, "jQuery(window).scrollTop()" ); + equals( jQuery(win).scrollLeft(), 1000, "jQuery(window).scrollLeft()" ); + + equals( jQuery(win.document).scrollTop(), 1000, "jQuery(document).scrollTop()" ); + equals( jQuery(win.document).scrollLeft(), 1000, "jQuery(document).scrollLeft()" ); }); testoffset("body", function( jQuery ) { @@ -145,7 +164,32 @@ testoffset("body", function( jQuery ) { equals( jQuery('body').offset().left, 1, "jQuery('#body').offset().left" ); }); +test("offsetParent", function(){ + expect(11); + var body = jQuery("body").offsetParent(); + equals( body.length, 1, "Only one offsetParent found." ); + equals( body[0], document.body, "The body is its own offsetParent." ); + + var header = jQuery("#header").offsetParent(); + equals( header.length, 1, "Only one offsetParent found." ); + equals( header[0], document.body, "The body is the offsetParent." ); + + var div = jQuery("#nothiddendivchild").offsetParent(); + equals( div.length, 1, "Only one offsetParent found." ); + equals( div[0], document.body, "The body is the offsetParent." ); + + jQuery("#nothiddendiv").css("position", "relative"); + + div = jQuery("#nothiddendivchild").offsetParent(); + equals( div.length, 1, "Only one offsetParent found." ); + equals( div[0], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); + + div = jQuery("body, #nothiddendivchild").offsetParent(); + equals( div.length, 2, "Two offsetParent found." ); + equals( div[0], document.body, "The body is the offsetParent." ); + equals( div[1], jQuery("#nothiddendiv")[0], "The div is the offsetParent." ); +}); function testoffset(name, fn) { @@ -162,7 +206,7 @@ function testoffset(name, fn) { // continue start(); // call actual tests passing the correct jQuery isntance to use - fn.call( this, win.jQuery ); + fn.call( this, win.jQuery, win ); document.body.removeChild( iframe ); iframe = null; } @@ -177,4 +221,4 @@ function testoffset(name, fn) { iframe.contentWindow.location = src; return iframe; } -} \ No newline at end of file +}