Skip to content

Commit 64d8fd2

Browse files
author
Adam Bradley
committed
platform detect updates
1 parent 41a7b45 commit 64d8fd2

File tree

6 files changed

+51
-59
lines changed

6 files changed

+51
-59
lines changed

dist/js/ionic-angular.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,7 @@ angular.module('ionic.service.platform', [])
435435

436436
// We need to do some stuff as soon as we know the platform,
437437
// like adjust header margins for iOS 7, etc.
438-
setTimeout(function afterReadyWait() {
439-
if(isReady() && ionic.Platform.detect()) {
440-
return;
441-
} else {
442-
setTimeout(afterReadyWait, 50);
443-
}
444-
}, 10);
445-
446-
438+
ionic.Platform.detect();
447439

448440

449441
return {

dist/js/ionic-angular.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/ionic.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,27 +1737,34 @@ window.ionic = {
17371737
(function(ionic) {
17381738

17391739
ionic.Platform = {
1740-
detect: function() {
1741-
var platforms = [];
1742-
1743-
var didDetect = this._checkPlatforms(platforms);
17441740

1745-
var classify = function() {
1746-
if(!document.body) { return; }
1747-
1748-
for(var i = 0; i < platforms.length; i++) {
1749-
document.body.classList.add('platform-' + platforms[i]);
1741+
detect: function() {
1742+
1743+
var domReady = function() {
1744+
// run when the DOM is ready
1745+
document.addEventListener("deviceready", deviceReady, false);
1746+
document.removeEventListener("DOMContentLoaded", domReady, false);
1747+
};
1748+
document.addEventListener("DOMContentLoaded", domReady, false);
1749+
1750+
var deviceReady = function() {
1751+
// run when cordova is fully loaded
1752+
var platforms = [];
1753+
ionic.Platform._checkPlatforms(platforms);
1754+
1755+
if(platforms.length) {
1756+
// only change the body class if we got platform info
1757+
var bodyClass = document.body.className;
1758+
for(var i = 0; i < platforms.length; i++) {
1759+
bodyClass += ' platform-' + platforms[i];
1760+
}
1761+
document.body.className = bodyClass;
17501762
}
1763+
document.removeEventListener("deviceready", deviceReady, false);
17511764
};
17521765

1753-
document.addEventListener( "DOMContentLoaded", function(){
1754-
classify();
1755-
});
1756-
1757-
classify();
1758-
1759-
return didDetect;
17601766
},
1767+
17611768
_checkPlatforms: function(platforms) {
17621769
if(this.isCordova()) {
17631770
platforms.push('cordova');
@@ -1773,10 +1780,7 @@ window.ionic = {
17731780
}
17741781

17751782
// Return whether we detected anything
1776-
if(platforms.length === 0) {
1777-
return false;
1778-
}
1779-
return true;
1783+
return (platforms.length > 0);
17801784
},
17811785

17821786
// Check if we are running in Cordova, which will have

dist/js/ionic.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/ext/angular/src/service/ionicPlatform.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@ angular.module('ionic.service.platform', [])
2727

2828
// We need to do some stuff as soon as we know the platform,
2929
// like adjust header margins for iOS 7, etc.
30-
setTimeout(function afterReadyWait() {
31-
if(isReady() && ionic.Platform.detect()) {
32-
return;
33-
} else {
34-
setTimeout(afterReadyWait, 50);
35-
}
36-
}, 10);
37-
38-
30+
ionic.Platform.detect();
3931

4032

4133
return {

js/utils/platform.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
(function(ionic) {
22

33
ionic.Platform = {
4-
detect: function() {
5-
var platforms = [];
64

7-
var didDetect = this._checkPlatforms(platforms);
5+
detect: function() {
6+
7+
var domReady = function() {
8+
// run when the DOM is ready
9+
document.addEventListener("deviceready", deviceReady, false);
10+
document.removeEventListener("DOMContentLoaded", domReady, false);
11+
};
12+
document.addEventListener("DOMContentLoaded", domReady, false);
813

9-
var classify = function() {
10-
if(!document.body) { return; }
14+
var deviceReady = function() {
15+
// run when cordova is fully loaded
16+
var platforms = [];
17+
ionic.Platform._checkPlatforms(platforms);
1118

12-
for(var i = 0; i < platforms.length; i++) {
13-
document.body.classList.add('platform-' + platforms[i]);
19+
if(platforms.length) {
20+
// only change the body class if we got platform info
21+
var bodyClass = document.body.className;
22+
for(var i = 0; i < platforms.length; i++) {
23+
bodyClass += ' platform-' + platforms[i];
24+
}
25+
document.body.className = bodyClass;
1426
}
27+
document.removeEventListener("deviceready", deviceReady, false);
1528
};
1629

17-
document.addEventListener( "DOMContentLoaded", function(){
18-
classify();
19-
});
20-
21-
classify();
22-
23-
return didDetect;
2430
},
31+
2532
_checkPlatforms: function(platforms) {
2633
if(this.isCordova()) {
2734
platforms.push('cordova');
@@ -37,10 +44,7 @@
3744
}
3845

3946
// Return whether we detected anything
40-
if(platforms.length === 0) {
41-
return false;
42-
}
43-
return true;
47+
return (platforms.length > 0);
4448
},
4549

4650
// Check if we are running in Cordova, which will have

0 commit comments

Comments
 (0)