Skip to content

Commit 95c8ddf

Browse files
author
Adam Bradley
committed
Update $ionicPlatform.ready()
1 parent 4d26f73 commit 95c8ddf

File tree

8 files changed

+50
-50
lines changed

8 files changed

+50
-50
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
## 0.9.23-alpha (pre-release)
33
- Android back button correctly goes back a view or closes the app
44
- CustomEvent polyfill improvements for Android
5+
- Fix tab icon alignments
6+
- Fix $ionicPlatform.ready()
57

68

79
## 0.9.22 "Alpha Narwhal" (2014-01-30)

dist/js/ionic-angular.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,7 @@ angular.module('ionic.service.platform', [])
483483
.provider('$ionicPlatform', function() {
484484

485485
return {
486-
setPlatform: function(p) {
487-
platform = p;
488-
},
489-
$get: ['$q', '$timeout', function($q, $timeout) {
486+
$get: ['$q', function($q) {
490487
return {
491488
/**
492489
* Some platforms have hardware back buttons, so this is one way to bind to it.
@@ -519,17 +516,12 @@ angular.module('ionic.service.platform', [])
519516
* ready.
520517
*/
521518
ready: function(cb) {
522-
var self = this;
523519
var q = $q.defer();
524520

525-
$timeout(function readyWait() {
526-
if(ionic.Platform.isReady) {
527-
q.resolve();
528-
cb();
529-
} else {
530-
$timeout(readyWait, 50);
531-
}
532-
}, 50);
521+
ionic.Platform.ready(function(){
522+
q.resolve();
523+
cb();
524+
});
533525

534526
return q.promise;
535527
}
@@ -621,7 +613,7 @@ angular.module('ionic.service.templateLoad', [])
621613
};
622614
}]);
623615
;
624-
angular.module('ionic.service.view', ['ui.router'])
616+
angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
625617

626618

627619
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',
@@ -1290,7 +1282,7 @@ angular.module('ionic.ui.checkbox', [])
12901282
(function() {
12911283
'use strict';
12921284

1293-
angular.module('ionic.ui.content', ['ionic.ui.service'])
1285+
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
12941286

12951287
/**
12961288
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be

dist/js/ionic.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,9 @@ window.ionic = {
17671767
if(this.isReady) {
17681768
cb();
17691769
} else {
1770-
ionic.on('platformready', cb, document);
1770+
// the platform isn't ready yet, add it to this array
1771+
// which will be called once the platform is ready
1772+
readyCallbacks.push(cb);
17711773
}
17721774
},
17731775

@@ -1815,16 +1817,28 @@ window.ionic = {
18151817
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
18161818
},
18171819
isIOS7: function() {
1818-
return this.device().platform == 'iOS' && parseFloat(window.device.version) >= 7.0;
1820+
return this.platformName == 'iOS' && parseFloat(window.device.version) >= 7.0;
18191821
},
18201822
isAndroid: function() {
1821-
return this.device().platform === "Android";
1823+
return this.platformName === "Android";
1824+
},
1825+
1826+
platform: function() {
1827+
if(!platformName) {
1828+
this.setPlatform(this.device().platform);
1829+
}
1830+
return platformName;
1831+
},
1832+
1833+
setPlatform: function(name) {
1834+
if(name) platformName = name.toLowerCase();
18221835
},
18231836

18241837
// Check if the platform is the one detected by cordova
18251838
is: function(type) {
1826-
if(this.device.platform) {
1827-
return window.device.platform.toLowerCase() === type.toLowerCase();
1839+
var pName = this.platform();
1840+
if(pName) {
1841+
return pName === type.toLowerCase();
18281842
}
18291843
// A quick hack for
18301844
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
@@ -1868,6 +1882,8 @@ window.ionic = {
18681882

18691883
};
18701884

1885+
var readyCallbacks = [];
1886+
var platformName;
18711887

18721888
// setup listeners to know when the device is ready to go
18731889
function onWindowLoad() {
@@ -1881,6 +1897,11 @@ window.ionic = {
18811897
// the device is all set to go, init our own stuff then fire off our event
18821898
ionic.Platform.isReady = true;
18831899
ionic.Platform.detect();
1900+
for(var x=0; x<readyCallbacks.length; x++) {
1901+
// fire off all the callbacks that were added before the platform was ready
1902+
readyCallbacks[x]();
1903+
}
1904+
readyCallbacks = [];
18841905
ionic.trigger('platformready', { target: document });
18851906
document.removeEventListener("deviceready", onCordovaReady, false);
18861907
}

js/ext/angular/src/directive/ionicContent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function() {
22
'use strict';
33

4-
angular.module('ionic.ui.content', ['ionic.ui.service'])
4+
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
55

66
/**
77
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ angular.module('ionic.service.platform', [])
1212
.provider('$ionicPlatform', function() {
1313

1414
return {
15-
setPlatform: function(p) {
16-
platform = p;
17-
},
18-
$get: ['$q', '$timeout', function($q, $timeout) {
15+
$get: ['$q', function($q) {
1916
return {
2017
/**
2118
* Some platforms have hardware back buttons, so this is one way to bind to it.
@@ -48,17 +45,12 @@ angular.module('ionic.service.platform', [])
4845
* ready.
4946
*/
5047
ready: function(cb) {
51-
var self = this;
5248
var q = $q.defer();
5349

54-
$timeout(function readyWait() {
55-
if(ionic.Platform.isReady) {
56-
q.resolve();
57-
cb();
58-
} else {
59-
$timeout(readyWait, 50);
60-
}
61-
}, 50);
50+
ionic.Platform.ready(function(){
51+
q.resolve();
52+
cb();
53+
});
6254

6355
return q.promise;
6456
}

js/ext/angular/src/service/ionicView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('ionic.service.view', ['ui.router'])
1+
angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
22

33

44
.run( ['$rootScope', '$state', '$location', '$document', '$animate', '$ionicPlatform',

js/ext/angular/test/directive/ionicContent.unit.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
describe('Ionic Content directive', function() {
2-
var compile, element, scope, platform = 'Android';
2+
var compile, element, scope;
33

4-
//beforeEach(module('ionic'));
5-
6-
beforeEach(module('ionic', function ($provide) {
7-
$provide.value('$ionicPlatform', {
8-
is: function(type) {
9-
return type === platform;
10-
}
11-
});
12-
}));
4+
beforeEach(module('ionic.ui.content'));
135

146
beforeEach(inject(function($compile, $rootScope, $timeout, $window) {
157
compile = $compile;
168
scope = $rootScope;
179
timeout = $timeout;
1810
window = $window;
11+
ionic.Platform.setPlatform('Android');
1912
}));
2013

2114
it('Has content class', function() {
@@ -37,7 +30,7 @@ describe('Ionic Content directive', function() {
3730
});
3831

3932
it('Enables bouncing by default', function() {
40-
platform = 'iPhone';
33+
ionic.Platform.setPlatform('iPhone');
4134
element = compile('<content has-header="true"></content>')(scope);
4235
timeout.flush();
4336
var newScope = element.isolateScope();
@@ -46,7 +39,7 @@ describe('Ionic Content directive', function() {
4639
});
4740

4841
it('Disables bouncing when has-bouncing = false', function() {
49-
platform = 'iPhone';
42+
ionic.Platform.setPlatform('iPhone');
5043
element = compile('<content has-header="true" has-bouncing="false"></content>')(scope);
5144
timeout.flush();
5245
var newScope = element.isolateScope();
@@ -55,7 +48,7 @@ describe('Ionic Content directive', function() {
5548
});
5649

5750
it('Disables bouncing by default on Android', function() {
58-
platform = 'Android';
51+
ionic.Platform.setPlatform('Android');
5952
element = compile('<content has-header="true"></content>')(scope);
6053
timeout.flush();
6154
var newScope = element.isolateScope();
@@ -64,7 +57,7 @@ describe('Ionic Content directive', function() {
6457
});
6558

6659
it('Disables bouncing by default on Android unless has-bouncing = true', function() {
67-
platform = 'Android';
60+
ionic.Platform.setPlatform('Android');
6861
element = compile('<content has-header="true" has-bouncing="true"></content>')(scope);
6962
timeout.flush();
7063
var newScope = element.isolateScope();

js/ext/angular/test/service/ionicModal.unit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Ionic Modal', function() {
4444
var modalInstance = modal.fromTemplate(template);
4545
modalInstance.show();
4646

47-
timeout.flush();
47+
//timeout.flush();
4848

4949
expect(modalInstance.el.classList.contains('active')).toBe(true);
5050

0 commit comments

Comments
 (0)