Skip to content

Commit

Permalink
Add PlatformSampler sample that shows the detected platform user agen…
Browse files Browse the repository at this point in the history
…t string and enyo.platform object

Add platform detection for Firefox (desktop) and Firefox on Android

Enyo-DCO-1.0-Signed-Off-By: Ben Combee (ben.combee@palm.com)
  • Loading branch information
Ben Combee committed Oct 22, 2012
1 parent ca91b43 commit d27ac15
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
11 changes: 11 additions & 0 deletions samples/PlatformSample.css
@@ -0,0 +1,11 @@
.platform-sample {
padding: 15px;
}
.platform-sample-divider {
color: #F49200;
text-transform: uppercase;
font-family: Segoe UI, Prelude Medium, Helvetica, Verdana, sans-serif;
font-size: 14px;
font-weight: bold;
margin-bottom: 8px;
}
21 changes: 21 additions & 0 deletions samples/PlatformSample.html
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Platform Sample</title>
<!-- -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<!-- -->
<script src="../enyo.js" type="text/javascript"></script>
<script src="../../lib/layout/package.js" type="text/javascript"></script>
<script src="../../lib/onyx/package.js" type="text/javascript"></script>
<!-- -->
<link href="PlatformSample.css" rel="stylesheet">
<script src="PlatformSample.js" type="text/javascript"></script>
<!-- -->
</head>
<body>
<script type="text/javascript">
new enyo.sample.PlatformSample().renderInto(document.body);
</script>
</body>
</html>
22 changes: 22 additions & 0 deletions samples/PlatformSample.js
@@ -0,0 +1,22 @@
enyo.kind({
name: "enyo.sample.PlatformSample",
kind: "FittableRows",
classes: "enyo-fit platform-sample",
components: [
{classes: "platform-sample-divider", content: "Enyo Platform Detection"},
{kind: "onyx.Groupbox", components: [
{kind: "onyx.GroupboxHeader", content: "User-Agent String"},
{name: "uaString", content: "", style: "padding: 8px;"}
]},
{tag: "br"},
{kind: "onyx.Groupbox", components: [
{kind: "onyx.GroupboxHeader", content: "enyo.platform"},
{name: "enyoPlatformJSON", content: "", style: "padding: 8px;"}
]}
],
create: function() {
this.inherited(arguments);
this.$.uaString.setContent(navigator.userAgent);
this.$.enyoPlatformJSON.setContent(JSON.stringify(enyo.platform));
}
});
2 changes: 2 additions & 0 deletions samples/package.js
@@ -1,5 +1,7 @@
enyo.depends(
"$lib/extra/exampler",
"PlatformSample.css",
"PlatformSample.js",
"Playground.css",
"Playground.js",
"AjaxSample.css",
Expand Down
8 changes: 6 additions & 2 deletions source/dom/platform.js
Expand Up @@ -49,10 +49,14 @@ enyo.platform = {
{platform: "ios", regex: /iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/},
// webOS 1 - 3
{platform: "webos", regex: /(?:web|hpw)OS\/(\d+)/},
// desktop safari
// desktop Safari
{platform: "safari", regex: /Version\/(\d+)[.\d]+\s+Safari/},
// desktop Chrome
{platform: "chrome", regex: /Chrome\/(\d+)[.\d]+/}
{platform: "chrome", regex: /Chrome\/(\d+)[.\d]+/},
// Firefox on Android
{platform: "androidFirefox", regex: /Android;.*Firefox\/(\d+)/},
// desktop Firefox
{platform: "firefox", regex: /Firefox\/(\d+)/}
];
for (var i = 0, p, m, v; p = platforms[i]; i++) {
m = p.regex.exec(ua);
Expand Down

0 comments on commit d27ac15

Please sign in to comment.