X Tutup
Skip to content

Commit f576cee

Browse files
committed
Beginnings of the offset test suite
1 parent 76e3a90 commit f576cee

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

test/data/offset/absolute.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
6+
<title>absolute</title>
7+
<style type="text/css" media="screen">
8+
body { margin: 1px; padding: 5px; }
9+
div.absolute { position: absolute; margin: 1px; border: 2px solid #000; padding: 5px; width: 100px; height: 100px; }
10+
#absolute-1 { top: 0; left: 0; }
11+
#absolute-1-1 { top: 1px; left: 1px; }
12+
#absolute-1-1-1 { top: 1px; left: 1px; }
13+
#absolute-2 { top: 19px; left: 19px; }
14+
</style>
15+
<script type="text/javascript" src="../../../dist/jquery.js"></script>
16+
<script type="text/javascript" charset="utf-8"> $(function() { return; }); </script>
17+
</head>
18+
<body>
19+
<div id="absolute-1" class="absolute">absolute-1
20+
<div id="absolute-1-1" class="absolute">absolute-1-1
21+
<div id="absolute-1-1-1" class="absolute">absolute-1-1-1</div>
22+
</div>
23+
</div>
24+
<div id="absolute-2" class="absolute">absolute-2</div>
25+
</body>
26+
</html>

test/data/offset/relative.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3+
<html>
4+
<head>
5+
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
6+
<title>relative</title>
7+
<style type="text/css" media="screen">
8+
body { margin: 1px; padding: 5px; }
9+
div.relative { position: relative; margin: 1px; border: 2px solid #000; padding: 5px; width: 100px; height: 100px; background: #fff; overflow: hidden; }
10+
#relative-2 { top: 20px; left: 20px; }
11+
#marker { position: absolute; border: 2px solid #000; width: 50px; height: 50px; background: #ccc; }
12+
</style>
13+
<script type="text/javascript" src="../../../dist/jquery.js"></script>
14+
<script type="text/javascript" charset="utf-8">
15+
$(function() {
16+
$('.relative').click(function() {
17+
$('#marker').css( $(this).offset() );
18+
return false;
19+
});
20+
});
21+
</script>
22+
</head>
23+
<body>
24+
<div id="relative-1" class="relative">relative-1
25+
<div id="relative-1-1" class="relative">relative-1-1
26+
<div id="relative-1-1-1" class="relative">relative-1-1-1</div>
27+
</div>
28+
</div>
29+
<div id="relative-2" class="relative">relative-2</div>
30+
<div id="marker"></div>
31+
</body>
32+
</html>

test/offset.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="html">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>jQuery Offset Test Suite</title>
6+
<link rel="Stylesheet" media="screen" href="data/testsuite.css" />
7+
<script type="text/javascript" src="../dist/jquery.js"></script>
8+
<script type="text/javascript" src="data/testrunner.js"></script>
9+
<script type="text/javascript" src="unit/offset.js"></script>
10+
</head>
11+
12+
<body id="body">
13+
<h1 id="header">jQuery Offset Test Suite</h1>
14+
<h2 id="banner"></h2>
15+
<h2 id="userAgent"></h2>
16+
17+
<!-- Test HTML -->
18+
<div id="nothiddendiv" style="height:1px;background:white;"></div>
19+
<dl id="dl" style="display:none;">
20+
<div id="main" style="display: none;">
21+
22+
</div>
23+
</dl>
24+
25+
<ol id="tests"></ol>
26+
</body>
27+
</html>

test/unit/offset.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module("offset");
2+
3+
// opens a new window to run the tests against
4+
var testwin = function(name, fn) {
5+
testwin[name] = load_offset_fixture(name);
6+
var interval = setInterval(function() {
7+
if (testwin[name] && testwin[name].$ && testwin[name].$.isReady) {
8+
clearInterval(interval);
9+
test(name, fn);
10+
}
11+
}, 0);
12+
13+
function load_offset_fixture(name) {
14+
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' );
15+
if ( !win ) {
16+
alert("Please disable your popup blocker for the offset test suite");
17+
throw "Please disable your popup blocker for the offset test suite";
18+
}
19+
return win;
20+
}
21+
};
22+
23+
testwin("absolute", function() {
24+
var $w = testwin["absolute"].$;
25+
26+
equals( $w('#absolute-1').offset().top, 1, "$('#absolute-1').offset().top" );
27+
equals( $w('#absolute-1').offset().left, 1, "$('#absolute-1').offset().left" );
28+
29+
equals( $w('#absolute-1-1').offset().top, 5, "$('#absolute-1-1').offset().top" );
30+
equals( $w('#absolute-1-1').offset().left, 5, "$('#absolute-1-1').offset().left" );
31+
32+
equals( $w('#absolute-1-1-1').offset().top, 9, "$('#absolute-1-1-1').offset().top" );
33+
equals( $w('#absolute-1-1-1').offset().left, 9, "$('#absolute-1-1-1').offset().left" );
34+
35+
equals( $w('#absolute-2').offset().top, 20, "$('#absolute-2').offset().top" );
36+
equals( $w('#absolute-2').offset().left, 20, "$('#absolute-2').offset().left" );
37+
38+
testwin["absolute"].close();
39+
});
40+
41+
testwin("relative", function() {
42+
var $w = testwin["relative"].$;
43+
44+
equals( $w('#relative-1').offset().top, jQuery.browser.msie ? 6 : 7, "$('#relative-1').offset().top" );
45+
equals( $w('#relative-1').offset().left, 7, "$('#relative-1').offset().left" );
46+
47+
equals( $w('#relative-2').offset().top, jQuery.browser.msie ? 141 : 142, "$('#relative-2').offset().top" );
48+
equals( $w('#relative-2').offset().left, 27, "$('#relative-2').offset().left" );
49+
50+
testwin["relative"].close();
51+
});

0 commit comments

Comments
 (0)
X Tutup