mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(platform): Rename isCordova() to isWebView()
BREAKING CHANGE: ionic.Platform.isCordova() has been renamed to ionic.Platform.isWebView()
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
*/
|
||||
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 {};
|
||||
},
|
||||
|
||||
@@ -87,7 +87,10 @@
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user