- equals( jQuery('#absolute-1').offset().top, 1, "jQuery('#absolute-1').offset().top" );
- equals( jQuery('#absolute-1').offset().left, 1, "jQuery('#absolute-1').offset().left" );
-
- equals( jQuery('#absolute-1-1').offset().top, 5, "jQuery('#absolute-1-1').offset().top" );
- equals( jQuery('#absolute-1-1').offset().left, 5, "jQuery('#absolute-1-1').offset().left" );
-
- equals( jQuery('#absolute-1-1-1').offset().top, 9, "jQuery('#absolute-1-1-1').offset().top" );
- equals( jQuery('#absolute-1-1-1').offset().left, 9, "jQuery('#absolute-1-1-1').offset().left" );
-
- equals( jQuery('#absolute-2').offset().top, 20, "jQuery('#absolute-2').offset().top" );
- equals( jQuery('#absolute-2').offset().left, 20, "jQuery('#absolute-2').offset().left" );
-
-
- equals( jQuery('#absolute-1').position().top, 0, "jQuery('#absolute-1').position().top" );
- equals( jQuery('#absolute-1').position().left, 0, "jQuery('#absolute-1').position().left" );
-
- equals( jQuery('#absolute-1-1').position().top, 1, "jQuery('#absolute-1-1').position().top" );
- equals( jQuery('#absolute-1-1').position().left, 1, "jQuery('#absolute-1-1').position().left" );
-
- equals( jQuery('#absolute-1-1-1').position().top, 1, "jQuery('#absolute-1-1-1').position().top" );
- equals( jQuery('#absolute-1-1-1').position().left, 1, "jQuery('#absolute-1-1-1').position().left" );
-
- equals( jQuery('#absolute-2').position().top, 19, "jQuery('#absolute-2').position().top" );
- equals( jQuery('#absolute-2').position().left, 19, "jQuery('#absolute-2').position().left" );
+ 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 })" );
+ });