Skip to content

Commit

Permalink
detect the silk browser (needs more cleanup work, see the todo in det…
Browse files Browse the repository at this point in the history
…ect.js)
  • Loading branch information
madrobby committed Apr 2, 2012
1 parent 9c95803 commit e97d100
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zepto.js -- a minimalist JavaScript framework

Zepto is a minimalist JavaScript framework for modern browsers with a
Zepto is a minimalist JavaScript framework for modern browsers with a
largely jQuery-compatible API. If you use jQuery, you already know how to use Zepto.

# Documentation
Expand Down
10 changes: 10 additions & 0 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
touchpad = webos && ua.match(/TouchPad/),
kindle = ua.match(/Kindle\/([\d.]+)/),
silk = ua.match(/Silk\/([\d._]+)/),
blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/)

// todo clean this up with a better OS/browser
// separation. we need to discern between multiple
// browsers on android, and decide if kindle fire in
// silk mode is android or not

if (browser.webkit = !!webkit) browser.version = webkit[1]

if (android) os.android = true, os.version = android[2]
Expand All @@ -21,6 +28,9 @@
if (webos) os.webos = true, os.version = webos[2]
if (touchpad) os.touchpad = true
if (blackberry) os.blackberry = true, os.version = blackberry[2]
if (kindle) os.kindle = true, os.version = kindle[1]
if (silk) browser.silk = true, browser.version = silk[1]
if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true
}

detect.call($, navigator.userAgent)
Expand Down
28 changes: 27 additions & 1 deletion test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ <h1>Browser detection</h1>
Firefox_Mobile_Simulator: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:2.1.1) Gecko/ Firefox/4.0.2pre Fennec/4.0.1",

Opera_11_51: "Opera/9.80 (Macintosh; Intel Mac OS X 10.7.1; U; en) Presto/2.9.168 Version/11.51",
Opera_Mobile_Simulator: "Opera/9.80 (Macintosh; Intel Mac OS X; Opera Mobi/[BUILD_NR]; U; en) Presto/2.7.81 Version/11.00"
Opera_Mobile_Simulator: "Opera/9.80 (Macintosh; Intel Mac OS X; Opera Mobi/[BUILD_NR]; U; en) Presto/2.7.81 Version/11.00",

Kindle: "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600×800; rotate)",
Silk_1_0_accel: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.13.328_10008910) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true",
Silk_1_0: "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
}

function detect(ua, callback){
Expand Down Expand Up @@ -141,6 +145,28 @@ <h1>Browser detection</h1>
})
},

testKindle: function(t) {
detect(UA.Kindle, function(os, browser){
t.assertTrue(os.kindle)
t.assertTrue(browser.webkit)
t.assertEqual("3.0", os.version)
})

detect(UA.Silk_1_0, function(os, browser){
t.assertTrue(os.android)
t.assertTrue(browser.webkit)
t.assertTrue(browser.silk)
t.assertEqual("2.3.4", os.version)
})

detect(UA.Silk_1_0_accel, function(os, browser){
t.assert(!os.android)
t.assertTrue(browser.webkit)
t.assertTrue(browser.silk)
t.assertEqual("1.0.13.328_10008910", browser.version)
})
},

testFirefox: function(t) {
detect(UA.Firefox_6_0_2, function(os, browser){
t.assertFalse(browser.webkit)
Expand Down

0 comments on commit e97d100

Please sign in to comment.