Skip to content

Commit

Permalink
Properly detect os.phone and os.tablet when running on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Sep 15, 2013
1 parent b4260d9 commit 0b9a6ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
ie = ua.match(/MSIE ([\d.]+)/),
safari = webkit && ua.match(/Mobile\//) && !chrome,
webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome,
ie = ua.match(/MSIE ([\d.]+)/)
ie = ua.match(/MSIE\s([\d.]+)/)

// Todo: clean this up with a better OS/browser seperation:
// - discern (more) between multiple browsers on android
Expand Down Expand Up @@ -51,11 +51,13 @@
if (ie) browser.ie = true, browser.version = ie[1]
if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true
if (webview) browser.webview = true
if (ie) browser.ie = true, browser.verson = ie[1]
if (ie) browser.ie = true, browser.version = ie[1]

os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) || (firefox && ua.match(/Tablet/)))
os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
(firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)))
os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 ||
(chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) || (firefox && ua.match(/Mobile/))))
(chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
(firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))))
}

detect.call($, navigator.userAgent)
Expand Down
30 changes: 26 additions & 4 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ <h1>Browser detection</h1>
t.assertEqual("420.1", browser.version)
t.assertTrue(os.phone)
t.assertTrue(browser.safari)
t.assertFalse(!!os.android)
t.assertFalse(!!browser.ie)
t.assertFalse(!!browser.firefox)
t.assertFalse(!!browser.silk)
t.assertFalse(!!browser.chrome)
t.assertFalse(!!browser.playbook)
})
detect(UA.iOS_3_1_1_iPod, function(os, browser){
t.assertTrue(os.ios)
Expand Down Expand Up @@ -370,10 +376,26 @@ <h1>Browser detection</h1>
},

testIE: function(t) {
detect(UA.Windows_IE, function(os, browser){
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})
detect(UA.Windows_IE, function(os, browser){
t.assertFalse(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})

detect(UA.Windows_RT_Surface, function(os, browser){
t.assertFalse(os.phone)
t.assertTrue(os.tablet)
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})

detect(UA.Windows_Phone_8, function(os, browser){
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.ie)
t.assertEqual("10.0", browser.version)
})
}
})
})()
Expand Down

0 comments on commit 0b9a6ea

Please sign in to comment.