Skip to content

Commit 25a9e52

Browse files
author
Adam Bradley
committed
ionic.Platform.exitApp(), always run onPlatformReady()
1 parent 2add26a commit 25a9e52

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- CustomEvent polyfill improvements for Android
55
- Fix tab icon alignments
66
- Fix $ionicPlatform.ready()
7+
- Fire off ionic.Platform.ready() callbacks for both Cordova and non-cordova
8+
- Created ionic.Platform.exitApp();
79

810

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

dist/js/ionic-angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
672672
$rootScope.$viewHistory.backView.go();
673673
} else {
674674
// there is no back view, so close the app instead
675-
navigator.app.exitApp();
675+
ionic.Platform.exitApp();
676676
}
677677
e.preventDefault();
678678
return false;

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: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ window.ionic = {
17881788

17891789
device: function() {
17901790
if(window.device) return window.device;
1791-
console.error('device plugin required');
1791+
if(this.isCordova()) console.error('device plugin required');
17921792
return {};
17931793
},
17941794

@@ -1853,6 +1853,10 @@ window.ionic = {
18531853
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
18541854
},
18551855

1856+
exitApp: function() {
1857+
navigator.app && navigator.app.exitApp && navigator.app.exitApp();
1858+
},
1859+
18561860
showStatusBar: function(val) {
18571861
// Only useful when run within cordova
18581862
this.showStatusBar = val;
@@ -1891,19 +1895,26 @@ window.ionic = {
18911895

18921896
};
18931897

1894-
var readyCallbacks = [];
1895-
var platformName;
1896-
var platformVersion;
1898+
var platformName,
1899+
platformVersion,
1900+
readyCallbacks = [];
18971901

18981902
// setup listeners to know when the device is ready to go
18991903
function onWindowLoad() {
1900-
// window is loaded, now lets listen for when the device is ready
1901-
document.addEventListener("deviceready", onCordovaReady, false);
1904+
if(ionic.Platform.isCordova()) {
1905+
// the window and scripts are fully loaded, and a cordova/phonegap
1906+
// object exists then let's listen for the deviceready
1907+
document.addEventListener("deviceready", onPlatformReady, false);
1908+
} else {
1909+
// the window and scripts are fully loaded, but the window object doesn't have the
1910+
// cordova/phonegap object, so its just a browser, not a webview wrapped w/ cordova
1911+
onPlatformReady();
1912+
}
19021913
window.removeEventListener("load", onWindowLoad, false);
19031914
}
19041915
window.addEventListener("load", onWindowLoad, false);
19051916

1906-
function onCordovaReady() {
1917+
function onPlatformReady() {
19071918
// the device is all set to go, init our own stuff then fire off our event
19081919
ionic.Platform.isReady = true;
19091920
ionic.Platform.detect();
@@ -1913,7 +1924,7 @@ window.ionic = {
19131924
}
19141925
readyCallbacks = [];
19151926
ionic.trigger('platformready', { target: document });
1916-
document.removeEventListener("deviceready", onCordovaReady, false);
1927+
document.removeEventListener("deviceready", onPlatformReady, false);
19171928
}
19181929

19191930
})(window.ionic);

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/ext/angular/src/service/ionicView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ angular.module('ionic.service.view', ['ui.router', 'ionic.service.platform'])
5757
$rootScope.$viewHistory.backView.go();
5858
} else {
5959
// there is no back view, so close the app instead
60-
navigator.app.exitApp();
60+
ionic.Platform.exitApp();
6161
}
6262
e.preventDefault();
6363
return false;

js/utils/platform.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
device: function() {
3434
if(window.device) return window.device;
35-
console.error('device plugin required');
35+
if(this.isCordova()) console.error('device plugin required');
3636
return {};
3737
},
3838

@@ -97,6 +97,10 @@
9797
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
9898
},
9999

100+
exitApp: function() {
101+
navigator.app && navigator.app.exitApp && navigator.app.exitApp();
102+
},
103+
100104
showStatusBar: function(val) {
101105
// Only useful when run within cordova
102106
this.showStatusBar = val;
@@ -135,19 +139,26 @@
135139

136140
};
137141

138-
var readyCallbacks = [];
139-
var platformName;
140-
var platformVersion;
142+
var platformName,
143+
platformVersion,
144+
readyCallbacks = [];
141145

142146
// setup listeners to know when the device is ready to go
143147
function onWindowLoad() {
144-
// window is loaded, now lets listen for when the device is ready
145-
document.addEventListener("deviceready", onCordovaReady, false);
148+
if(ionic.Platform.isCordova()) {
149+
// the window and scripts are fully loaded, and a cordova/phonegap
150+
// object exists then let's listen for the deviceready
151+
document.addEventListener("deviceready", onPlatformReady, false);
152+
} else {
153+
// the window and scripts are fully loaded, but the window object doesn't have the
154+
// cordova/phonegap object, so its just a browser, not a webview wrapped w/ cordova
155+
onPlatformReady();
156+
}
146157
window.removeEventListener("load", onWindowLoad, false);
147158
}
148159
window.addEventListener("load", onWindowLoad, false);
149160

150-
function onCordovaReady() {
161+
function onPlatformReady() {
151162
// the device is all set to go, init our own stuff then fire off our event
152163
ionic.Platform.isReady = true;
153164
ionic.Platform.detect();
@@ -157,7 +168,7 @@
157168
}
158169
readyCallbacks = [];
159170
ionic.trigger('platformready', { target: document });
160-
document.removeEventListener("deviceready", onCordovaReady, false);
171+
document.removeEventListener("deviceready", onPlatformReady, false);
161172
}
162173

163174
})(window.ionic);

0 commit comments

Comments
 (0)