Skip to content

Commit 2add26a

Browse files
author
Adam Bradley
committed
readyCallbacks array and platform() method to get name
1 parent 95c8ddf commit 2add26a

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

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: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,23 +1817,32 @@ window.ionic = {
18171817
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
18181818
},
18191819
isIOS7: function() {
1820-
return this.platformName == 'iOS' && parseFloat(window.device.version) >= 7.0;
1820+
return this.platform() == 'ios' && this.version() >= 7.0;
18211821
},
18221822
isAndroid: function() {
1823-
return this.platformName === "Android";
1823+
return this.platform() === "android";
18241824
},
18251825

18261826
platform: function() {
1827-
if(!platformName) {
1828-
this.setPlatform(this.device().platform);
1829-
}
1827+
// singleton to get the platform name
1828+
if(!platformName) this.setPlatform(this.device().platform);
18301829
return platformName;
18311830
},
18321831

18331832
setPlatform: function(name) {
18341833
if(name) platformName = name.toLowerCase();
18351834
},
18361835

1836+
version: function() {
1837+
// singleton to get the platform version
1838+
if(!platformVersion) this.setVersion(this.device().version);
1839+
return platformVersion;
1840+
},
1841+
1842+
setVersion: function(v) {
1843+
if( !isNaN(v) ) version = parseFloat(v);
1844+
},
1845+
18371846
// Check if the platform is the one detected by cordova
18381847
is: function(type) {
18391848
var pName = this.platform();
@@ -1884,6 +1893,7 @@ window.ionic = {
18841893

18851894
var readyCallbacks = [];
18861895
var platformName;
1896+
var platformVersion;
18871897

18881898
// setup listeners to know when the device is ready to go
18891899
function onWindowLoad() {

dist/js/ionic.min.js

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

js/utils/platform.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
if(this.isReady) {
1212
cb();
1313
} else {
14-
ionic.on('platformready', cb, document);
14+
// the platform isn't ready yet, add it to this array
15+
// which will be called once the platform is ready
16+
readyCallbacks.push(cb);
1517
}
1618
},
1719

@@ -59,16 +61,37 @@
5961
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
6062
},
6163
isIOS7: function() {
62-
return this.device().platform == 'iOS' && parseFloat(window.device.version) >= 7.0;
64+
return this.platform() == 'ios' && this.version() >= 7.0;
6365
},
6466
isAndroid: function() {
65-
return this.device().platform === "Android";
67+
return this.platform() === "android";
68+
},
69+
70+
platform: function() {
71+
// singleton to get the platform name
72+
if(!platformName) this.setPlatform(this.device().platform);
73+
return platformName;
74+
},
75+
76+
setPlatform: function(name) {
77+
if(name) platformName = name.toLowerCase();
78+
},
79+
80+
version: function() {
81+
// singleton to get the platform version
82+
if(!platformVersion) this.setVersion(this.device().version);
83+
return platformVersion;
84+
},
85+
86+
setVersion: function(v) {
87+
if( !isNaN(v) ) version = parseFloat(v);
6688
},
6789

6890
// Check if the platform is the one detected by cordova
6991
is: function(type) {
70-
if(this.device.platform) {
71-
return window.device.platform.toLowerCase() === type.toLowerCase();
92+
var pName = this.platform();
93+
if(pName) {
94+
return pName === type.toLowerCase();
7295
}
7396
// A quick hack for
7497
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
@@ -112,6 +135,9 @@
112135

113136
};
114137

138+
var readyCallbacks = [];
139+
var platformName;
140+
var platformVersion;
115141

116142
// setup listeners to know when the device is ready to go
117143
function onWindowLoad() {
@@ -125,6 +151,11 @@
125151
// the device is all set to go, init our own stuff then fire off our event
126152
ionic.Platform.isReady = true;
127153
ionic.Platform.detect();
154+
for(var x=0; x<readyCallbacks.length; x++) {
155+
// fire off all the callbacks that were added before the platform was ready
156+
readyCallbacks[x]();
157+
}
158+
readyCallbacks = [];
128159
ionic.trigger('platformready', { target: document });
129160
document.removeEventListener("deviceready", onCordovaReady, false);
130161
}

0 commit comments

Comments
 (0)