From 5c300dd3e094e20ca90a311a704dfa0864b320f4 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Mon, 7 Apr 2014 11:56:11 -0500 Subject: [PATCH] refactor(platform): Rename isCordova() to isWebView() BREAKING CHANGE: ionic.Platform.isCordova() has been renamed to ionic.Platform.isWebView() --- .../test/service/ionicPlatform.unit.js | 35 ++++++++++--------- js/utils/platform.js | 15 ++++---- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/js/ext/angular/test/service/ionicPlatform.unit.js b/js/ext/angular/test/service/ionicPlatform.unit.js index 93e0d3cf68..351e2c4b22 100644 --- a/js/ext/angular/test/service/ionicPlatform.unit.js +++ b/js/ext/angular/test/service/ionicPlatform.unit.js @@ -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() { diff --git a/js/utils/platform.js b/js/utils/platform.js index 07316e4c9a..129cdbc1a7 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -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);