fix(platform): Update ionic.Platform.is() to check all platforms, closes #604

This commit is contained in:
Adam Bradley
2014-02-23 21:58:17 -06:00
parent 1a0213e250
commit fcd0fa73c4
2 changed files with 35 additions and 7 deletions

View File

@@ -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() {
@@ -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');
@@ -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);
});
});

View File

@@ -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');
@@ -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() {