html_docScroll.html
3.18 KB
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>testing Core _docScroll function</title>
<script type="text/javascript" src="../../dojo.js" data-dojo-config="isDebug:true"></script>
<script type="text/javascript">
require(["dojo", "doh", "dojo/domReady!"], function(dojo, doh){
doh.register("t",
[
function testNonScrolled(t){
dojo.global.scrollTo(0,0);
var s = dojo._docScroll();
t.is(0, s.x);
t.is(0, s.y);
},
function testScrolled(t){
dojo.global.scrollTo(1,2);
var s = dojo._docScroll();
t.is(1, s.x);
t.is(2, s.y);
},
function testQuirksNonScrolled(t){
var win = dojo.byId('iframe').iframeContentWindow;
win.scrollTo(0,0);
var s = dojo.withGlobal(win, "_docScroll", dojo);
t.is(0, s.x);
t.is(0, s.y);
var s = dojo._docScroll();
t.is(1, s.x);
t.is(2, s.y);
},
function testQuirksScrolled(t){
dojo.global.scrollTo(0,0);
var win = dojo.byId('iframe').iframeContentWindow;
win.scrollTo(10,20);
var s = dojo.withGlobal(win, "_docScroll", dojo);
t.is(10, s.x);
t.is(20, s.y);
},
function testSpeed(t){
var old_docScroll = function(){
var
_b = dojo.body(),
_w = dojo.global,
de = dojo.doc.documentElement;
return {
y: (_w.pageYOffset || de.scrollTop || _b.scrollTop || 0),
x: (_w.pageXOffset || dojo._fixIeBiDiScrollLeft(de.scrollLeft) || _b.scrollLeft || 0)
};
};
var count = 10000; // initial guess
var new_docScroll = dojo._docScroll;
var t0 = new Date().getTime();
for (var i=0; i < count; i++){
var j = new_docScroll();
}
t0 = new Date().getTime() - t0;
// modify guess to get about 1 second of CPU crunching
if(t0 < 50){ // crazy short time
count *= 25;
}else{
count = Math.ceil(10000000/t0);
}
t0 = new Date().getTime();
for (i=0; i < count; i++){
j = new_docScroll();
}
t0 = new Date().getTime() - t0;
var t1 = new Date().getTime();
for (var i=0; i < count; i++){
j = old_docScroll();
}
t1 = new Date().getTime() - t1;
console.log(Math.floor(100*(t1-t0)/t1)+"% speed improvement");
t.is(true, t1 > t0);
}
]
);
doh.runOnLoad();
});
</script>
</head>
<body>
<h1>testing Core _docScroll function</h1>
<div id='div' style="border:0px;padding:0px;margin:0px;">
<iframe id="iframe" src="javascript:'<html><head><script>frameElement.iframeContentWindow=window</script></head><body><div style=\'height:500px;width:500px;\'> </div></body>'"></iframe>
</div>
<script type="text/javascript">
// make sure div is too big to display
require(["dojo"], function(dojo) {
var div = dojo.byId('div');
div.style.height = (dojo.doc.documentElement.clientHeight + 2) + "px";
div.style.width = (dojo.doc.documentElement.clientWidth + 1) + "px";
});
</script>
</body>
</html>