Skip to content

Commit

Permalink
Merge branch 'safari-windows'
Browse files Browse the repository at this point in the history
Closes #1008
  • Loading branch information
mislav committed Dec 11, 2014
2 parents 52fe3b0 + a4b55e7 commit ec016ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Zepto.js may be freely distributed under the MIT license.

;(function($){
function detect(ua){
function detect(ua, platform){
var os = this.os = {}, browser = this.browser = {},
webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/),
android = ua.match(/(Android);?[\s\/]+([\d.]+)?/),
Expand All @@ -12,6 +12,7 @@
ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/),
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
win = /Win\d{2}|Windows/.test(platform),
wp = ua.match(/Windows Phone ([\d.]+)/),
touchpad = webos && ua.match(/TouchPad/),
kindle = ua.match(/Kindle\/([\d.]+)/),
Expand Down Expand Up @@ -53,7 +54,10 @@
if (firefox) browser.firefox = true, browser.version = firefox[1]
if (firefoxos) os.firefoxos = true, os.version = firefoxos[1]
if (ie) browser.ie = true, browser.version = ie[1]
if (safari && (osx || os.ios)) {browser.safari = true; if (osx) browser.version = safari[1]}
if (safari && (osx || os.ios || win)) {
browser.safari = true
if (!os.ios) browser.version = safari[1]
}
if (webview) browser.webview = true

os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
Expand All @@ -63,7 +67,7 @@
(firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))))
}

detect.call($, navigator.userAgent)
detect.call($, navigator.userAgent, navigator.platform)
// make available to unit tests
$.__detect = detect

Expand Down
18 changes: 16 additions & 2 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h1>Zepto Detect unit tests</h1>
Safari_OSX_7_0_1: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11",
Safari_OSX_7_0: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9) AppleWebKit/537.71 (KHTML, like Gecko) Version/7.0 Safari/537.71",
Safari_OSX_6_0: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25",
Safari_Windows_NT: "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27",

WebOS_1_4_0_Pre: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.1",
WebOS_1_4_0_Pixi: "Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2 (KHTML, like Gecko) Version/1.0 Safari/532.2 Pixi/1.1",
Expand Down Expand Up @@ -94,9 +95,10 @@ <h1>Zepto Detect unit tests</h1>
Windows_Phone_8: "Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; HTC; Windows Phone 8X by HTC)"
}

function detect(ua, callback){
function detect(ua, platform, callback){
if (!callback) callback = platform, platform = ""
var obj = {}
$.__detect.call(obj, ua)
$.__detect.call(obj, ua, platform)
callback.call(null, obj.os, obj.browser)
}

Expand Down Expand Up @@ -126,6 +128,18 @@ <h1>Zepto Detect unit tests</h1>
});
},

testSafariWindows: function(t){
detect(UA.Safari_Windows_NT, "Windows", function(os, browser){
t.assertUndefined(os.osx)
t.assertUndefined(os.ios)
t.assertUndefined(os.wp)
t.assertTrue(browser.webkit)
t.assertTrue(browser.safari)
t.assertFalse(!!browser.chrome)
t.assertEqual("5.0.4", browser.version)
});
},

testWebOS: function(t){
detect(UA.WebOS_1_4_0_Pre, function(os, browser){
t.assertTrue(os.webos)
Expand Down

0 comments on commit ec016ff

Please sign in to comment.