Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Add isMobile filter #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "5"
- "4"
- "8"
- "6"
env:
- CXX=g++-4.8
addons:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ angular.module('myApp').controller('someController', ['isMobile', function(isMob
}]);
```

## Usage Filter

```html
<p data-ng-if="('phone' | isMobile)">This is a phone header</p>
```

## Contributing
Please create an issue. If you add a pull request, try to respect my code style, check for JSHint and assure the unit tests do pass, and extend them if necessary!
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "angular-ismobile",
"version": "1.0.0",
"version": "1.3.0",
"description": "A Angular wrapper provider-service for isMobile (https://github.com/kaimallea/isMobile)",
"homepage": "https://github.com/ronnyhaase/angular-ismobile",
"authors": [
"Ronny Haase <ronhaase@gmail.com>"
"Ronny Haase <ronhaase@gmail.com>",
"Auban le Grelle <auban@viamonkey.com>"
],
"license": "CC0-1.0",
"keywords": [
Expand Down
258 changes: 136 additions & 122 deletions dist/angular-ismobile.js
Original file line number Diff line number Diff line change
@@ -1,128 +1,133 @@
/**
* isMobile.js v0.3.9
*
* A simple library to detect Apple phones and tablets,
* Android phones and tablets, other mobile devices (like blackberry, mini-opera and windows phone),
* and any kind of seven inch device, via user agent sniffing.
*
* @author: Kai Mallea (kmallea@gmail.com)
*
* @license: http://creativecommons.org/publicdomain/zero/1.0/
*/
(function (global) {

var apple_phone = /iPhone/i,
apple_ipod = /iPod/i,
apple_tablet = /iPad/i,
android_phone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i, // Match 'Android' AND 'Mobile'
android_tablet = /Android/i,
amazon_phone = /(?=.*\bAndroid\b)(?=.*\bSD4930UR\b)/i,
amazon_tablet = /(?=.*\bAndroid\b)(?=.*\b(?:KFOT|KFTT|KFJWI|KFJWA|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|KFARWI|KFASWI|KFSAWI|KFSAWA)\b)/i,
windows_phone = /IEMobile/i,
windows_tablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i, // Match 'Windows' AND 'ARM'
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

'Nexus 7' + // Nexus 7

'|' + // OR

'BNTV250' + // B&N Nook Tablet 7 inch

'|' + // OR

'Kindle Fire' + // Kindle Fire

'|' + // OR

'Silk' + // Kindle Fire, Silk Accelerated

'|' + // OR

'GT-P1000' + // Galaxy Tab 7 inch

')', // End non-capturing group

'i'); // Case-insensitive matching

var match = function(regex, userAgent) {
return regex.test(userAgent);
};

var IsMobileClass = function(userAgent) {
var ua = userAgent || navigator.userAgent;
// Facebook mobile app's integrated browser adds a bunch of strings that
// match everything. Strip it out if it exists.
var tmp = ua.split('[FBAN');
if (typeof tmp[1] !== 'undefined') {
ua = tmp[0];
}

this.apple = {
phone: match(apple_phone, ua),
ipod: match(apple_ipod, ua),
tablet: !match(apple_phone, ua) && match(apple_tablet, ua),
device: match(apple_phone, ua) || match(apple_ipod, ua) || match(apple_tablet, ua)
};
this.amazon = {
phone: match(amazon_phone, ua),
tablet: !match(amazon_phone, ua) && match(amazon_tablet, ua),
device: match(amazon_phone, ua) || match(amazon_tablet, ua)
};
this.android = {
phone: match(amazon_phone, ua) || match(android_phone, ua),
tablet: !match(amazon_phone, ua) && !match(android_phone, ua) && (match(amazon_tablet, ua) || match(android_tablet, ua)),
device: match(amazon_phone, ua) || match(amazon_tablet, ua) || match(android_phone, ua) || match(android_tablet, ua)
};
this.windows = {
phone: match(windows_phone, ua),
tablet: match(windows_tablet, ua),
device: match(windows_phone, ua) || match(windows_tablet, ua)
};
this.other = {
blackberry: match(other_blackberry, ua),
blackberry10: match(other_blackberry_10, ua),
opera: match(other_opera, ua),
firefox: 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;
// excludes 'other' devices and ipods, targeting touchscreen phones
this.phone = this.apple.phone || this.android.phone || this.windows.phone;
// excludes 7 inch devices, classifying as phone or tablet is left to the user
this.tablet = this.apple.tablet || this.android.tablet || this.windows.tablet;

if (typeof window === 'undefined') {
return this;
}
};

var instantiate = function() {
var IM = new IsMobileClass();
IM.Class = IsMobileClass;
return IM;
};
(function(global) {
var apple_phone = /iPhone/i,
apple_ipod = /iPod/i,
apple_tablet = /iPad/i,
android_phone = /\bAndroid(?:.+)Mobile\b/i, // Match 'Android' AND 'Mobile'
android_tablet = /Android/i,
amazon_phone = /\bAndroid(?:.+)SD4930UR\b/i,
amazon_tablet = /\bAndroid(?:.+)(?:KF[A-Z]{2,4})\b/i,
windows_phone = /Windows Phone/i,
windows_tablet = /\bWindows(?:.+)ARM\b/i, // Match 'Windows' AND 'ARM'
other_blackberry = /BlackBerry/i,
other_blackberry_10 = /BB10/i,
other_opera = /Opera Mini/i,
other_chrome = /\b(CriOS|Chrome)(?:.+)Mobile/i,
other_firefox = /Mobile(?:.+)Firefox\b/i; // Match 'Mobile' AND 'Firefox'

function match(regex, userAgent) {
return regex.test(userAgent);
}

function isMobile(userAgent) {
var ua =
userAgent ||
(typeof navigator !== 'undefined' ? navigator.userAgent : '');

// Facebook mobile app's integrated browser adds a bunch of strings that
// match everything. Strip it out if it exists.
var tmp = ua.split('[FBAN');
if (typeof tmp[1] !== 'undefined') {
ua = tmp[0];
}

if (typeof module != 'undefined' && module.exports && typeof window === 'undefined') {
//node
module.exports = IsMobileClass;
} else if (typeof module != 'undefined' && module.exports && typeof window !== 'undefined') {
//browserify
module.exports = instantiate();
} else if (typeof define === 'function' && define.amd) {
//AMD
define('isMobile', [], global.isMobile = instantiate());
} else {
global.isMobile = instantiate();
// Twitter mobile app's integrated browser on iPad adds a "Twitter for
// iPhone" string. Same probably happens on other tablet platforms.
// This will confuse detection so strip it out if it exists.
tmp = ua.split('Twitter');
if (typeof tmp[1] !== 'undefined') {
ua = tmp[0];
}

var result = {
apple: {
phone: match(apple_phone, ua) && !match(windows_phone, ua),
ipod: match(apple_ipod, ua),
tablet:
!match(apple_phone, ua) &&
match(apple_tablet, ua) &&
!match(windows_phone, ua),
device:
(match(apple_phone, ua) ||
match(apple_ipod, ua) ||
match(apple_tablet, ua)) &&
!match(windows_phone, ua)
},
amazon: {
phone: match(amazon_phone, ua),
tablet: !match(amazon_phone, ua) && match(amazon_tablet, ua),
device: match(amazon_phone, ua) || match(amazon_tablet, ua)
},
android: {
phone:
(!match(windows_phone, ua) && match(amazon_phone, ua)) ||
(!match(windows_phone, ua) && match(android_phone, ua)),
tablet:
!match(windows_phone, ua) &&
!match(amazon_phone, ua) &&
!match(android_phone, ua) &&
(match(amazon_tablet, ua) || match(android_tablet, ua)),
device:
(!match(windows_phone, ua) &&
(match(amazon_phone, ua) ||
match(amazon_tablet, ua) ||
match(android_phone, ua) ||
match(android_tablet, ua))) ||
match(/\bokhttp\b/i, ua)
},
windows: {
phone: match(windows_phone, ua),
tablet: match(windows_tablet, ua),
device: match(windows_phone, ua) || match(windows_tablet, ua)
},
other: {
blackberry: match(other_blackberry, ua),
blackberry10: match(other_blackberry_10, ua),
opera: match(other_opera, ua),
firefox: 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)
}
};
(result.any =
result.apple.device ||
result.android.device ||
result.windows.device ||
result.other.device),
// excludes 'other' devices and ipods, targeting touchscreen phones
(result.phone =
result.apple.phone || result.android.phone || result.windows.phone),
(result.tablet =
result.apple.tablet || result.android.tablet || result.windows.tablet);

return result;
}

if (
typeof module !== 'undefined' &&
module.exports &&
typeof window === 'undefined'
) {
// Node.js
module.exports = isMobile;
} else if (
typeof module !== 'undefined' &&
module.exports &&
typeof window !== 'undefined'
) {
// Browserify
module.exports = isMobile();
module.exports.isMobile = isMobile;
} else if (typeof define === 'function' && define.amd) {
// AMD
define([], (global.isMobile = isMobile()));
} else {
global.isMobile = isMobile();
}
})(this);


Expand All @@ -147,4 +152,13 @@
return angular.copy(_window.isMobile);
}];
}]);


angular.module('ismobile').filter('isMobile', ['isMobile', function(isMobile) {

return function( device ) {

return isMobile[device];
};
}]);
})();
33 changes: 1 addition & 32 deletions dist/angular-ismobile.min.js

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