diff --git a/README.md b/README.md index 09d2e53..438e01b 100644 --- a/README.md +++ b/README.md @@ -67,10 +67,12 @@ The following properties of the global `isMobile` object will either be `true` o ### "Other" devices -* `isMobile.other_blackberry_10` -* `isMobile.other_blackberry` -* `isMobile.other_opera` (Opera Mini) -* `isMobile.other_firefox` +* `isMobile.other.blackberry_10` +* `isMobile.other.blackberry` +* `isMobile.other.opera` (Opera Mini) +* `isMobile.other.firefox` +* `isMobile.other.chrome` +* `isMobile.other.device` (any "Other" device) ### Aggregate Groupings diff --git a/isMobile.js b/isMobile.js index e6f8134..2f77341 100644 --- a/isMobile.js +++ b/isMobile.js @@ -23,6 +23,7 @@ other_blackberry = /BlackBerry/i, other_blackberry_10 = /BB10/i, other_opera = /Opera Mini/i, + other_chrome = /(CriOS|Chrome)(?=.*\bMobile\b)/i, other_firefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i, // Match 'Firefox' AND 'Mobile' seven_inch = new RegExp( '(?:' + // Non-capturing group @@ -88,7 +89,8 @@ blackberry10: match(other_blackberry_10, ua), opera: match(other_opera, ua), firefox: match(other_firefox, ua), - device: match(other_blackberry, ua) || match(other_blackberry_10, ua) || match(other_opera, ua) || match(other_firefox, ua) + chrome: match(other_chrome, ua), + device: match(other_blackberry, ua) || match(other_blackberry_10, ua) || match(other_opera, ua) || match(other_firefox, ua) || match(other_chrome, ua) }; this.seven_inch = match(seven_inch, ua); this.any = this.apple.device || this.android.device || this.windows.device || this.other.device || this.seven_inch; diff --git a/isMobile.min.js b/isMobile.min.js index 2c6e214..06771a4 100644 --- a/isMobile.min.js +++ b/isMobile.min.js @@ -1 +1 @@ -!function(a){var b=/iPhone/i,c=/iPod/i,d=/iPad/i,e=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,f=/Android/i,g=/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,h=/(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,i=/IEMobile/i,j=/(?=.*\bWindows\b)(?=.*\bARM\b)/i,k=/BlackBerry/i,l=/BB10/i,m=/Opera Mini/i,n=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,o=new RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),p=function(a,b){return a.test(b)},q=function(a){var q=a||navigator.userAgent,r=q.split("[FBAN");return"undefined"!=typeof r[1]&&(q=r[0]),this.apple={phone:p(b,q),ipod:p(c,q),tablet:!p(b,q)&&p(d,q),device:p(b,q)||p(c,q)||p(d,q)},this.amazon={phone:p(g,q),tablet:!p(g,q)&&p(h,q),device:p(g,q)||p(h,q)},this.android={phone:p(g,q)||p(e,q),tablet:!p(g,q)&&!p(e,q)&&(p(h,q)||p(f,q)),device:p(g,q)||p(h,q)||p(e,q)||p(f,q)},this.windows={phone:p(i,q),tablet:p(j,q),device:p(i,q)||p(j,q)},this.other={blackberry:p(k,q),blackberry10:p(l,q),opera:p(m,q),firefox:p(n,q),device:p(k,q)||p(l,q)||p(m,q)||p(n,q)},this.seven_inch=p(o,q),this.any=this.apple.device||this.android.device||this.windows.device||this.other.device||this.seven_inch,this.phone=this.apple.phone||this.android.phone||this.windows.phone,this.tablet=this.apple.tablet||this.android.tablet||this.windows.tablet,"undefined"==typeof window?this:void 0},r=function(){var a=new q;return a.Class=q,a};"undefined"!=typeof module&&module.exports&&"undefined"==typeof window?module.exports=q:"undefined"!=typeof module&&module.exports&&"undefined"!=typeof window?module.exports=r():"function"==typeof define&&define.amd?define("isMobile",[],a.isMobile=r()):a.isMobile=r()}(this); \ No newline at end of file +!function(a){var b=/iPhone/i,c=/iPod/i,d=/iPad/i,e=/(?=.*\bAndroid\b)(?=.*\bMobile\b)/i,f=/Android/i,g=/(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,h=/(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,i=/IEMobile/i,j=/(?=.*\bWindows\b)(?=.*\bARM\b)/i,k=/BlackBerry/i,l=/BB10/i,m=/Opera Mini/i,n=/(CriOS|Chrome)(?=.*\bMobile\b)/i,o=/(?=.*\bFirefox\b)(?=.*\bMobile\b)/i,p=new RegExp("(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)","i"),q=function(a,b){return a.test(b)},r=function(a){var r=a||navigator.userAgent,s=r.split("[FBAN");return"undefined"!=typeof s[1]&&(r=s[0]),this.apple={phone:q(b,r),ipod:q(c,r),tablet:!q(b,r)&&q(d,r),device:q(b,r)||q(c,r)||q(d,r)},this.amazon={phone:q(g,r),tablet:!q(g,r)&&q(h,r),device:q(g,r)||q(h,r)},this.android={phone:q(g,r)||q(e,r),tablet:!q(g,r)&&!q(e,r)&&(q(h,r)||q(f,r)),device:q(g,r)||q(h,r)||q(e,r)||q(f,r)},this.windows={phone:q(i,r),tablet:q(j,r),device:q(i,r)||q(j,r)},this.other={blackberry:q(k,r),blackberry10:q(l,r),opera:q(m,r),firefox:q(o,r),chrome:q(n,r),device:q(k,r)||q(l,r)||q(m,r)||q(o,r)||q(n,r)},this.seven_inch=q(p,r),this.any=this.apple.device||this.android.device||this.windows.device||this.other.device||this.seven_inch,this.phone=this.apple.phone||this.android.phone||this.windows.phone,this.tablet=this.apple.tablet||this.android.tablet||this.windows.tablet,"undefined"==typeof window?this:void 0},s=function(){var a=new r;return a.Class=r,a};"undefined"!=typeof module&&module.exports&&"undefined"==typeof window?module.exports=r:"undefined"!=typeof module&&module.exports&&"undefined"!=typeof window?module.exports=s():"function"==typeof define&&define.amd?define("isMobile",[],a.isMobile=s()):a.isMobile=s()}(this); \ No newline at end of file diff --git a/tests/spec/OtherSpec.js b/tests/spec/OtherSpec.js index 15c8a63..0578108 100644 --- a/tests/spec/OtherSpec.js +++ b/tests/spec/OtherSpec.js @@ -14,6 +14,10 @@ describe("Other Mobile Devices", function(){ mobile = new isMobile.Class(userAgent); }); + it("should not be a Chrome device", function() { + expect(mobile.other.chrome).not.toBe(true); + }); + it("should be a BlackBerry 10 device", function() { expect(mobile.other.blackberry10).toBe(true); }); @@ -43,6 +47,10 @@ describe("Other Mobile Devices", function(){ mobile = new isMobile.Class(userAgent); }); + it("should not be a Chrome device", function() { + expect(mobile.other.chrome).not.toBe(true); + }); + it("should be a BlackBerry device", function() { expect(mobile.other.blackberry).toBe(true); }); @@ -72,6 +80,10 @@ describe("Other Mobile Devices", function(){ mobile = new isMobile.Class(userAgent); }); + it("should not be a Chrome device", function() { + expect(mobile.other.chrome).not.toBe(true); + }); + it("should be an Opera Mini device", function() { expect(mobile.other.opera).toBe(true); }); @@ -97,6 +109,10 @@ describe("Other Mobile Devices", function(){ mobile = new isMobile.Class(userAgent); }); + it("should not be a Chrome device", function() { + expect(mobile.other.chrome).not.toBe(true); + }); + it("should be a Firefox OS device", function() { expect(mobile.other.firefox).toBe(true); }); @@ -115,4 +131,33 @@ describe("Other Mobile Devices", function(){ }); + describe("Chrome", function() { + + beforeEach(function() { + userAgent = "Mozilla/5.0 (Linux; Android 4.4.4; en-us; Nexus 4 Build/JOP40D) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2307.2 Mobile Safari/537.36"; + mobile = new isMobile.Class(userAgent); + }); + + it("should be a Chrome device", function() { + expect(mobile.other.chrome).toBe(true); + }); + + it("should be an Android device", function() { + expect(mobile.android.device).toBe(true); + }); + + it("should not be a Firefox OS device", function() { + expect(mobile.other.firefox).toBe(false); + }); + + it("should not be an Apple device", function() { + expect(mobile.apple.device).not.toBe(true); + }); + + it("should be a mobile device", function() { + expect(mobile.any).toBe(true); + }); + + }); + });