Skip to content

Commit 5c300dd

Browse files
committed
refactor(platform): Rename isCordova() to isWebView()
BREAKING CHANGE: ionic.Platform.isCordova() has been renamed to ionic.Platform.isWebView()
1 parent 9bac605 commit 5c300dd

2 files changed

Lines changed: 28 additions & 22 deletions

File tree

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,16 @@ describe('Ionic Platform Service', function() {
102102
expect(ionic.Platform.isAndroid()).toEqual(true);
103103
});
104104

105-
it('is Cordova', function() {
106-
expect(ionic.Platform.isCordova()).toEqual(false);
105+
it('is WebView', function() {
106+
expect(ionic.Platform.isWebView()).toEqual(false);
107107
window.cordova = {};
108-
expect(ionic.Platform.isCordova()).toEqual(true);
108+
expect(ionic.Platform.isWebView()).toEqual(true);
109109
delete window.cordova;
110110
window.PhoneGap = {};
111-
expect(ionic.Platform.isCordova()).toEqual(true);
111+
expect(ionic.Platform.isWebView()).toEqual(true);
112112
delete window.phonegap;
113113
window.phonegap = {};
114-
expect(ionic.Platform.isCordova()).toEqual(true);
114+
expect(ionic.Platform.isWebView()).toEqual(true);
115115
});
116116

117117
it('sets ios platforms', function() {
@@ -121,10 +121,11 @@ describe('Ionic Platform Service', function() {
121121

122122
ionic.Platform._checkPlatforms()
123123

124-
expect(ionic.Platform.platforms[0]).toEqual('cordova');
125-
expect(ionic.Platform.platforms[1]).toEqual('ios');
126-
expect(ionic.Platform.platforms[2]).toEqual('ios7');
127-
expect(ionic.Platform.platforms[3]).toEqual('ios7_0');
124+
expect(ionic.Platform.platforms[0]).toEqual('webview');
125+
expect(ionic.Platform.platforms[1]).toEqual('cordova');
126+
expect(ionic.Platform.platforms[2]).toEqual('ios');
127+
expect(ionic.Platform.platforms[3]).toEqual('ios7');
128+
expect(ionic.Platform.platforms[4]).toEqual('ios7_0');
128129
});
129130

130131
it('sets android platforms', function() {
@@ -134,21 +135,23 @@ describe('Ionic Platform Service', function() {
134135

135136
ionic.Platform._checkPlatforms()
136137

137-
expect(ionic.Platform.platforms[0]).toEqual('cordova');
138-
expect(ionic.Platform.platforms[1]).toEqual('android');
139-
expect(ionic.Platform.platforms[2]).toEqual('android4');
140-
expect(ionic.Platform.platforms[3]).toEqual('android4_2');
138+
expect(ionic.Platform.platforms[0]).toEqual('webview');
139+
expect(ionic.Platform.platforms[1]).toEqual('cordova');
140+
expect(ionic.Platform.platforms[2]).toEqual('android');
141+
expect(ionic.Platform.platforms[3]).toEqual('android4');
142+
expect(ionic.Platform.platforms[4]).toEqual('android4_2');
141143
});
142144

143-
it('should only set the cordova', function() {
145+
it('should only set the webview', function() {
144146
window.cordova = {};
145147
ionic.Platform.setPlatform('');
146148
ionic.Platform.setVersion('');
147149

148150
ionic.Platform._checkPlatforms()
149151

150-
expect(ionic.Platform.platforms.length).toEqual(1);
151-
expect(ionic.Platform.platforms[0]).toEqual('cordova');
152+
expect(ionic.Platform.platforms.length).toEqual(2);
153+
expect(ionic.Platform.platforms[0]).toEqual('webview');
154+
expect(ionic.Platform.platforms[1]).toEqual('cordova');
152155
});
153156

154157
it('should not set any platform', function() {

js/utils/platform.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@
7979
*/
8080
device: function() {
8181
if(window.device) return window.device;
82-
if(this.isCordova()) console.error('device plugin required');
82+
if(this.isWebView()) console.error('device plugin required');
8383
return {};
8484
},
8585

8686
_checkPlatforms: function(platforms) {
8787
this.platforms = [];
8888
this.grade = 'a';
8989

90-
if(this.isCordova()) this.platforms.push('cordova');
90+
if(this.isWebView()) {
91+
this.platforms.push('webview');
92+
this.platforms.push('cordova');
93+
}
9194
if(this.isIPad()) this.platforms.push('ipad');
9295

9396
var platform = this.platform();
@@ -114,10 +117,10 @@
114117

115118
/**
116119
* @ngdoc method
117-
* @name ionic.Platform#isCordova
118-
* @returns {boolean} Whether we are running on Cordova.
120+
* @name ionic.Platform#isWebView
121+
* @returns {boolean} Check if we are running within a WebView (such as Cordova).
119122
*/
120-
isCordova: function() {
123+
isWebView: function() {
121124
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
122125
},
123126
/**
@@ -301,7 +304,7 @@
301304

302305
// setup listeners to know when the device is ready to go
303306
function onWindowLoad() {
304-
if(ionic.Platform.isCordova()) {
307+
if(ionic.Platform.isWebView()) {
305308
// the window and scripts are fully loaded, and a cordova/phonegap
306309
// object exists then let's listen for the deviceready
307310
document.addEventListener("deviceready", onPlatformReady, false);

0 commit comments

Comments
 (0)