-testwin("relative", function() {
- var $w = testwin["relative"].$;
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-1').offset().top, jQuery.browser.msie ? 6 : 7, "jQuery('#relative-1').offset().top" );
- equals( $w('#relative-1').offset().left, 7, "jQuery('#relative-1').offset().left" );
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-1-1').offset().top, jQuery.browser.msie ? 13 : 15, "jQuery('#relative-1-1').offset().top" );
- equals( $w('#relative-1-1').offset().left, 15, "jQuery('#relative-1-1').offset().left" );
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-2').offset().top, jQuery.browser.msie ? 141 : 142, "jQuery('#relative-2').offset().top" );
- equals( $w('#relative-2').offset().left, 27, "jQuery('#relative-2').offset().left" );
-
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-1').position().top, jQuery.browser.msie ? 5 : 6, "jQuery('#relative-1').position().top" );
- equals( $w('#relative-1').position().left, 6, "jQuery('#relative-1').position().left" );
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-1-1').position().top, jQuery.browser.msie ? 4 : 5, "jQuery('#relative-1-1').position().top" );
- equals( $w('#relative-1-1').position().left, 5, "jQuery('#relative-1-1').position().left" );
-
- // IE is collapsing the top margin of 1px
- equals( $w('#relative-2').position().top, jQuery.browser.msie ? 140 : 141, "jQuery('#relative-2').position().top" );
- equals( $w('#relative-2').position().left, 26, "jQuery('#relative-2').position().left" );
-
- testwin["relative"].close();
+testoffset("absolute", function( jQuery ) {
+ expect(178);
+
+ // get offset tests
+ var tests = [
+ { id: '#absolute-1', top: 1, left: 1 },
+ { id: '#absolute-1-1', top: 5, left: 5 },
+ { id: '#absolute-1-1-1', top: 9, left: 9 },
+ { id: '#absolute-2', top: 20, left: 20 }
+ ];
+ jQuery.each( tests, function() {
+ equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" );
+ equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" );
+ });
+
+
+ // get position
+ tests = [
+ { id: '#absolute-1', top: 0, left: 0 },
+ { id: '#absolute-1-1', top: 1, left: 1 },
+ { id: '#absolute-1-1-1', top: 1, left: 1 },
+ { id: '#absolute-2', top: 19, left: 19 }
+ ];
+ jQuery.each( tests, function() {
+ equals( jQuery( this.id ).position().top, this.top, "jQuery('" + this.id + "').position().top" );
+ equals( jQuery( this.id ).position().left, this.left, "jQuery('" + this.id + "').position().left" );
+ });
+
+ // test #5781
+ var offset = jQuery( '#positionTest' ).offset({ top: 10, left: 10 }).offset();
+ equals( offset.top, 10, "Setting offset on element with position absolute but 'auto' values." )
+ equals( offset.left, 10, "Setting offset on element with position absolute but 'auto' values." )
+
+
+ // set offset
+ tests = [
+ { id: '#absolute-2', top: 30, left: 30 },
+ { id: '#absolute-2', top: 10, left: 10 },
+ { id: '#absolute-2', top: -1, left: -1 },
+ { id: '#absolute-2', top: 19, left: 19 },
+ { id: '#absolute-1-1-1', top: 15, left: 15 },
+ { id: '#absolute-1-1-1', top: 5, left: 5 },
+ { id: '#absolute-1-1-1', top: -1, left: -1 },
+ { id: '#absolute-1-1-1', top: 9, left: 9 },
+ { id: '#absolute-1-1', top: 10, left: 10 },
+ { id: '#absolute-1-1', top: 0, left: 0 },
+ { id: '#absolute-1-1', top: -1, left: -1 },
+ { id: '#absolute-1-1', top: 5, left: 5 },
+ { id: '#absolute-1', top: 2, left: 2 },
+ { id: '#absolute-1', top: 0, left: 0 },
+ { id: '#absolute-1', top: -1, left: -1 },
+ { id: '#absolute-1', top: 1, left: 1 }
+ ];
+ jQuery.each( tests, function() {
+ jQuery( this.id ).offset({ top: this.top, left: this.left });
+ equals( jQuery( this.id ).offset().top, this.top, "jQuery('" + this.id + "').offset({ top: " + this.top + " })" );
+ equals( jQuery( this.id ).offset().left, this.left, "jQuery('" + this.id + "').offset({ left: " + this.left + " })" );
+
+ var top = this.top, left = this.left;
+
+ jQuery( this.id ).offset(function(i, val){
+ equals( val.top, top, "Verify incoming top position." );
+ equals( val.left, left, "Verify incoming top position." );
+ return { top: top + 1, left: left + 1 };
+ });
+ equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + " })" );
+ equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + " })" );
+
+ jQuery( this.id )
+ .offset({ left: this.left + 2 })
+ .offset({ top: this.top + 2 });
+ equals( jQuery( this.id ).offset().top, this.top + 2, "Setting one property at a time." );
+ equals( jQuery( this.id ).offset().left, this.left + 2, "Setting one property at a time." );
+
+ jQuery( this.id ).offset({ top: this.top, left: this.left, using: function( props ) {
+ jQuery( this ).css({
+ top: props.top + 1,
+ left: props.left + 1
+ });
+ }});
+ equals( jQuery( this.id ).offset().top, this.top + 1, "jQuery('" + this.id + "').offset({ top: " + (this.top + 1) + ", using: fn })" );
+ equals( jQuery( this.id ).offset().left, this.left + 1, "jQuery('" + this.id + "').offset({ left: " + (this.left + 1) + ", using: fn })" );
+ });