Debian Codegraph @

closure-library/closure/goog/demos/useragent.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2010 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>goog.userAgent</title>
11 <link rel="stylesheet" href="css/demo.css">
12 <style>
13 th {
14 text-align: left;
15 font-weight: normal;
16 }
17
18 thead th {
19 text-align: left;
20 font-size: 2em;
21 }
22
23 tbody td {
24 text-align: center;
25 }
26
27 .container {
28 margin: 1em 3em 1em 0;
29 vertical-align: top;
30 }
31
32 .section {
33 font-weight: bold;
34 font-size: 1.2em;
35 border-bottom: 1px solid #ccc;
36 padding-top: 0.5em;
37 }
38
39 .no {
40 background: #efefef;
41 }
42
43 .yes {
44 background: #ddf8cc;
45 }
46 </style>
47
48 <script src="../base.js"></script>
49 <script>
50 goog.require('goog.array');
51 goog.require('goog.dom');
52 goog.require('goog.dom.classlist');
53 goog.require('goog.userAgent');
54 goog.require('goog.userAgent.adobeReader');
55 goog.require('goog.userAgent.flash');
56 goog.require('goog.userAgent.iphoto');
57 goog.require('goog.userAgent.jscript');
58 goog.require('goog.userAgent.product');
59 goog.require('goog.userAgent.product.isVersion');
60 goog.require('goog.dom.TagName');
61 </script>
62
63 </head>
64 <body>
65 <h1>goog.userAgent</h1>
66
67 <div class="goog-inline-block container">
68 <table>
69 <tbody id="browserFields">
70 </tbody>
71 </table>
72 </div>
73
74 <div class="goog-inline-block container">
75 <table style="display:inline-table">
76 <tbody id="featureFields">
77 </tbody>
78 </table>
79 </div>
80
81
82 <script>
83
84 var platformFields = [
85 'LINUX',
86 'MAC',
87 'WINDOWS',
88 'X11',
89 'PLATFORM'
90 ];
91
92 var rendererFields = [
93 'GECKO',
94 'IE',
95 'OPERA',
96 'WEBKIT',
97 'VERSION'
98 ];
99
100 var productFields = [
101 'ANDROID',
102 'CHROME',
103 'FIREFOX',
104 'IE',
105 'IPAD',
106 'IPHONE',
107 'OPERA',
108 'SAFARI',
109 'VERSION'
110 ];
111
112 // Public members in goog.userAgent.flash
113 var flashFields = [
114 'HAS_FLASH',
115 'VERSION'
116 ];
117
118 // Public members in goog.userAgent.iphoto
119 var iphotoFields = [
120 'HAS_IPHOTO',
121 'VERSION'
122 ];
123
124 // Public members in goog.userAgent.jscript
125 var jscriptFields = [
126 'HAS_JSCRIPT',
127 'VERSION'
128 ];
129
130 // Public members in goog.userAgent.adobeReader
131 var adobeReaderFields = [
132 'HAS_READER',
133 'SILENT_PRINT',
134 'VERSION'
135 ];
136
137 /**
138 * Adds a list of user-agent properties and their values to the output table.
139 * @param {Element} parent The table body to append new rows to
140 * @param {string} title The header for this table section
141 * @param {Object} ns The Closure namespace to read properties from
142 * @param {Array.<string>} A list of properties to read from that namespace
143 */
144 function addSection(parent, title, ns, properties) {
145 goog.dom.appendChild(
146 parent,
147 goog.dom.createDom(goog.dom.TagName.TR,
148 null,
149 goog.dom.createDom(goog.dom.TagName.TH,
150 {'colspan': 2, 'class': 'section'},
151 title)));
152
153 goog.array.forEach(
154 properties,
155 function(p) {
156 addValue(parent, p.toLowerCase(), ns[p]);
157 })
158 }
159
160
161 /**
162 * Adds a name/value row to the table.
163 * @param {Element} parent The table body to append the row to
164 * @param {string} name The name of the property
165 * @param {string|boolean} value The value to display
166 */
167 function addValue(parent, name, value) {
168 var row = goog.dom.createElement('tr');
169 goog.dom.appendChild(parent, row);
170
171 var nameCell = goog.dom.createDom(goog.dom.TagName.TH, null, name);
172 goog.dom.appendChild(row, nameCell);
173
174 var valueCell = goog.dom.createElement('td');
175 goog.dom.appendChild(row, valueCell);
176
177 if (goog.isBoolean(value)) {
178 value = value ? 'yes' : 'no';
179 goog.dom.setTextContent(valueCell, value);
180 goog.dom.classlist.set(valueCell, value);
181 } else {
182 goog.dom.setTextContent(valueCell, value);
183 if (!value) {
184 goog.dom.classlist.set(valueCell, 'no');
185 }
186 }
187 }
188
189
190 var browser = goog.dom.getElement('browserFields');
191 addSection(browser, 'Hardware Platform', goog.userAgent, platformFields);
192 addSection(browser, 'Renderer', goog.userAgent, rendererFields);
193 addSection(browser, 'Product', goog.userAgent.product, productFields);
194
195 var features = goog.dom.getElement('featureFields');
196 addSection(features, 'Adobe Reader Detection', goog.userAgent.adobeReader,
197 adobeReaderFields);
198 addSection(features, 'Flash Plugin', goog.userAgent.flash, flashFields);
199 addSection(features, 'iPhoto Detection', goog.userAgent.iphoto, iphotoFields);
200 addSection(features, 'Microsoft JScript', goog.userAgent.jscript,
201 jscriptFields);
202
203 </script>
204
205 </body>
206 </html>