diff --git a/js/utils/platform.js b/js/utils/platform.js index 5af319faef6..9c7694124ed 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -1,5 +1,9 @@ (function(window, document, ionic) { + var IOS = 'ios'; + var ANDROID = 'android'; + var WINDOWS_PHONE = 'windowsphone'; + /** * @ngdoc utility * @name ionic.Platform @@ -142,7 +146,7 @@ * @returns {boolean} Whether we are running on iOS. */ isIOS: function() { - return this.is('ios'); + return this.is(IOS); }, /** * @ngdoc method @@ -150,7 +154,15 @@ * @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); }, /** @@ -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] || ''; } }, @@ -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] ); diff --git a/test/unit/angular/service/platform.unit.js b/test/unit/angular/service/platform.unit.js index 762bcb9bd07..918381ed2bd 100644 --- a/test/unit/angular/service/platform.unit.js +++ b/test/unit/angular/service/platform.unit.js @@ -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); diff --git a/test/unit/utils/tap.unit.js b/test/unit/utils/tap.unit.js index f24dac85904..889f862e141 100644 --- a/test/unit/utils/tap.unit.js +++ b/test/unit/utils/tap.unit.js @@ -82,7 +82,7 @@ Tested on: */ -window.console.debug = function(){}; +window.console.log = function(){}; describe('Ionic Tap', function() { var deregisterTap;