Debian Codegraph @

test/viewport.html

raw
1 <!doctype html>
2 <html>
3 <head>
4 <meta charset="utf-8"/>
5 <title>Test: Responsive without ViewPort Tag</title>
6 </head>
7 <body>
8 <h2>Viewport Detections</h2>
9 <h3><a href="viewport-meta.html">With ViewPort Tag</a></h3>
10
11 <div id="result"></div>
12
13 <ul>
14 <li>1) Prefered: Inner browser surface/viewport. Excludes toolbars & scrollbars.</li>
15 <li>2) Fallback: Like 1, but not supported everywhere.</li>
16 <li>3) Experimental: Just testing accuracy here.</li>
17 <li>4) Prefered: Current browser size. Also takes into account a resized browser window.</li>
18 <li>5) Fallback: Measures the entire screen resolution.</li>
19 <li><a href="http://www.browserscope.org/user/tests/table/agt1YS1wcm9maWxlcnIRCxIEVGVzdBiAgICA-dvoCQw?v=3&layout=simple" target="results">BrowserScope Results</a></li>
20 </ul>
21
22 <script>
23 // Throttle navigators from triggering too many resize events
24 var resizeId = 0;
25 function onResize() {
26 clearTimeout(resizeId);
27 resizeId = setTimeout(resize, 50);
28 }
29
30 function addResult(title, value) {
31 var ele = document.createElement("div");
32
33 if (value !== false) {
34 ele.innerHTML = title + ": " + value;
35
36 if (value === "false") {
37 value = 0;
38 }
39 else if (value === "true") {
40 value = 1;
41 }
42
43 browserScopeAdd(title, value);
44 } else {
45 ele.innerHTML = title;
46 }
47
48 return ele;
49 }
50
51 // Log results to BrowserScope
52 function browserScopeClear() {
53 window._bTestResults = {};
54 }
55
56 function browserScopeAdd(title, value) {
57 window._bTestResults = window._bTestResults || {};
58 window._bTestResults[title] = value;
59 }
60
61 function browserScopeLog() {
62 var result = document.getElementById("browserscope");
63 if (result) {
64 result.parentNode.removeChild(result);
65 }
66
67 var apiKey = 'agt1YS1wcm9maWxlcnIRCxIEVGVzdBiAgICA-dvoCQw';
68 var script = document.createElement('script');
69
70 script.id = "browserscope";
71 script.src = 'http://www.browserscope.org/user/beacon/' + apiKey;
72
73 // use insertBefore to keep IE from throwing Operation Aborted (thx Bryan Forbes!)
74 var head = document.head || document.getElementsByTagName('head')[0];
75 // but insert at end of head, because otherwise if it is a stylesheet, it will not override values
76 head.insertBefore(script, head.lastChild);
77 }
78
79 // Detect
80 function resize() {
81 browserScopeClear();
82
83 var result = document.getElementById("result");
84 var parent = result.parentNode;
85 parent.removeChild(result);
86
87 var newResult = document.createElement("div");
88 newResult.id = "result";
89
90 newResult.appendChild(addResult("1) INNER measurements", false));
91
92 newResult.appendChild(addResult("innerWidth" , window.innerWidth));
93 newResult.appendChild(addResult("innerHeight", window.innerHeight));
94 newResult.appendChild(addResult("landscape (iwh)", (window.innerWidth > window.innerHeight).toString()));
95
96 newResult.appendChild(addResult("<br/>", false));
97 newResult.appendChild(addResult("2) INNER measurements", false));
98
99 newResult.appendChild(addResult("clientWidth" , document.documentElement.clientWidth));
100 newResult.appendChild(addResult("clientHeight", document.documentElement.clientHeight));
101 newResult.appendChild(addResult("landscape (cwh)", (document.documentElement.clientWidth > document.documentElement.clientHeight).toString()));
102
103 newResult.appendChild(addResult("<br/>", false));
104 newResult.appendChild(addResult("3) INNER measurements", false));
105
106 newResult.appendChild(addResult("availWidth", window.screen.availWidth));
107 newResult.appendChild(addResult("availHeight", window.screen.availHeight));
108 newResult.appendChild(addResult("landscape (awh)", (window.screen.availWidth > window.screen.availHeight).toString()));
109
110 newResult.appendChild(addResult("<br/>", false));
111 newResult.appendChild(addResult("4) OUTER measurements", false));
112
113 newResult.appendChild(addResult("outerWidth" , window.outerWidth));
114 newResult.appendChild(addResult("outerHeight", window.outerHeight));
115 newResult.appendChild(addResult("landscape (owh)", (window.outerWidth > window.outerHeight).toString()));
116
117 newResult.appendChild(addResult("<br/>", false));
118 newResult.appendChild(addResult("5) OUTER measurements", false));
119
120 newResult.appendChild(addResult("screen.width" , window.screen.width));
121 newResult.appendChild(addResult("screen.height", window.screen.height));
122 newResult.appendChild(addResult("landscape (swh)", (window.screen.width > window.screen.height).toString()));
123
124 parent.appendChild(newResult);
125 browserScopeLog();
126 }
127
128 resize();
129
130 // Manually attach, as to not overwrite existing handler
131 if (window.addEventListener) {
132 window.addEventListener("resize", onResize, false);
133
134 } else {
135 window.attachEvent("onresize", onResize);
136 }
137 </script>
138 </body>
139 </html>