viewport.html
2.95 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>dojo.window.getBox() test</title>
<style type="text/css">
@import "../../../dojo/resources/dojo.css";
html, body { margin: 0px; padding: 0px; }
</style>
<script type="text/javascript" src="../../../dojo/dojo.js" data-dojo-config="isDebug:true"></script>
<script type="text/javascript">
require(["doh", "dojo/dom", "dojo/dom-geometry", "dojo/window", "dojo/domReady!"], function(doh, dom, domGeom, winUtils){
function compute(){
var d = domGeom.getMarginBox(dom.byId("documentBorder")),
v = winUtils.getBox();
dom.byId("results").innerHTML +=
"Document is " + d.w + "px x " + d.h + "px" +
", viewport is " + v.w + "px x " + v.h + "px" +
", with scroll offset of (" + v.l + ", " + v.t + ")<br>";
}
function addText(){
dom.byId("results").innerHTML += "Adding text...<br><br>";
var text=[];
for(var i=0;i<100;i++){
text.push("<span style='white-space: nowrap'>");
for(var j=0;j<3;j++){ text.push("Now is the time for all good men to come to the aid of their country."); }
text.push("</span><br>");
}
dom.byId("documentBorder").innerHTML += text.join("\n");
}
doh.register("dojo.window.viewport", [
function initial(t){
console.log("calling compute");
compute();
console.log("called compute");
var d = domGeom.getMarginBox(dom.byId("documentBorder")),
v = winUtils.getBox();
doh.t(v.h > d.h, "test that viewport is bigger than document");
console.log("v.h is " + v.h + " and d.h is " + d.h);
},
function expand(t){
var v = winUtils.getBox();
console.log("calling addText");
addText();
compute();
var v2 = winUtils.getBox();
doh.t(v2.h <= v.h, "test that viewport didn't increase in size due to text added to document");
doh.t(v2.h+20 >= v.h, "test that viewport didn't shrink, except for space taken by scrollbars");
console.log("end");
}
]);
doh.run();
});
</script>
</head>
<body>
<div id="documentBorder" style="border: solid red 2px;">
<h1>dojo.window.getBox() test</h1>
<div style="padding: 10px; border: solid blue 1px;">padding div</div>
<button onclick="addText(); compute();">add text and compute size</button>
<button onclick="compute();">recompute size</button>
<ol>
<li>check results div below to see that before adding text, document is smaller than viewport
<li>after adding text, document should be bigger than viewport,and check that viewport size hasn't changed,
except maybe being a little bit smaller (about 15px) because of the size of the scrollbars
<li>resize browser window and click the "recompute size" button; reported viewport size should change
<li>scroll the window and click "recompute size" to see that the scroll position is taken into effect
</ol>
<div id=results style="border: 5px solid blue;"></div>
</div>
</body>
</html>