Skip to content

Commit

Permalink
Add blackberry detection in $.os
Browse files Browse the repository at this point in the history
  • Loading branch information
peutetre committed Jan 12, 2011
1 parent d4d51fe commit 441c42b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
android = ua.match(/(Android)\s+([\d.]+)/),
iphone = ua.match(/(iPhone\sOS)\s([\d_]+)/),
ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
webos = ua.match(/(webOS)\/([\d.]+)/);
webos = ua.match(/(webOS)\/([\d.]+)/),
blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
if (android) os.android = true, os.version = android[2];
if (iphone) os.ios = true, os.version = iphone[2].replace(/_/g, '.'), os.iphone = true;
if (ipad) os.ios = true, os.version = ipad[2].replace(/_/g, '.'), os.ipad = true;
if (webos) os.webos = true, os.version = webos[2];
if (blackberry) os.blackberry = true, os.version = blackberry[2];
return os;
}
$.os = detect(navigator.userAgent);
Expand Down
8 changes: 7 additions & 1 deletion test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ <h1>Zepto environment detection unit tests</h1>


Android_1_5: "Mozilla/5.0 (Linux; U; Android 1.5; de-; HTC Magic Build/PLAT-RC33) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1",
Android_2_1: "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 Chrome/4.1.249.1025"
Android_2_1: "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 Chrome/4.1.249.1025",

BlackBerry_6_0_0_141: "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.141 Mobile Safari/534.1+"
};

function detect(t, os, version, ua){
Expand Down Expand Up @@ -59,6 +61,10 @@ <h1>Zepto environment detection unit tests</h1>
t.assert($.__detect(UA.iOS_4_0_iPhone).iphone);
},

testBlackBerry: function(t) {
detect(t, "blackberry", "6.0.0.141", UA.BlackBerry_6_0_0_141);
},

testBrowser: function(t){
navigator.userAgent = UA.iOS_4_0_iPhone;
t.assert($.browser);
Expand Down

0 comments on commit 441c42b

Please sign in to comment.