Skip to content

Commit

Permalink
Merge pull request #35 from isRuslan/master
Browse files Browse the repository at this point in the history
Add mobile Chrome detection
  • Loading branch information
kaimallea committed Jul 16, 2015
2 parents f44fcfa + 8809f0c commit dd78759
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion isMobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion isMobile.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions tests/spec/OtherSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand All @@ -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);
});

});

});

0 comments on commit dd78759

Please sign in to comment.