Skip to content

Commit 08e4b3d

Browse files
author
Adam Bradley
committed
feat(platform): added isWindowsPhone() method
1 parent 25c02a3 commit 08e4b3d

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

Diff for: js/utils/platform.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
(function(window, document, ionic) {
22

3+
var IOS = 'ios';
4+
var ANDROID = 'android';
5+
var WINDOWS_PHONE = 'windowsphone';
6+
37
/**
48
* @ngdoc utility
59
* @name ionic.Platform
@@ -142,15 +146,23 @@
142146
* @returns {boolean} Whether we are running on iOS.
143147
*/
144148
isIOS: function() {
145-
return this.is('ios');
149+
return this.is(IOS);
146150
},
147151
/**
148152
* @ngdoc method
149153
* @name ionic.Platform#isAndroid
150154
* @returns {boolean} Whether we are running on Android.
151155
*/
152156
isAndroid: function() {
153-
return this.is('android');
157+
return this.is(ANDROID);
158+
},
159+
/**
160+
* @ngdoc method
161+
* @name ionic.Platform#isWindowsPhone
162+
* @returns {boolean} Whether we are running on Windows Phone.
163+
*/
164+
isWindowsPhone: function() {
165+
return this.is(WINDOWS_PHONE);
154166
},
155167

156168
/**
@@ -171,11 +183,13 @@
171183
if(typeof n != 'undefined' && n !== null && n.length) {
172184
platformName = n.toLowerCase();
173185
} else if(this.ua.indexOf('Android') > 0) {
174-
platformName = 'android';
186+
platformName = ANDROID;
175187
} else if(this.ua.indexOf('iPhone') > -1 || this.ua.indexOf('iPad') > -1 || this.ua.indexOf('iPod') > -1) {
176-
platformName = 'ios';
188+
platformName = IOS;
189+
} else if(this.ua.indexOf('Windows Phone') > -1) {
190+
platformName = WINDOWS_PHONE;
177191
} else {
178-
platformName = window.navigator.platform && window.navigator.platform.toLowerCase().split(' ')[0] || '';
192+
platformName = window.navigator.platform && navigator.platform.toLowerCase().split(' ')[0] || '';
179193
}
180194
},
181195

@@ -209,7 +223,8 @@
209223
var pName = this.platform();
210224
var versionMatch = {
211225
'android': /Android (\d+).(\d+)?/,
212-
'ios': /OS (\d+)_(\d+)?/
226+
'ios': /OS (\d+)_(\d+)?/,
227+
'windowsphone': /Windows Phone (\d+).(\d+)?/
213228
};
214229
if(versionMatch[pName]) {
215230
v = this.ua.match( versionMatch[pName] );

Diff for: test/unit/angular/service/platform.unit.js

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ describe('Ionic Platform Service', function() {
7171
expect(ionic.Platform.version()).toEqual(2.2);
7272
});
7373

74+
it('set windowsphone with user agent', function() {
75+
ionic.Platform.ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch;';
76+
ionic.Platform.setPlatform(undefined);
77+
ionic.Platform.setVersion(undefined);
78+
expect(ionic.Platform.platform()).toEqual('windowsphone');
79+
expect(ionic.Platform.version()).toEqual(8);
80+
});
81+
7482
it('set ios with iPhone user agent', function() {
7583
ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';
7684
ionic.Platform.setPlatform(undefined);

Diff for: test/unit/utils/tap.unit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Tested on:
8282
8383
*/
8484

85-
window.console.debug = function(){};
85+
window.console.log = function(){};
8686

8787
describe('Ionic Tap', function() {
8888
var deregisterTap;

0 commit comments

Comments
 (0)