mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 21:48:42 +08:00
fix(platform): types
This commit is contained in:
@ -7,13 +7,13 @@ export * from './components/button/button'
|
||||
export * from './components/checkbox/checkbox'
|
||||
export * from './components/content/content'
|
||||
export * from './components/icon/icon'
|
||||
export * from './components/input/input'
|
||||
export * from './components/item/item'
|
||||
export * from './components/item/item-sliding'
|
||||
export * from './components/menu/menu'
|
||||
export * from './components/menu/menu-types'
|
||||
export * from './components/menu/menu-toggle'
|
||||
export * from './components/menu/menu-close'
|
||||
export * from './components/text-input/text-input'
|
||||
export * from './components/label/label'
|
||||
export * from './components/list/list'
|
||||
export * from './components/show-hide-when/show-hide-when'
|
||||
@ -36,5 +36,6 @@ export * from './components/select/select'
|
||||
export * from './components/tabs/tabs'
|
||||
export * from './components/tabs/tab'
|
||||
export * from './components/tap-click/tap-click'
|
||||
export * from './components/text-input/text-input'
|
||||
export * from './components/toggle/toggle'
|
||||
export * from './components/toolbar/toolbar'
|
||||
|
@ -28,9 +28,9 @@ export function ionicProviders(args={}) {
|
||||
config = new Config(config);
|
||||
}
|
||||
|
||||
platform.url(window.location.href);
|
||||
platform.userAgent(window.navigator.userAgent);
|
||||
platform.navigatorPlatform(window.navigator.platform);
|
||||
platform.setUrl(window.location.href);
|
||||
platform.setUserAgent(window.navigator.userAgent);
|
||||
platform.setNavigatorPlatform(window.navigator.platform);
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
|
@ -5,8 +5,8 @@ export function run() {
|
||||
it('should set activator setting to none for old Android Browser on a linux device', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
|
||||
platform.navigatorPlatform('linux');
|
||||
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
|
||||
platform.setNavigatorPlatform('linux');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -16,8 +16,8 @@ export function run() {
|
||||
it('should set activator setting to ripple for Android dev tools simulation on a mac', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
|
||||
platform.navigatorPlatform('MacIntel');
|
||||
platform.setUserAgent('Mozilla/5.0 (Linux; U; Android 4.2.2; nl-nl; GT-I9505 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
|
||||
platform.setNavigatorPlatform('MacIntel');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -27,8 +27,8 @@ export function run() {
|
||||
it('should set activator setting to none for Android Chrome versions below v36 on a linux device', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1650.59 Mobile Safari/537.36');
|
||||
platform.navigatorPlatform('linux');
|
||||
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1650.59 Mobile Safari/537.36');
|
||||
platform.setNavigatorPlatform('linux');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -38,8 +38,8 @@ export function run() {
|
||||
it('should set activator setting to ripple for Android Chrome v36 and above on a linux device', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1650.59 Mobile Safari/537.36');
|
||||
platform.navigatorPlatform('linux');
|
||||
platform.setUserAgent('Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1650.59 Mobile Safari/537.36');
|
||||
platform.setNavigatorPlatform('linux');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -49,8 +49,8 @@ export function run() {
|
||||
it('should set activator setting to ripple for Android v5.0 and above on a linux device not using Chrome', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Android 5.0; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
|
||||
platform.navigatorPlatform('linux');
|
||||
platform.setUserAgent('Mozilla/5.0 (Android 5.0; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
|
||||
platform.setNavigatorPlatform('linux');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -60,8 +60,8 @@ export function run() {
|
||||
it('should set activator setting to none for Android versions below v5.0 on a linux device not using Chrome', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.userAgent('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
|
||||
platform.navigatorPlatform('linux');
|
||||
platform.setUserAgent('Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0');
|
||||
platform.setNavigatorPlatform('linux');
|
||||
platform.load();
|
||||
config.setPlatform(platform);
|
||||
|
||||
@ -126,13 +126,13 @@ export function run() {
|
||||
it('should get boolean value from querystring', () => {
|
||||
let config = new Config();
|
||||
let platform = new Platform();
|
||||
platform.url('http://biff.com/?ionicanimate=true')
|
||||
platform.setUrl('http://biff.com/?ionicanimate=true')
|
||||
config.setPlatform(platform);
|
||||
expect(config.get('animate')).toEqual(true);
|
||||
|
||||
config = new Config();
|
||||
platform = new Platform();
|
||||
platform.url('http://biff.com/?ionicanimate=false')
|
||||
platform.setUrl('http://biff.com/?ionicanimate=false')
|
||||
config.setPlatform(platform);
|
||||
expect(config.get('animate')).toEqual(false);
|
||||
});
|
||||
@ -142,7 +142,7 @@ export function run() {
|
||||
mode: 'a'
|
||||
});
|
||||
let platform = new Platform();
|
||||
platform.url('http://biff.com/?ionicConfigKey=b')
|
||||
platform.setUrl('http://biff.com/?ionicConfigKey=b')
|
||||
config.setPlatform(platform);
|
||||
|
||||
expect(config.get('configKey')).toEqual('b');
|
||||
@ -153,7 +153,7 @@ export function run() {
|
||||
mode: 'modeA'
|
||||
});
|
||||
let platform = new Platform();
|
||||
platform.url('http://biff.com/?ionicmode=modeB')
|
||||
platform.setUrl('http://biff.com/?ionicmode=modeB')
|
||||
config.setPlatform(platform);
|
||||
|
||||
expect(config.get('mode')).toEqual('modeB');
|
||||
|
@ -27,7 +27,7 @@ export class Platform {
|
||||
private _dir: string;
|
||||
private _lang: string;
|
||||
private _url: string;
|
||||
private _qs: string;
|
||||
private _qs: any;
|
||||
private _ua: string;
|
||||
private _bPlt: string;
|
||||
private _onResizes: Array<any>=[];
|
||||
@ -277,11 +277,15 @@ export class Platform {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
url(val) {
|
||||
if (arguments.length) {
|
||||
this._url = val;
|
||||
this._qs = getQuerystring(val);
|
||||
setUrl(url) {
|
||||
this._url = url;
|
||||
this._qs = getQuerystring(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
url(val) {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
@ -295,20 +299,28 @@ export class Platform {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
userAgent(val) {
|
||||
if (arguments.length) {
|
||||
this._ua = val;
|
||||
setUserAgent(userAgent) {
|
||||
this._ua = userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
userAgent(val) {
|
||||
return this._ua || '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
navigatorPlatform(val) {
|
||||
if (arguments.length) {
|
||||
this._bPlt = val;
|
||||
setNavigatorPlatform(navigatorPlatform) {
|
||||
this._bPlt = navigatorPlatform;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
navigatorPlatform(val) {
|
||||
return this._bPlt || '';
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@ export function run() {
|
||||
|
||||
it('should set core as the fallback', () => {
|
||||
let platform = new Platform();
|
||||
platform.userAgent('idk');
|
||||
platform.setUserAgent('idk');
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('android')).toEqual(false);
|
||||
@ -14,7 +14,7 @@ export function run() {
|
||||
|
||||
it('should set android via platformOverride, despite ios user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.userAgent(IPAD_UA);
|
||||
platform.setUserAgent(IPAD_UA);
|
||||
platform.load('android');
|
||||
|
||||
expect(platform.is('android')).toEqual(true);
|
||||
@ -23,21 +23,21 @@ export function run() {
|
||||
|
||||
it('should get case insensitive querystring value', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?KEY=value');
|
||||
platform.setUrl('/?KEY=value');
|
||||
|
||||
expect(platform.query('key')).toEqual('value');
|
||||
});
|
||||
|
||||
it('should get querystring value', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?key=value');
|
||||
platform.setUrl('/?key=value');
|
||||
|
||||
expect(platform.query('key')).toEqual('value');
|
||||
});
|
||||
|
||||
it('should set ios via platformOverride, despite android querystring', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?ionicplatform=android');
|
||||
platform.setUrl('/?ionicplatform=android');
|
||||
platform.load('ios');
|
||||
|
||||
expect(platform.is('android')).toEqual(false);
|
||||
@ -62,7 +62,7 @@ export function run() {
|
||||
|
||||
it('should set ios via querystring', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?ionicplatform=ios');
|
||||
platform.setUrl('/?ionicplatform=ios');
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('mobile')).toEqual(true);
|
||||
@ -73,8 +73,8 @@ export function run() {
|
||||
|
||||
it('should set ios via querystring, even with android user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?ionicplatform=ios');
|
||||
platform.userAgent(ANDROID_UA);
|
||||
platform.setUrl('/?ionicplatform=ios');
|
||||
platform.setUserAgent(ANDROID_UA);
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('android')).toEqual(false);
|
||||
@ -83,7 +83,7 @@ export function run() {
|
||||
|
||||
it('should set android via querystring', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?ionicplatform=android');
|
||||
platform.setUrl('/?ionicplatform=android');
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('android')).toEqual(true);
|
||||
@ -92,8 +92,8 @@ export function run() {
|
||||
|
||||
it('should set android via querystring, even with ios user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.url('/?ionicplatform=android');
|
||||
platform.userAgent(IPHONE_UA);
|
||||
platform.setUrl('/?ionicplatform=android');
|
||||
platform.setUserAgent(IPHONE_UA);
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('android')).toEqual(true);
|
||||
@ -102,7 +102,7 @@ export function run() {
|
||||
|
||||
it('should set android via user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.userAgent(ANDROID_UA);
|
||||
platform.setUserAgent(ANDROID_UA);
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('mobile')).toEqual(true);
|
||||
@ -112,7 +112,7 @@ export function run() {
|
||||
|
||||
it('should set iphone via user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.userAgent(IPHONE_UA);
|
||||
platform.setUserAgent(IPHONE_UA);
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('mobile')).toEqual(true);
|
||||
@ -124,7 +124,7 @@ export function run() {
|
||||
|
||||
it('should set ipad via user agent', () => {
|
||||
let platform = new Platform();
|
||||
platform.userAgent(IPAD_UA);
|
||||
platform.setUserAgent(IPAD_UA);
|
||||
platform.load();
|
||||
|
||||
expect(platform.is('mobile')).toEqual(true);
|
||||
|
@ -17,7 +17,7 @@ export function clamp(min, n, max) {
|
||||
* @param dst the destination
|
||||
* @param ... the param objects
|
||||
*/
|
||||
export function extend(dst: any) {
|
||||
export function extend(dst: any, ...args: any[]) {
|
||||
return _baseExtend(dst, [].slice.call(arguments, 1), false);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ export function extend(dst: any) {
|
||||
* @param dst the destination
|
||||
* @param ... the param objects
|
||||
*/
|
||||
export function merge(dst: any) {
|
||||
export function merge(dst: any, ...args: any[]) {
|
||||
return _baseExtend(dst, [].slice.call(arguments, 1), true);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ export function debounce(func: any, wait: number, immediate: boolean) {
|
||||
* the first object.
|
||||
* @param the destination to apply defaults to.
|
||||
*/
|
||||
export function defaults(dest) {
|
||||
export function defaults(dest, ...args: any[]) {
|
||||
for (let i = arguments.length - 1; i >= 1; i--) {
|
||||
let source = arguments[i] || {};
|
||||
for (let key in source) {
|
||||
@ -140,10 +140,10 @@ export const array = {
|
||||
}
|
||||
|
||||
/**
|
||||
* Grab the query string param value for the given key.
|
||||
* @param key the key to look for
|
||||
* Grab all query strings keys and values.
|
||||
* @param url
|
||||
*/
|
||||
export function getQuerystring(url, key) {
|
||||
export function getQuerystring(url: string): any {
|
||||
var queryParams = {};
|
||||
if (url) {
|
||||
const startIndex = url.indexOf('?');
|
||||
@ -154,9 +154,6 @@ export function getQuerystring(url, key) {
|
||||
queryParams[split[0].toLowerCase()] = split[1].split('#')[0];
|
||||
});
|
||||
}
|
||||
if (key) {
|
||||
return queryParams[key] || '';
|
||||
}
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
Reference in New Issue
Block a user