Skip to content

Instantly share code, notes, and snippets.

Created October 22, 2013 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/e73e7b598b5f5cb1ba69 to your computer and use it in GitHub Desktop.
Save anonymous/e73e7b598b5f5cb1ba69 to your computer and use it in GitHub Desktop.
define("OS", [], function () {
var d = navigator.userAgent,
b = {}, c = d.match(/(Android)\s+([\d.]+)/),
f = d.match(/(iPhone\sOS)\s([\d_]+)/),
i = d.match(/(iPad).*OS\s([\d_]+)/),
v = d.match(/(webOS)\/([\d.]+)/),
e = d.match(/(BlackBerry|RIM).*Version\/([\d.]+)/),
n = d.match(/(Firefox)\/([\d.]+)/),
o = d.match(/(Opera\sMini)\/([\d.]+)/),
t = d.match(/(Safari)\/([\d.]+)/);
d = d.match(/(Chrome)\/([\d.]+)/);
b.supported = false;
if (c) {
b.android = true;
b.version = c[2];
b.supported = true;
b.name = "android"
}
if (f) {
b.ios = true;
b.version = f[2].replace(/_/g,
".");
b.iphone = true;
b.supported = true;
b.name = "iphone"
}
if (i) {
b.ios = true;
b.version = i[2].replace(/_/g, ".");
b.ipad = true;
b.supported = true;
b.name = "ipad"
}
if (v) {
b.webos = true;
b.version = v[2];
b.name = "webos"
}
if (e) {
b.blackberry = true;
b.version = e[2];
b.name = "blackberry"
}
if (n) {
b.browser = "firefox";
b.supported = false
}
if (o) {
b.browser = "operamini";
b.supported = false
}
if (t) {
b.browser = "safari";
b.supported = true
}
if (d) {
b.browser = "chrome";
b.supported = true
}
b.versionAtLeast = function (x) {
x = x.split(".");
for (var H = b.version.split("."),
I = 0, W = x.length; I < W; I++) {
var z = parseInt(H[I], 10),
R = parseInt(x[I], 10);
if (isNaN(z) || z < R) return false
}
return true
};
b.supportsWindowOpenFromTap = function () {
return b.browser === "chrome" || b.browser === "safari" && b.versionAtLeast("6.0.0")
};
b.desktop = navigator.userAgent.match(/(Macintosh;)/) || navigator.userAgent.match(/(Windows;)/) || navigator.userAgent.match(/(X11;)/);
return b
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment