Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(platform): Rename isCordova() to isWebView()
Browse files Browse the repository at this point in the history
BREAKING CHANGE: ionic.Platform.isCordova() has been renamed to
ionic.Platform.isWebView()
adamdbradley committed Apr 7, 2014
1 parent 9bac605 commit 5c300dd
Showing 2 changed files with 28 additions and 22 deletions.
35 changes: 19 additions & 16 deletions js/ext/angular/test/service/ionicPlatform.unit.js
Original file line number Diff line number Diff line change
@@ -102,16 +102,16 @@ describe('Ionic Platform Service', function() {
expect(ionic.Platform.isAndroid()).toEqual(true);
});

it('is Cordova', function() {
expect(ionic.Platform.isCordova()).toEqual(false);
it('is WebView', function() {
expect(ionic.Platform.isWebView()).toEqual(false);
window.cordova = {};
expect(ionic.Platform.isCordova()).toEqual(true);
expect(ionic.Platform.isWebView()).toEqual(true);
delete window.cordova;
window.PhoneGap = {};
expect(ionic.Platform.isCordova()).toEqual(true);
expect(ionic.Platform.isWebView()).toEqual(true);
delete window.phonegap;
window.phonegap = {};
expect(ionic.Platform.isCordova()).toEqual(true);
expect(ionic.Platform.isWebView()).toEqual(true);
});

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

ionic.Platform._checkPlatforms()

expect(ionic.Platform.platforms[0]).toEqual('cordova');
expect(ionic.Platform.platforms[1]).toEqual('ios');
expect(ionic.Platform.platforms[2]).toEqual('ios7');
expect(ionic.Platform.platforms[3]).toEqual('ios7_0');
expect(ionic.Platform.platforms[0]).toEqual('webview');
expect(ionic.Platform.platforms[1]).toEqual('cordova');
expect(ionic.Platform.platforms[2]).toEqual('ios');
expect(ionic.Platform.platforms[3]).toEqual('ios7');
expect(ionic.Platform.platforms[4]).toEqual('ios7_0');
});

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

ionic.Platform._checkPlatforms()

expect(ionic.Platform.platforms[0]).toEqual('cordova');
expect(ionic.Platform.platforms[1]).toEqual('android');
expect(ionic.Platform.platforms[2]).toEqual('android4');
expect(ionic.Platform.platforms[3]).toEqual('android4_2');
expect(ionic.Platform.platforms[0]).toEqual('webview');
expect(ionic.Platform.platforms[1]).toEqual('cordova');
expect(ionic.Platform.platforms[2]).toEqual('android');
expect(ionic.Platform.platforms[3]).toEqual('android4');
expect(ionic.Platform.platforms[4]).toEqual('android4_2');
});

it('should only set the cordova', function() {
it('should only set the webview', function() {
window.cordova = {};
ionic.Platform.setPlatform('');
ionic.Platform.setVersion('');

ionic.Platform._checkPlatforms()

expect(ionic.Platform.platforms.length).toEqual(1);
expect(ionic.Platform.platforms[0]).toEqual('cordova');
expect(ionic.Platform.platforms.length).toEqual(2);
expect(ionic.Platform.platforms[0]).toEqual('webview');
expect(ionic.Platform.platforms[1]).toEqual('cordova');
});

it('should not set any platform', function() {
15 changes: 9 additions & 6 deletions js/utils/platform.js
Original file line number Diff line number Diff line change
@@ -79,15 +79,18 @@
*/
device: function() {
if(window.device) return window.device;
if(this.isCordova()) console.error('device plugin required');
if(this.isWebView()) console.error('device plugin required');
return {};
},

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

if(this.isCordova()) this.platforms.push('cordova');
if(this.isWebView()) {
this.platforms.push('webview');
this.platforms.push('cordova');
}
if(this.isIPad()) this.platforms.push('ipad');

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

/**
* @ngdoc method
* @name ionic.Platform#isCordova
* @returns {boolean} Whether we are running on Cordova.
* @name ionic.Platform#isWebView
* @returns {boolean} Check if we are running within a WebView (such as Cordova).
*/
isCordova: function() {
isWebView: function() {
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
},
/**
@@ -301,7 +304,7 @@

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

8 comments on commit 5c300dd

@darrenahunter
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi
Just wondering if 'isWebView' is best name for this now as with Android 4.4 they are using Chromium rather than webView now as I understand.
Just a thought.

@rvanbaalen
Copy link

@rvanbaalen rvanbaalen commented on 5c300dd Apr 26, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrenahunter
Copy link

@darrenahunter darrenahunter commented on 5c300dd Apr 26, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdbradley
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to hardcode ourselves in to only using Cordova. What if they're using PhoneGap, or one of the other newer self proclaimed PhoneGap killers? In the end its the same, but down the road it may cause issues so I want to keep any 3rd party names out of our code.

@darrenahunter
Copy link

@darrenahunter darrenahunter commented on 5c300dd Apr 28, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdbradley
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@darrenahunter
Copy link

@darrenahunter darrenahunter commented on 5c300dd Apr 29, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvanbaalen
Copy link

@rvanbaalen rvanbaalen commented on 5c300dd Apr 29, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.