Skip to content

Commit

Permalink
fix(platform): Update ionic.Platform.is() to check all platforms, closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Bradley committed Feb 24, 2014
1 parent 1a0213e commit fcd0fa7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
19 changes: 16 additions & 3 deletions js/ext/angular/test/service/ionicPlatform.unit.js
Expand Up @@ -85,14 +85,14 @@ describe('Ionic Platform Service', function() {
it('sets ios platforms', function() {
window.cordova = {};
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.9.3');
ionic.Platform.setVersion('7.0.3');

ionic.Platform._checkPlatforms()

expect(ionic.Platform.platforms[0]).toEqual('cordova');
expect(ionic.Platform.platforms[1]).toEqual('ios');
expect(ionic.Platform.platforms[2]).toEqual('ios7');
expect(ionic.Platform.platforms[3]).toEqual('ios7_9');
expect(ionic.Platform.platforms[3]).toEqual('ios7_0');
});

it('sets android platforms', function() {
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.is('android')).toEqual(false);
});

it('is android', function() {
it('is iOS', function() {
ionic.Platform.setPlatform('iOs');
expect(ionic.Platform.is('ios')).toEqual(true);
ionic.Platform.setPlatform('iOs');
Expand All @@ -202,4 +202,17 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.is('android')).toEqual(false);
});

it('should be all platforms for ios', function() {
window.cordova = {};
ionic.Platform.setPlatform('iOS');
ionic.Platform.setVersion('7.1.4');
ionic.Platform._checkPlatforms();

expect(ionic.Platform.is('ios')).toEqual(true);
expect(ionic.Platform.is('ios7')).toEqual(true);
expect(ionic.Platform.is('ios7_1')).toEqual(true);
expect(ionic.Platform.is('cordova')).toEqual(true);
expect(ionic.Platform.is('android')).toEqual(false);
});

});
23 changes: 19 additions & 4 deletions js/utils/platform.js
Expand Up @@ -42,7 +42,13 @@
_checkPlatforms: function(platforms) {
this.platforms = [];
this.grade = 'a';
var v = this.version().toString().replace('.', '_');

var v = this.version().toString();
if(v.indexOf('.') > 0) {
v = v.replace('.', '_');
} else {
v += '_0';
}

if(this.isCordova()) {
this.platforms.push('cordova');
Expand Down Expand Up @@ -107,12 +113,21 @@

// Check if the platform is the one detected by cordova
is: function(type) {
type = type.toLowerCase();
// check if it has an array of platforms
if(this.platforms) {
for(var x = 0; x < this.platforms.length; x++) {
if(this.platforms[x] === type) return true;
}
}
// exact match
var pName = this.platform();
if(pName) {
return pName.toLowerCase() === type.toLowerCase();
return pName.toLowerCase() === type;
}
// A quick hack for
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;

// A quick hack for to check userAgent
return navigator.userAgent.toLowerCase().indexOf(type) >= 0;
},

exitApp: function() {
Expand Down

0 comments on commit fcd0fa7

Please sign in to comment.