From c62322fced293321b0044bcab62bd763d8ac0a56 Mon Sep 17 00:00:00 2001 From: mhartington Date: Fri, 15 Dec 2017 11:09:33 -0500 Subject: [PATCH] feat(config): add queryParam support --- .../src/components/action-sheet/action-sheet.tsx | 13 ++++++++++--- packages/core/src/global/config-controller.ts | 14 ++++++++++---- packages/core/src/global/platform-configs.ts | 5 +---- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/core/src/components/action-sheet/action-sheet.tsx b/packages/core/src/components/action-sheet/action-sheet.tsx index e4e291a5b2..ef84c3af59 100644 --- a/packages/core/src/components/action-sheet/action-sheet.tsx +++ b/packages/core/src/components/action-sheet/action-sheet.tsx @@ -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(); diff --git a/packages/core/src/global/config-controller.ts b/packages/core/src/global/config-controller.ts index d76df6a62e..ef197bb283 100644 --- a/packages/core/src/global/config-controller.ts +++ b/packages/core/src/global/config-controller.ts @@ -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]; } } diff --git a/packages/core/src/global/platform-configs.ts b/packages/core/src/global/platform-configs.ts index be7631d99e..d9bd371502 100644 --- a/packages/core/src/global/platform-configs.ts +++ b/packages/core/src/global/platform-configs.ts @@ -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};