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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>goog.userAgent</title>
<link rel="stylesheet" href="css/demo.css">
<style>
th {
text-align: left;
font-weight: normal;
}
thead th {
text-align: left;
font-size: 2em;
}
tbody td {
text-align: center;
}
.container {
margin: 1em 3em 1em 0;
vertical-align: top;
}
.section {
font-weight: bold;
font-size: 1.2em;
border-bottom: 1px solid #ccc;
padding-top: 0.5em;
}
.no {
background: #efefef;
}
.yes {
background: #ddf8cc;
}
</style>
<script src="../base.js"></script>
<script>
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.userAgent');
goog.require('goog.userAgent.adobeReader');
goog.require('goog.userAgent.flash');
goog.require('goog.userAgent.iphoto');
goog.require('goog.userAgent.jscript');
goog.require('goog.userAgent.product');
goog.require('goog.userAgent.product.isVersion');
goog.require('goog.dom.TagName');
</script>
</head>
<body>
<h1>goog.userAgent</h1>
<div class="goog-inline-block container">
<table>
<tbody id="browserFields">
</tbody>
</table>
</div>
<div class="goog-inline-block container">
<table style="display:inline-table">
<tbody id="featureFields">
</tbody>
</table>
</div>
<script>
var platformFields = [
'LINUX',
'MAC',
'WINDOWS',
'X11',
'PLATFORM'
];
var rendererFields = [
'GECKO',
'IE',
'OPERA',
'WEBKIT',
'VERSION'
];
var productFields = [
'ANDROID',
'CHROME',
'FIREFOX',
'IE',
'IPAD',
'IPHONE',
'OPERA',
'SAFARI',
'VERSION'
];
// Public members in goog.userAgent.flash
var flashFields = [
'HAS_FLASH',
'VERSION'
];
// Public members in goog.userAgent.iphoto
var iphotoFields = [
'HAS_IPHOTO',
'VERSION'
];
// Public members in goog.userAgent.jscript
var jscriptFields = [
'HAS_JSCRIPT',
'VERSION'
];
// Public members in goog.userAgent.adobeReader
var adobeReaderFields = [
'HAS_READER',
'SILENT_PRINT',
'VERSION'
];
/**
* Adds a list of user-agent properties and their values to the output table.
* @param {Element} parent The table body to append new rows to
* @param {string} title The header for this table section
* @param {Object} ns The Closure namespace to read properties from
* @param {Array.<string>} A list of properties to read from that namespace
*/
function addSection(parent, title, ns, properties) {
goog.dom.appendChild(
parent,
goog.dom.createDom(goog.dom.TagName.TR,
null,
goog.dom.createDom(goog.dom.TagName.TH,
{'colspan': 2, 'class': 'section'},
title)));
goog.array.forEach(
properties,
function(p) {
addValue(parent, p.toLowerCase(), ns[p]);
})
}
/**
* Adds a name/value row to the table.
* @param {Element} parent The table body to append the row to
* @param {string} name The name of the property
* @param {string|boolean} value The value to display
*/
function addValue(parent, name, value) {
var row = goog.dom.createElement('tr');
goog.dom.appendChild(parent, row);
var nameCell = goog.dom.createDom(goog.dom.TagName.TH, null, name);
goog.dom.appendChild(row, nameCell);
var valueCell = goog.dom.createElement('td');
goog.dom.appendChild(row, valueCell);
if (goog.isBoolean(value)) {
value = value ? 'yes' : 'no';
goog.dom.setTextContent(valueCell, value);
goog.dom.classlist.set(valueCell, value);
} else {
goog.dom.setTextContent(valueCell, value);
if (!value) {
goog.dom.classlist.set(valueCell, 'no');
}
}
}
var browser = goog.dom.getElement('browserFields');
addSection(browser, 'Hardware Platform', goog.userAgent, platformFields);
addSection(browser, 'Renderer', goog.userAgent, rendererFields);
addSection(browser, 'Product', goog.userAgent.product, productFields);
var features = goog.dom.getElement('featureFields');
addSection(features, 'Adobe Reader Detection', goog.userAgent.adobeReader,
adobeReaderFields);
addSection(features, 'Flash Plugin', goog.userAgent.flash, flashFields);
addSection(features, 'iPhoto Detection', goog.userAgent.iphoto, iphotoFields);
addSection(features, 'Microsoft JScript', goog.userAgent.jscript,
jscriptFields);
</script>
</body>
</html>
|