mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
feat(config): add queryParam support
This commit is contained in:
@ -8,7 +8,7 @@ import {
|
||||
OverlayDismissEventDetail
|
||||
} from '../../index';
|
||||
|
||||
import { domControllerAsync, playAnimationAsync } from '../../utils/helpers';
|
||||
import { domControllerAsync, playAnimationAsync, isDef } from '../../utils/helpers';
|
||||
import { createThemedClasses } from '../../utils/theme';
|
||||
|
||||
import iosEnterAnimation from './animations/ios.enter';
|
||||
@ -132,8 +132,11 @@ export class ActionSheet {
|
||||
|
||||
// build the animation and kick it off
|
||||
return this.animationCtrl.create(animationBuilder, this.el).then(animation => {
|
||||
|
||||
this.animation = animation;
|
||||
if (!this.animate) {
|
||||
|
||||
// Check if prop animate is false or if the config for animate is defined/false
|
||||
if (!this.animate || (isDef(this.config.get('animate')) && this.config.get('animate') === false)) {
|
||||
// if the duration is 0, it won't actually animate I don't think
|
||||
// TODO - validate this
|
||||
this.animation = animation.duration(0);
|
||||
@ -160,9 +163,13 @@ export class ActionSheet {
|
||||
});
|
||||
const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation);
|
||||
|
||||
|
||||
return this.animationCtrl.create(animationBuilder, this.el).then(animation => {
|
||||
this.animation = animation;
|
||||
|
||||
if (!this.animate || (isDef(this.config.get('animate')) && this.config.get('animate') === false)) {
|
||||
this.animation = animation.duration(0);
|
||||
}
|
||||
|
||||
return playAnimationAsync(animation);
|
||||
}).then((animation) => {
|
||||
animation.destroy();
|
||||
|
@ -1,12 +1,18 @@
|
||||
import { Config } from '../index';
|
||||
import { PlatformConfig } from './platform-configs';
|
||||
|
||||
import { PlatformConfig, queryParam } from './platform-configs';
|
||||
import { isDef } from '../utils/helpers';
|
||||
|
||||
export function createConfigController(configObj: any, platforms: PlatformConfig[]): Config {
|
||||
configObj = configObj || {};
|
||||
|
||||
function get(key: string, fallback?: any): any {
|
||||
if (configObj[key] !== undefined) {
|
||||
|
||||
let queryValue = queryParam(window.location.href, `ionic${key}`);
|
||||
if (isDef(queryValue)) {
|
||||
return configObj[key] = (queryValue === 'true' ? true : queryValue === 'false' ? false : queryValue);
|
||||
}
|
||||
|
||||
if (isDef(configObj[key])) {
|
||||
return configObj[key];
|
||||
}
|
||||
|
||||
@ -14,7 +20,7 @@ export function createConfigController(configObj: any, platforms: PlatformConfig
|
||||
|
||||
for (let i = 0; i < platforms.length; i++) {
|
||||
settings = platforms[i]['settings'];
|
||||
if (settings && settings[key] !== undefined) {
|
||||
if (settings && isDef(settings[key])) {
|
||||
return settings[key];
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,6 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
|
||||
|
||||
];
|
||||
|
||||
|
||||
export function detectPlatforms(url: string, userAgent: string, platforms: PlatformConfig[], defaultPlatform: string) {
|
||||
// bracket notation to ensure they're not property renamed
|
||||
let validPlatforms = platforms.filter(p => p.isMatch && p.isMatch(url, userAgent));
|
||||
@ -59,7 +58,6 @@ export function detectPlatforms(url: string, userAgent: string, platforms: Platf
|
||||
return validPlatforms;
|
||||
}
|
||||
|
||||
|
||||
export function isPlatformMatch(url: string, userAgent: string, platformName: string, userAgentAtLeastHas: string[], userAgentMustNotHave: string[]) {
|
||||
const queryValue = queryParam(url, 'ionicplatform');
|
||||
if (queryValue) {
|
||||
@ -85,14 +83,13 @@ export function isPlatformMatch(url: string, userAgent: string, platformName: st
|
||||
}
|
||||
|
||||
|
||||
function queryParam(url: string, key: string) {
|
||||
export function queryParam(url: string, key: string) {
|
||||
key = key.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
var regex = new RegExp('[\\?&]' + key + '=([^&#]*)');
|
||||
var results = regex.exec(url);
|
||||
return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null;
|
||||
}
|
||||
|
||||
|
||||
export interface PlatformConfig {
|
||||
name: string;
|
||||
isMatch?: {(url: string, userAgent: string): boolean};
|
||||
|
Reference in New Issue
Block a user