-
Notifications
You must be signed in to change notification settings - Fork 22
/
angular-adaptive-detection.js
135 lines (125 loc) · 3.42 KB
/
angular-adaptive-detection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
(function () {
'use strict';
/**
* @ngdoc overview
* @name adaptive.detection
*
* @description
* The main module which holds everything together.
*/
var adaptive = angular.module('adaptive.detection', []);
/**
* @ngdoc object
* @name adaptive.detection.$detectionProvider
*
* @description
* The `$detectionProvider` provides an interface to configure `$detection service for
* runtime.
*/
adaptive.provider('$detection', [function() {
this.userAgent = navigator.userAgent;
/**
* @ngdoc function
* @name adaptive.detection.$detectionProvider#setUserAgent
* @methodOf adaptive.detection.$detectionProvider
*
* @description
* Let's you configure a custom User Agent string during your apps configuration.
*
* <pre>
* var app = angular.module('myApp', ['adaptive.detection']);
*
* app.config(['$detectionProvider', function ($detectionProvider) {
* // sets custom User Agent
* $detectionProvider.setUserAgent('angular browser');
* }]);
* </pre>
*
* @param {string} Custom User Agent string
*/
this.setUserAgent = function(userAgent) {
this.userAgent = userAgent;
};
/**
* @ngdoc object
* @name adaptive.detection.$detection
*
* @description
* The `$detection` service can be injected anywhere in your app during runtime like
* every other service. It provides methods to detect wheter a the current client is
* for example and iOS device or an Android device.
*
* You are also able to retreive the current User Agent using this service.
*/
this.$get = function() {
var userAgent = this.userAgent;
return {
/**
* @ngdoc function
* @name adaptive.detection.$detection#getUserAgent
* @methodOf adaptive.detection.$detection
*
* @description
* Returns the current User Agent which was set with `$detectionProvider.setUserAgent'.
*
* @return {string} userAgent
*/
getUserAgent: function(){
return userAgent;
},
/**
* @ngdoc function
* @name adaptive.detection.$detection#isiOS
* @methodOf adaptive.detection.$detection
*
* @description
* Returns true if current device is an iOS device.
*
* @return {bool}
*/
isiOS: function(){
return (/(iPad|iPhone|iPod)/gi).test(userAgent);
},
/**
* @ngdoc function
* @name adaptive.detection.$detection#isAndroid
* @methodOf adaptive.detection.$detection
*
* @description
* Returns true if current device is an Android device.
*
* @return {bool}
*/
isAndroid: function(){
return (/(Android)/gi).test(userAgent);
},
/**
* @ngdoc function
* @name adaptive.detection.$detection#isWindowsPhone
* @methodOf adaptive.detection.$detection
*
* @description
* Returns true if current device is a Windows Phone device.
*
* @return {bool}
*/
isWindowsPhone: function(){
return (/(IEMobile)/gi).test(userAgent);
},
/**
* @ngdoc function
* @name adaptive.detection.$detection#isBB10
* @methodOf adaptive.detection.$detection
*
* @description
* Returns true if current device is a BlackBerry 10 device.
*
* @return {bool}
*/
isBB10: function(){
return (/(BB10)/gi).test(userAgent);
}
};
};
}]);
})();