Skip to content

Commit

Permalink
feat(ionic.Platform): add ionic.Platform.setGrade() function
Browse files Browse the repository at this point in the history
Closes #1104
  • Loading branch information
ajoslin committed Jun 11, 2014
1 parent a034561 commit 05dd7b1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions js/utils/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},

Expand All @@ -89,7 +107,7 @@

_checkPlatforms: function(platforms) {
this.platforms = [];
this.grade = 'a';
var grade = 'a';

if(this.isWebView()) {
this.platforms.push('webview');
Expand All @@ -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);
},

/**
Expand Down

0 comments on commit 05dd7b1

Please sign in to comment.