From b69b40c82684acf3003f19277a44caf4614c75e4 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Thu, 20 Feb 2014 20:41:48 -0600 Subject: [PATCH] feat(grade): Set grade in body class depending on platform performance First draft of how devices play out: .grade-a: - iOS - >= Android 4.4 .grade-b: - Android >= 4 && < 4.4 .grade-c: - Android < 4 --- .../test/service/ionicPlatform.unit.js | 72 +++++++++++++++++++ js/utils/platform.js | 22 ++++-- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/js/ext/angular/test/service/ionicPlatform.unit.js b/js/ext/angular/test/service/ionicPlatform.unit.js index 9d266e95158..25cf4cdf94a 100644 --- a/js/ext/angular/test/service/ionicPlatform.unit.js +++ b/js/ext/angular/test/service/ionicPlatform.unit.js @@ -108,6 +108,78 @@ describe('Ionic Platform Service', function() { expect(ionic.Platform.platforms[3]).toEqual('android4_2'); }); + it('sets grade a from iOS7', function() { + window.cordova = {}; + ionic.Platform.setPlatform('iOS'); + ionic.Platform.setVersion('7.1.1'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('a'); + }); + + it('sets grade a from iOS6', function() { + window.cordova = {}; + ionic.Platform.setPlatform('iOS'); + ionic.Platform.setVersion('6.1.1'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('a'); + }); + + it('sets grade a from Android 4.4', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('4.4.1'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('a'); + }); + + it('sets grade b from Android 4.3', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('4.3.1'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('b'); + }); + + it('sets grade b from Android 4.0', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('4.0.0'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('b'); + }); + + it('sets grade c from Android 3.0', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('3.0.0'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('c'); + }); + + it('sets grade c from Android 2.3.4', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('2.3.4'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('c'); + }); + + it('sets grade a from unknown android version', function() { + window.cordova = {}; + ionic.Platform.setPlatform('android'); + ionic.Platform.setVersion('0'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('a'); + }); + + it('sets grade a from unknown platform', function() { + window.cordova = {}; + ionic.Platform.setPlatform('whatever'); + ionic.Platform.setVersion('20.3.4'); + ionic.Platform._checkPlatforms() + expect(ionic.Platform.grade).toEqual('a'); + }); + it('is android', function() { ionic.Platform.setPlatform('AnDrOiD'); expect(ionic.Platform.is('android')).toEqual(true); diff --git a/js/utils/platform.js b/js/utils/platform.js index 0bf477c8975..b7d6d964609 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -5,6 +5,7 @@ isReady: false, isFullScreen: false, platforms: null, + grade: null, ready: function(cb) { // run through tasks to complete now that the device is ready @@ -18,16 +19,18 @@ }, detect: function() { + var i, bodyClass = document.body.className; + ionic.Platform._checkPlatforms(); - if(this.platforms.length) { - // only change the body class if we got platform info - var i, bodyClass = document.body.className; - for(i = 0; i < this.platforms.length; i++) { - bodyClass += ' platform-' + this.platforms[i]; - } - document.body.className = bodyClass; + // only change the body class if we got platform info + for(i = 0; i < this.platforms.length; i++) { + bodyClass += ' platform-' + this.platforms[i]; } + + bodyClass += ' grade-' + this.grade; + + document.body.className = bodyClass.trim(); }, device: function() { @@ -38,6 +41,7 @@ _checkPlatforms: function(platforms) { this.platforms = []; + this.grade = 'a'; var v = this.version().toString().replace('.', '_'); if(this.isCordova()) { @@ -55,6 +59,10 @@ this.platforms.push('android'); this.platforms.push('android' + v.split('_')[0]); this.platforms.push('android' + v); + + if(platformVersion > 0 && platformVersion < 4.4) { + this.grade = (platformVersion < 4 ? 'c' : 'b'); + } } },