Update $ionicPlatform.ready()

This commit is contained in:
Adam Bradley
2014-01-31 10:31:42 -06:00
parent 4d26f730bc
commit 95c8ddf301
8 changed files with 50 additions and 50 deletions

View File

@@ -2,6 +2,8 @@
## 0.9.23-alpha (pre-release)
- Android back button correctly goes back a view or closes the app
- CustomEvent polyfill improvements for Android
- Fix tab icon alignments
- Fix $ionicPlatform.ready()
## 0.9.22 "Alpha Narwhal" (2014-01-30)

View File

@@ -483,10 +483,7 @@ angular.module('ionic.service.platform', [])
.provider('$ionicPlatform', function() {
return {
setPlatform: function(p) {
platform = p;
},
$get: ['$q', '$timeout', function($q, $timeout) {
$get: ['$q', function($q) {
return {
/**
* Some platforms have hardware back buttons, so this is one way to bind to it.
@@ -519,17 +516,12 @@ angular.module('ionic.service.platform', [])
* ready.
*/
ready: function(cb) {
var self = this;
var q = $q.defer();
$timeout(function readyWait() {
if(ionic.Platform.isReady) {
q.resolve();
cb();
} else {
$timeout(readyWait, 50);
}
}, 50);
ionic.Platform.ready(function(){
q.resolve();
cb();
});
return q.promise;
}
@@ -621,7 +613,7 @@ angular.module('ionic.service.templateLoad', [])
};
}]);
;
angular.module('ionic.service.view', ['ui.router'])
angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
@@ -1290,7 +1282,7 @@ angular.module('ionic.ui.checkbox', [])
(function() {
'use strict';
angular.module('ionic.ui.content', ['ionic.ui.service'])
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
/**
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be

31
dist/js/ionic.js vendored
View File

@@ -1767,7 +1767,9 @@ window.ionic = {
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);
}
},
@@ -1815,16 +1817,28 @@ window.ionic = {
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
},
isIOS7: function() {
return this.device().platform == 'iOS' && parseFloat(window.device.version) >= 7.0;
return this.platformName == 'iOS' && parseFloat(window.device.version) >= 7.0;
},
isAndroid: function() {
return this.device().platform === "Android";
return this.platformName === "Android";
},
platform: function() {
if(!platformName) {
this.setPlatform(this.device().platform);
}
return platformName;
},
setPlatform: function(name) {
if(name) platformName = name.toLowerCase();
},
// 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;
@@ -1868,6 +1882,8 @@ window.ionic = {
};
var readyCallbacks = [];
var platformName;
// setup listeners to know when the device is ready to go
function onWindowLoad() {
@@ -1881,6 +1897,11 @@ window.ionic = {
// 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);
}

View File

@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('ionic.ui.content', ['ionic.ui.service'])
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
/**
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be

View File

@@ -12,10 +12,7 @@ angular.module('ionic.service.platform', [])
.provider('$ionicPlatform', function() {
return {
setPlatform: function(p) {
platform = p;
},
$get: ['$q', '$timeout', function($q, $timeout) {
$get: ['$q', function($q) {
return {
/**
* Some platforms have hardware back buttons, so this is one way to bind to it.
@@ -48,17 +45,12 @@ angular.module('ionic.service.platform', [])
* ready.
*/
ready: function(cb) {
var self = this;
var q = $q.defer();
$timeout(function readyWait() {
if(ionic.Platform.isReady) {
q.resolve();
cb();
} else {
$timeout(readyWait, 50);
}
}, 50);
ionic.Platform.ready(function(){
q.resolve();
cb();
});
return q.promise;
}

View File

@@ -1,4 +1,4 @@
angular.module('ionic.service.view', ['ui.router'])
angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',

View File

@@ -1,21 +1,14 @@
describe('Ionic Content directive', function() {
var compile, element, scope, platform = 'Android';
var compile, element, scope;
//beforeEach(module('ionic'));
beforeEach(module('ionic', function ($provide) {
$provide.value('$ionicPlatform', {
is: function(type) {
return type === platform;
}
});
}));
beforeEach(module('ionic.ui.content'));
beforeEach(inject(function($compile, $rootScope, $timeout, $window) {
compile = $compile;
scope = $rootScope;
timeout = $timeout;
window = $window;
ionic.Platform.setPlatform('Android');
}));
it('Has content class', function() {
@@ -37,7 +30,7 @@ describe('Ionic Content directive', function() {
});
it('Enables bouncing by default', function() {
platform = 'iPhone';
ionic.Platform.setPlatform('iPhone');
element = compile('<content has-header="true"></content>')(scope);
timeout.flush();
var newScope = element.isolateScope();
@@ -46,7 +39,7 @@ describe('Ionic Content directive', function() {
});
it('Disables bouncing when has-bouncing = false', function() {
platform = 'iPhone';
ionic.Platform.setPlatform('iPhone');
element = compile('<content has-header="true" has-bouncing="false"></content>')(scope);
timeout.flush();
var newScope = element.isolateScope();
@@ -55,7 +48,7 @@ describe('Ionic Content directive', function() {
});
it('Disables bouncing by default on Android', function() {
platform = 'Android';
ionic.Platform.setPlatform('Android');
element = compile('<content has-header="true"></content>')(scope);
timeout.flush();
var newScope = element.isolateScope();
@@ -64,7 +57,7 @@ describe('Ionic Content directive', function() {
});
it('Disables bouncing by default on Android unless has-bouncing = true', function() {
platform = 'Android';
ionic.Platform.setPlatform('Android');
element = compile('<content has-header="true" has-bouncing="true"></content>')(scope);
timeout.flush();
var newScope = element.isolateScope();

View File

@@ -44,7 +44,7 @@ describe('Ionic Modal', function() {
var modalInstance = modal.fromTemplate(template);
modalInstance.show();
timeout.flush();
//timeout.flush();
expect(modalInstance.el.classList.contains('active')).toBe(true);