aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/offset.js
blob: 328442ac1ed9f239f6c83aa5324ab6674542b905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
module("offset");

// opens a new window to run the tests against
var testwin = function(name, fn) {
	testwin[name] = load_offset_fixture(name);
	var interval = setInterval(function() {
		if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) {
			clearInterval(interval);
			test(name, fn);
		}
	}, 0);
	
	function load_offset_fixture(name) {
		var win = window.open( "./data/offset/" + name + ".html?num"+parseInt(Math.random()*1000), name, 'left=0,top=0,width=500,height=500,toolbar=1,resizable=0' );
		if ( !win ) { 
			alert("Please disable your popup blocker for the offset test suite");
			throw "Please disable your popup blocker for the offset test suite";
		}
		return win;
	}
};

testwin("absolute", function() {
	var $w = testwin["absolute"].$;
	
	equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" );
	equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" );
	
	equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" );
	equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" );
	
	equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" );
	equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" );
	
	equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" );
	equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" );
	
	testwin["absolute"].close();
});

testwin("relative", function() {
	var $w = testwin["relative"].$;
	
	equals( $w('#relative-1').offset().top, $.browser.msie ? 6 : 7, "$('#relative-1').offset().top" );
	equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" );
	
	equals( $w('#relative-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#relative-1-1').offset().top" );
	equals( $w('#relative-1-1').offset().left, 15, "$('#relative-1-1').offset().left" );
	
	equals( $w('#relative-2').offset().top, $.browser.msie ? 141 : 142, "$('#relative-2').offset().top" );
	equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" );
	
	testwin["relative"].close();
});

testwin("static", function() {
	var $w = testwin["static"].$;
	
	equals( $w('#static-1').offset().top, $.browser.msie ? 6 : 7, "$('#static-1').offset().top" );
	equals( $w('#static-1').offset().left, 7, "$('#static-1').offset().left" );
	
	equals( $w('#static-1-1').offset().top, $.browser.msie ? 13 : 15, "$('#static-1-1').offset().top" );
	equals( $w('#static-1-1').offset().left, 15, "$('#static-1-1').offset().left" );
	
	equals( $w('#static-1-1-1').offset().top, $.browser.msie ? 20 : 23, "$('#static-1-1-1').offset().top" );
	equals( $w('#static-1-1-1').offset().left, 23, "$('#static-1-1-1').offset().left" );
	
	equals( $w('#static-2').offset().top, $.browser.msie ? 121 : 122, "$('#static-2').offset().top" );
	equals( $w('#static-2').offset().left, 7, "$('#static-2').offset().left" );
	
	testwin["static"].close();
});

if ( !$.browser.msie || ($.browser.msie && parseInt($.browser.version) > 6) )
	testwin("fixed", function() {
		var $w = testwin["fixed"].$;
	
		equals( $w('#fixed-1').offset().top, 1001, "$('#fixed-1').offset().top" );
		equals( $w('#fixed-1').offset().left, $.browser.msie ? 994 : 1001, "$('#fixed-1').offset().left" );
	
		equals( $w('#fixed-2').offset().top, 1021, "$('#fixed-2').offset().top" );
		equals( $w('#fixed-2').offset().left, $.browser.msie ? 1014 : 1021, "$('#fixed-2').offset().left" );
	
		testwin["fixed"].close();
	});

testwin("table", function() {
	var $w = testwin["table"].$;
	
	equals( $w('#table-1').offset().top, 6, "$('#table-1').offset().top" );
	equals( $w('#table-1').offset().left, 6, "$('#table-1').offset().left" );
	
	equals( $w('#th-1').offset().top, 10, "$('#table-1').offset().top" );
	equals( $w('#th-1').offset().left, 10, "$('#table-1').offset().left" );
	
	equals( $w('#th-2').offset().top, 10, "$('#table-1').offset().top" );
	equals( $w('#th-2').offset().left, 116, "$('#table-1').offset().left" );
	
	testwin["table"].close();
});

testwin("scroll", function() {
	var $w = testwin["scroll"].$;
	
	equals( $w('#scroll-1').offset().top, $.browser.msie ? 6 : 7, "$('#scroll-1').offset().top" );
	equals( $w('#scroll-1').offset().left, 7, "$('#scroll-1').offset().left" );
	
	equals( $w('#scroll-1-1').offset().top, $.browser.msie ? 9 : 11, "$('#scroll-1-1').offset().top" );
	equals( $w('#scroll-1-1').offset().left, 11, "$('#scroll-1-1').offset().left" );
	
	testwin["scroll"].close();
});