mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor ionic.Platform methods
This commit is contained in:
6
dist/js/ionic-angular.js
vendored
6
dist/js/ionic-angular.js
vendored
@@ -1282,7 +1282,7 @@ angular.module('ionic.ui.checkbox', [])
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
|
||||
angular.module('ionic.ui.content', ['ionic.ui.service'])
|
||||
|
||||
/**
|
||||
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be
|
||||
@@ -1299,7 +1299,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'
|
||||
|
||||
// The content directive is a core scrollable content area
|
||||
// that is part of many View hierarchies
|
||||
.directive('content', ['$parse', '$timeout', '$ionicPlatform', '$ionicScrollDelegate', function($parse, $timeout, $ionicPlatform, $ionicScrollDelegate) {
|
||||
.directive('content', ['$parse', '$timeout', '$ionicScrollDelegate', function($parse, $timeout, $ionicScrollDelegate) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
@@ -1364,7 +1364,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'
|
||||
|
||||
// Otherwise, supercharge this baby!
|
||||
var hasBouncing = $scope.$eval($scope.hasBouncing);
|
||||
var enableBouncing = (!$ionicPlatform.is('Android') && hasBouncing !== false) || hasBouncing === true;
|
||||
var enableBouncing = (!ionic.Platform.isAndroid() && hasBouncing !== false) || hasBouncing === true;
|
||||
// No bouncing by default for Android users, lest they take up pitchforks
|
||||
// to our bouncing goodness
|
||||
sv = new ionic.views.Scroll({
|
||||
|
||||
2
dist/js/ionic-angular.min.js
vendored
2
dist/js/ionic-angular.min.js
vendored
File diff suppressed because one or more lines are too long
31
dist/js/ionic.js
vendored
31
dist/js/ionic.js
vendored
@@ -1798,29 +1798,31 @@ window.ionic = {
|
||||
if(this.isCordova()) {
|
||||
this.platforms.push('cordova');
|
||||
}
|
||||
if(this.isIOS7()) {
|
||||
this.platforms.push('ios7');
|
||||
if(this.isIOS()) {
|
||||
this.platforms.push('ios');
|
||||
this.platforms.push('ios' + parseInt(this.version(), 10));
|
||||
}
|
||||
if(this.isIPad()) {
|
||||
this.platforms.push('ipad');
|
||||
}
|
||||
if(this.isAndroid()) {
|
||||
this.platforms.push('android');
|
||||
this.platforms.push('android' + parseInt(this.version(), 10));
|
||||
}
|
||||
},
|
||||
|
||||
// Check if we are running in Cordova
|
||||
isCordova: function() {
|
||||
return (window.cordova || window.PhoneGap || window.phonegap);
|
||||
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
|
||||
},
|
||||
isIPad: function() {
|
||||
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
|
||||
},
|
||||
isIOS7: function() {
|
||||
return this.platform() == 'ios' && this.version() >= 7.0;
|
||||
isIOS: function() {
|
||||
return this.is('ios');
|
||||
},
|
||||
isAndroid: function() {
|
||||
return this.platform() === "android";
|
||||
return this.is('android');
|
||||
},
|
||||
|
||||
platform: function() {
|
||||
@@ -1829,8 +1831,8 @@ window.ionic = {
|
||||
return platformName;
|
||||
},
|
||||
|
||||
setPlatform: function(name) {
|
||||
if(name) platformName = name.toLowerCase();
|
||||
setPlatform: function(n) {
|
||||
platformName = n;
|
||||
},
|
||||
|
||||
version: function() {
|
||||
@@ -1840,14 +1842,19 @@ window.ionic = {
|
||||
},
|
||||
|
||||
setVersion: function(v) {
|
||||
if( !isNaN(v) ) version = parseFloat(v);
|
||||
if(v) {
|
||||
v = v.split('.');
|
||||
platformVersion = parseFloat(v[0] + '.' + (v.length > 1 ? v[1] : 0));
|
||||
} else {
|
||||
platformVersion = 0;
|
||||
}
|
||||
},
|
||||
|
||||
// Check if the platform is the one detected by cordova
|
||||
is: function(type) {
|
||||
var pName = this.platform();
|
||||
if(pName) {
|
||||
return pName === type.toLowerCase();
|
||||
return pName.toLowerCase() === type.toLowerCase();
|
||||
}
|
||||
// A quick hack for
|
||||
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
|
||||
@@ -1895,8 +1902,8 @@ window.ionic = {
|
||||
|
||||
};
|
||||
|
||||
var platformName,
|
||||
platformVersion,
|
||||
var platformName, // just the name, like iOS or Android
|
||||
platformVersion, // a float of the major and minor, like 7.1
|
||||
readyCallbacks = [];
|
||||
|
||||
// setup listeners to know when the device is ready to go
|
||||
|
||||
6
dist/js/ionic.min.js
vendored
6
dist/js/ionic.min.js
vendored
File diff suppressed because one or more lines are too long
6
js/ext/angular/src/directive/ionicContent.js
vendored
6
js/ext/angular/src/directive/ionicContent.js
vendored
@@ -1,7 +1,7 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'])
|
||||
angular.module('ionic.ui.content', ['ionic.ui.service'])
|
||||
|
||||
/**
|
||||
* Panel is a simple 100% width and height, fixed panel. It's meant for content to be
|
||||
@@ -18,7 +18,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'
|
||||
|
||||
// The content directive is a core scrollable content area
|
||||
// that is part of many View hierarchies
|
||||
.directive('content', ['$parse', '$timeout', '$ionicPlatform', '$ionicScrollDelegate', function($parse, $timeout, $ionicPlatform, $ionicScrollDelegate) {
|
||||
.directive('content', ['$parse', '$timeout', '$ionicScrollDelegate', function($parse, $timeout, $ionicScrollDelegate) {
|
||||
return {
|
||||
restrict: 'E',
|
||||
replace: true,
|
||||
@@ -83,7 +83,7 @@ angular.module('ionic.ui.content', ['ionic.ui.service', 'ionic.service.platform'
|
||||
|
||||
// Otherwise, supercharge this baby!
|
||||
var hasBouncing = $scope.$eval($scope.hasBouncing);
|
||||
var enableBouncing = (!$ionicPlatform.is('Android') && hasBouncing !== false) || hasBouncing === true;
|
||||
var enableBouncing = (!ionic.Platform.isAndroid() && hasBouncing !== false) || hasBouncing === true;
|
||||
// No bouncing by default for Android users, lest they take up pitchforks
|
||||
// to our bouncing goodness
|
||||
sv = new ionic.views.Scroll({
|
||||
|
||||
128
js/ext/angular/test/service/ionicPlatform.unit.js
Normal file
128
js/ext/angular/test/service/ionicPlatform.unit.js
Normal file
@@ -0,0 +1,128 @@
|
||||
describe('Ionic Platform Service', function() {
|
||||
var window;
|
||||
|
||||
beforeEach(inject(function($window) {
|
||||
window = $window;
|
||||
}));
|
||||
|
||||
it('should set platform name', function() {
|
||||
ionic.Platform.setPlatform('Android');
|
||||
expect(ionic.Platform.platform()).toEqual('Android');
|
||||
|
||||
ionic.Platform.setPlatform('iOS');
|
||||
expect(ionic.Platform.platform()).toEqual('iOS');
|
||||
|
||||
ionic.Platform.setPlatform('wInDoWs');
|
||||
expect(ionic.Platform.platform()).toEqual('wInDoWs');
|
||||
|
||||
ionic.Platform.setPlatform('');
|
||||
expect(ionic.Platform.platform()).toEqual(undefined);
|
||||
|
||||
ionic.Platform.setPlatform();
|
||||
expect(ionic.Platform.platform()).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('set version', function() {
|
||||
ionic.Platform.setVersion('1.2.3');
|
||||
expect(ionic.Platform.version()).toEqual(1.2);
|
||||
|
||||
ionic.Platform.setVersion('1.2');
|
||||
expect(ionic.Platform.version()).toEqual(1.2);
|
||||
|
||||
ionic.Platform.setVersion('1');
|
||||
expect(ionic.Platform.version()).toEqual(1.0);
|
||||
|
||||
ionic.Platform.setVersion(' ');
|
||||
expect(ionic.Platform.version()).toEqual(0);
|
||||
|
||||
ionic.Platform.setVersion('');
|
||||
expect(ionic.Platform.version()).toEqual(0);
|
||||
|
||||
ionic.Platform.setVersion(null);
|
||||
expect(ionic.Platform.version()).toEqual(0);
|
||||
|
||||
ionic.Platform.setVersion();
|
||||
expect(ionic.Platform.version()).toEqual(0);
|
||||
});
|
||||
|
||||
it('is iOS', function() {
|
||||
ionic.Platform.setPlatform('iOS');
|
||||
expect(ionic.Platform.isIOS()).toEqual(true);
|
||||
|
||||
ionic.Platform.setPlatform('ios');
|
||||
expect(ionic.Platform.isIOS()).toEqual(true);
|
||||
|
||||
ionic.Platform.setPlatform('Android');
|
||||
expect(ionic.Platform.isIOS()).toEqual(false);
|
||||
});
|
||||
|
||||
it('is Android', function() {
|
||||
ionic.Platform.setPlatform('Android');
|
||||
expect(ionic.Platform.isAndroid()).toEqual(true);
|
||||
|
||||
ionic.Platform.setPlatform('android');
|
||||
expect(ionic.Platform.isAndroid()).toEqual(true);
|
||||
|
||||
ionic.Platform.setPlatform('ios');
|
||||
expect(ionic.Platform.isAndroid()).toEqual(false);
|
||||
});
|
||||
|
||||
it('is Cordova', function() {
|
||||
expect(ionic.Platform.isCordova()).toEqual(false);
|
||||
window.cordova = {};
|
||||
expect(ionic.Platform.isCordova()).toEqual(true);
|
||||
delete window.cordova;
|
||||
window.PhoneGap = {};
|
||||
expect(ionic.Platform.isCordova()).toEqual(true);
|
||||
delete window.phonegap;
|
||||
window.phonegap = {};
|
||||
expect(ionic.Platform.isCordova()).toEqual(true);
|
||||
});
|
||||
|
||||
it('sets ios platforms', function() {
|
||||
window.cordova = {};
|
||||
ionic.Platform.setPlatform('iOS');
|
||||
ionic.Platform.setVersion('7.9.3');
|
||||
|
||||
ionic.Platform._checkPlatforms()
|
||||
|
||||
expect(ionic.Platform.platforms[0]).toEqual('cordova');
|
||||
expect(ionic.Platform.platforms[1]).toEqual('ios');
|
||||
expect(ionic.Platform.platforms[2]).toEqual('ios7');
|
||||
});
|
||||
|
||||
it('sets android platforms', function() {
|
||||
window.cordova = {};
|
||||
ionic.Platform.setPlatform('android');
|
||||
ionic.Platform.setVersion('4.4.4');
|
||||
|
||||
ionic.Platform._checkPlatforms()
|
||||
|
||||
expect(ionic.Platform.platforms[0]).toEqual('cordova');
|
||||
expect(ionic.Platform.platforms[1]).toEqual('android');
|
||||
expect(ionic.Platform.platforms[2]).toEqual('android4');
|
||||
});
|
||||
|
||||
it('is android', function() {
|
||||
ionic.Platform.setPlatform('AnDrOiD');
|
||||
expect(ionic.Platform.is('android')).toEqual(true);
|
||||
ionic.Platform.setPlatform('ANDROID');
|
||||
expect(ionic.Platform.is('android')).toEqual(true);
|
||||
ionic.Platform.setPlatform('android');
|
||||
expect(ionic.Platform.is('android')).toEqual(true);
|
||||
ionic.Platform.setPlatform('ios');
|
||||
expect(ionic.Platform.is('android')).toEqual(false);
|
||||
});
|
||||
|
||||
it('is android', function() {
|
||||
ionic.Platform.setPlatform('iOs');
|
||||
expect(ionic.Platform.is('ios')).toEqual(true);
|
||||
ionic.Platform.setPlatform('iOs');
|
||||
expect(ionic.Platform.is('IOS')).toEqual(true);
|
||||
ionic.Platform.setPlatform('IOS');
|
||||
expect(ionic.Platform.is('ios')).toEqual(true);
|
||||
ionic.Platform.setPlatform('IOS');
|
||||
expect(ionic.Platform.is('android')).toEqual(false);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -42,29 +42,31 @@
|
||||
if(this.isCordova()) {
|
||||
this.platforms.push('cordova');
|
||||
}
|
||||
if(this.isIOS7()) {
|
||||
this.platforms.push('ios7');
|
||||
if(this.isIOS()) {
|
||||
this.platforms.push('ios');
|
||||
this.platforms.push('ios' + parseInt(this.version(), 10));
|
||||
}
|
||||
if(this.isIPad()) {
|
||||
this.platforms.push('ipad');
|
||||
}
|
||||
if(this.isAndroid()) {
|
||||
this.platforms.push('android');
|
||||
this.platforms.push('android' + parseInt(this.version(), 10));
|
||||
}
|
||||
},
|
||||
|
||||
// Check if we are running in Cordova
|
||||
isCordova: function() {
|
||||
return (window.cordova || window.PhoneGap || window.phonegap);
|
||||
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
|
||||
},
|
||||
isIPad: function() {
|
||||
return navigator.userAgent.toLowerCase().indexOf('ipad') >= 0;
|
||||
},
|
||||
isIOS7: function() {
|
||||
return this.platform() == 'ios' && this.version() >= 7.0;
|
||||
isIOS: function() {
|
||||
return this.is('ios');
|
||||
},
|
||||
isAndroid: function() {
|
||||
return this.platform() === "android";
|
||||
return this.is('android');
|
||||
},
|
||||
|
||||
platform: function() {
|
||||
@@ -73,8 +75,8 @@
|
||||
return platformName;
|
||||
},
|
||||
|
||||
setPlatform: function(name) {
|
||||
if(name) platformName = name.toLowerCase();
|
||||
setPlatform: function(n) {
|
||||
platformName = n;
|
||||
},
|
||||
|
||||
version: function() {
|
||||
@@ -84,14 +86,19 @@
|
||||
},
|
||||
|
||||
setVersion: function(v) {
|
||||
if( !isNaN(v) ) version = parseFloat(v);
|
||||
if(v) {
|
||||
v = v.split('.');
|
||||
platformVersion = parseFloat(v[0] + '.' + (v.length > 1 ? v[1] : 0));
|
||||
} else {
|
||||
platformVersion = 0;
|
||||
}
|
||||
},
|
||||
|
||||
// Check if the platform is the one detected by cordova
|
||||
is: function(type) {
|
||||
var pName = this.platform();
|
||||
if(pName) {
|
||||
return pName === type.toLowerCase();
|
||||
return pName.toLowerCase() === type.toLowerCase();
|
||||
}
|
||||
// A quick hack for
|
||||
return navigator.userAgent.toLowerCase().indexOf(type.toLowerCase()) >= 0;
|
||||
@@ -139,8 +146,8 @@
|
||||
|
||||
};
|
||||
|
||||
var platformName,
|
||||
platformVersion,
|
||||
var platformName, // just the name, like iOS or Android
|
||||
platformVersion, // a float of the major and minor, like 7.1
|
||||
readyCallbacks = [];
|
||||
|
||||
// setup listeners to know when the device is ready to go
|
||||
|
||||
Reference in New Issue
Block a user