Skip to content

Commit

Permalink
feat(platform): added isWindowsPhone() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bradley committed May 7, 2014
1 parent 25c02a3 commit 08e4b3d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
27 changes: 21 additions & 6 deletions js/utils/platform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
(function(window, document, ionic) {

var IOS = 'ios';
var ANDROID = 'android';
var WINDOWS_PHONE = 'windowsphone';

/**
* @ngdoc utility
* @name ionic.Platform
Expand Down Expand Up @@ -142,15 +146,23 @@
* @returns {boolean} Whether we are running on iOS.
*/
isIOS: function() {
return this.is('ios');
return this.is(IOS);
},
/**
* @ngdoc method
* @name ionic.Platform#isAndroid
* @returns {boolean} Whether we are running on Android.
*/
isAndroid: function() {
return this.is('android');
return this.is(ANDROID);
},
/**
* @ngdoc method
* @name ionic.Platform#isWindowsPhone
* @returns {boolean} Whether we are running on Windows Phone.
*/
isWindowsPhone: function() {
return this.is(WINDOWS_PHONE);
},

/**
Expand All @@ -171,11 +183,13 @@
if(typeof n != 'undefined' && n !== null && n.length) {
platformName = n.toLowerCase();
} else if(this.ua.indexOf('Android') > 0) {
platformName = 'android';
platformName = ANDROID;
} else if(this.ua.indexOf('iPhone') > -1 || this.ua.indexOf('iPad') > -1 || this.ua.indexOf('iPod') > -1) {
platformName = 'ios';
platformName = IOS;
} else if(this.ua.indexOf('Windows Phone') > -1) {
platformName = WINDOWS_PHONE;
} else {
platformName = window.navigator.platform && window.navigator.platform.toLowerCase().split(' ')[0] || '';
platformName = window.navigator.platform && navigator.platform.toLowerCase().split(' ')[0] || '';
}
},

Expand Down Expand Up @@ -209,7 +223,8 @@
var pName = this.platform();
var versionMatch = {
'android': /Android (\d+).(\d+)?/,
'ios': /OS (\d+)_(\d+)?/
'ios': /OS (\d+)_(\d+)?/,
'windowsphone': /Windows Phone (\d+).(\d+)?/
};
if(versionMatch[pName]) {
v = this.ua.match( versionMatch[pName] );
Expand Down
8 changes: 8 additions & 0 deletions test/unit/angular/service/platform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.version()).toEqual(2.2);
});

it('set windowsphone with user agent', function() {
ionic.Platform.ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch;';
ionic.Platform.setPlatform(undefined);
ionic.Platform.setVersion(undefined);
expect(ionic.Platform.platform()).toEqual('windowsphone');
expect(ionic.Platform.version()).toEqual(8);
});

it('set ios with iPhone user agent', function() {
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';
ionic.Platform.setPlatform(undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/utils/tap.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Tested on:
*/

window.console.debug = function(){};
window.console.log = function(){};

describe('Ionic Tap', function() {
var deregisterTap;
Expand Down

0 comments on commit 08e4b3d

Please sign in to comment.