UNPKG

sku-pg

Version:

Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!

174 lines (145 loc) 4.1 kB
<!DOCTYPE html> <html> <!-- Copyright 2010 The Closure Library Authors. All Rights Reserved. Use of this source code is governed by an Apache 2.0 License. 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; } .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.classes'); goog.require('goog.userAgent'); goog.require('goog.userAgent.adobeReader'); goog.require('goog.userAgent.flash'); goog.require('goog.userAgent.iphoto'); goog.require('goog.userAgent.picasa'); </script> </head> <body> <h1>goog.userAgent</h1> <table> <tbody id="fields"> </tbody> </table> <script> var platformFields = [ 'LINUX', 'MAC', 'WINDOWS', 'X11', 'PLATFORM' ]; var browserFields = [ 'GECKO', 'IE', 'OPERA', 'WEBKIT', 'VERSION' ]; // Public members in goog.userAgent.flash var flashFields = [ 'HAS_FLASH', 'VERSION' ]; // Public members in goog.userAgent.picasa var picasaFields = [ 'HAS_PICASA', 'VERSION' ]; // Public members in goog.userAgent.iphoto var iphotoFields = [ 'HAS_IPHOTO', 'VERSION' ]; // Public members in goog.userAgent.adobeReader var adobeReaderFields = [ 'HAS_READER', 'VERSION', 'SILENT_PRINT' ]; /** * 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('tr', null, goog.dom.createDom('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('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.classes.set(valueCell, value); } else { goog.dom.setTextContent(valueCell, value); if (!value) { goog.dom.classes.set(valueCell, 'no'); } } } var fields = goog.dom.getElement('fields'); addSection(fields, 'Hardware Platform', goog.userAgent, platformFields); addSection(fields, 'Browser Info', goog.userAgent, browserFields); addSection(fields, 'Flash Plugin', goog.userAgent.flash, flashFields); addSection(fields, 'Picasa Detection', goog.userAgent.picasa, picasaFields); addSection(fields, 'iPhoto Detection', goog.userAgent.iphoto, iphotoFields); addSection(fields, 'Adobe Reader Detection', goog.userAgent.adobeReader, adobeReaderFields); </script> </body> </html>