From 05dd7b18646a532f2f688642439f744e8db2369e Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Wed, 11 Jun 2014 11:14:15 -0600 Subject: [PATCH] feat(ionic.Platform): add ionic.Platform.setGrade() function Closes #1104 --- js/utils/platform.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/js/utils/platform.js b/js/utils/platform.js index 2ebf2781f8..c23c700487 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -71,7 +71,25 @@ for(var i = 0; i < ionic.Platform.platforms.length; i++) { document.body.classList.add('platform-' + ionic.Platform.platforms[i]); } - document.body.classList.add('grade-' + ionic.Platform.grade); + }); + }, + + /** + * @ngdoc method + * @name ionic.Platform#setGrade + * @description Set the grade of the device: 'a', 'b', or 'c'. 'a' is the best + * (most css features enabled), 'c' is the worst. By default, sets the grade + * depending on the current device. + * @param {string} grade The new grade to set. + */ + setGrade: function(grade) { + var oldGrade = this.grade; + this.grade = grade; + ionic.requestAnimationFrame(function() { + if (oldGrade) { + document.body.classList.remove('grade-' + oldGrade); + } + document.body.classList.add('grade-' + grade); }); }, @@ -89,7 +107,7 @@ _checkPlatforms: function(platforms) { this.platforms = []; - this.grade = 'a'; + var grade = 'a'; if(this.isWebView()) { this.platforms.push('webview'); @@ -115,12 +133,14 @@ this.platforms.push(platform + v); if(this.isAndroid() && version < 4.4) { - this.grade = (version < 4 ? 'c' : 'b'); + grade = (version < 4 ? 'c' : 'b'); } else if(this.isWindowsPhone()) { - this.grade = 'b'; + grade = 'b'; } } } + + this.setGrade(grade); }, /**