useragent.html 4.8 KB

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