readyCallbacks array and platform() method to get name

This commit is contained in:
Adam Bradley
2014-01-31 10:45:31 -06:00
parent 95c8ddf301
commit 2add26afbb
4 changed files with 55 additions and 14 deletions

View File

File diff suppressed because one or more lines are too long

20
dist/js/ionic.js vendored
View File

@@ -1817,16 +1817,15 @@ window.ionic = {
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
},
isIOS7: function() {
return this.platformName == 'iOS' && parseFloat(window.device.version) >= 7.0;
return this.platform() == 'ios' && this.version() >= 7.0;
},
isAndroid: function() {
return this.platformName === "Android";
return this.platform() === "android";
},
platform: function() {
if(!platformName) {
this.setPlatform(this.device().platform);
}
// singleton to get the platform name
if(!platformName) this.setPlatform(this.device().platform);
return platformName;
},
@@ -1834,6 +1833,16 @@ window.ionic = {
if(name) platformName = name.toLowerCase();
},
version: function() {
// singleton to get the platform version
if(!platformVersion) this.setVersion(this.device().version);
return platformVersion;
},
setVersion: function(v) {
if( !isNaN(v) ) version = parseFloat(v);
},
// Check if the platform is the one detected by cordova
is: function(type) {
var pName = this.platform();
@@ -1884,6 +1893,7 @@ window.ionic = {
var readyCallbacks = [];
var platformName;
var platformVersion;
// setup listeners to know when the device is ready to go
function onWindowLoad() {

View File

File diff suppressed because one or more lines are too long

View File

@@ -11,7 +11,9 @@
if(this.isReady) {
cb();
} else {
ionic.on('platformready', cb, document);
// the platform isn't ready yet, add it to this array
// which will be called once the platform is ready
readyCallbacks.push(cb);
}
},
@@ -59,16 +61,37 @@
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
},
isIOS7: function() {
return this.device().platform == 'iOS' && parseFloat(window.device.version) >= 7.0;
return this.platform() == 'ios' && this.version() >= 7.0;
},
isAndroid: function() {
return this.device().platform === "Android";
return this.platform() === "android";
},
platform: function() {
// singleton to get the platform name
if(!platformName) this.setPlatform(this.device().platform);
return platformName;
},
setPlatform: function(name) {
if(name) platformName = name.toLowerCase();
},
version: function() {
// singleton to get the platform version
if(!platformVersion) this.setVersion(this.device().version);
return platformVersion;
},
setVersion: function(v) {
if( !isNaN(v) ) version = parseFloat(v);
},
// Check if the platform is the one detected by cordova
is: function(type) {
if(this.device.platform) {
return window.device.platform.toLowerCase() === type.toLowerCase();
var pName = this.platform();
if(pName) {
return pName === type.toLowerCase();
}
// A quick hack for
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
@@ -112,6 +135,9 @@
};
var readyCallbacks = [];
var platformName;
var platformVersion;
// setup listeners to know when the device is ready to go
function onWindowLoad() {
@@ -125,6 +151,11 @@
// the device is all set to go, init our own stuff then fire off our event
ionic.Platform.isReady = true;
ionic.Platform.detect();
for(var x=0; x<readyCallbacks.length; x++) {
// fire off all the callbacks that were added before the platform was ready
readyCallbacks[x]();
}
readyCallbacks = [];
ionic.trigger('platformready', { target: document });
document.removeEventListener("deviceready", onCordovaReady, false);
}