|
1 | 1 | module("offset"); |
2 | 2 |
|
| 3 | +testoffset("absolute"/* in iframe */, function($, iframe) { |
| 4 | + expect(4); |
| 5 | + |
| 6 | + var doc = iframe.document, tests; |
| 7 | + |
| 8 | + // force a scroll value on the main window |
| 9 | + // this insures that the results will be wrong |
| 10 | + // if the offset method is using the scroll offset |
| 11 | + // of the parent window |
| 12 | + var forceScroll = jQuery('<div>', { width: 2000, height: 2000 }).appendTo('body'); |
| 13 | + window.scrollTo(1, 1); |
| 14 | + |
| 15 | + // get offset |
| 16 | + tests = [ |
| 17 | + { id: '#absolute-1', top: 1, left: 1 } |
| 18 | + ]; |
| 19 | + jQuery.each( tests, function() { |
| 20 | + equals( jQuery( this.id, doc ).offset().top, this.top, "jQuery('" + this.id + "').offset().top" ); |
| 21 | + equals( jQuery( this.id, doc ).offset().left, this.left, "jQuery('" + this.id + "').offset().left" ); |
| 22 | + }); |
| 23 | + |
| 24 | + |
| 25 | + // get position |
| 26 | + tests = [ |
| 27 | + { id: '#absolute-1', top: 0, left: 0 } |
| 28 | + ]; |
| 29 | + jQuery.each( tests, function() { |
| 30 | + equals( jQuery( this.id, doc ).position().top, this.top, "jQuery('" + this.id + "').position().top" ); |
| 31 | + equals( jQuery( this.id, doc ).position().left, this.left, "jQuery('" + this.id + "').position().left" ); |
| 32 | + }); |
| 33 | + |
| 34 | + forceScroll.remove(); |
| 35 | +}); |
| 36 | + |
3 | 37 | testoffset("absolute", function( jQuery ) { |
4 | 38 | expect(144); |
5 | 39 |
|
@@ -306,8 +340,8 @@ testoffset("body", function( jQuery ) { |
306 | 340 | }); |
307 | 341 |
|
308 | 342 | test("Chaining offset(coords) returns jQuery object", function() { |
309 | | - expect(2); |
310 | | - var coords = { top: 1, left: 1 }; |
| 343 | + expect(2); |
| 344 | + var coords = { top: 1, left: 1 }; |
311 | 345 | equals( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" ); |
312 | 346 | equals( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" ); |
313 | 347 | }); |
|
0 commit comments