feat(config): add queryParam support

This commit is contained in:
mhartington
2017-12-15 11:09:33 -05:00
parent a4dfb7ae4f
commit c62322fced
3 changed files with 21 additions and 11 deletions

View File

@ -8,7 +8,7 @@ import {
OverlayDismissEventDetail OverlayDismissEventDetail
} from '../../index'; } from '../../index';
import { domControllerAsync, playAnimationAsync } from '../../utils/helpers'; import { domControllerAsync, playAnimationAsync, isDef } from '../../utils/helpers';
import { createThemedClasses } from '../../utils/theme'; import { createThemedClasses } from '../../utils/theme';
import iosEnterAnimation from './animations/ios.enter'; import iosEnterAnimation from './animations/ios.enter';
@ -132,8 +132,11 @@ export class ActionSheet {
// build the animation and kick it off // build the animation and kick it off
return this.animationCtrl.create(animationBuilder, this.el).then(animation => { return this.animationCtrl.create(animationBuilder, this.el).then(animation => {
this.animation = 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 // if the duration is 0, it won't actually animate I don't think
// TODO - validate this // TODO - validate this
this.animation = animation.duration(0); 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); const animationBuilder = this.leaveAnimation || this.config.get('actionSheetLeave', this.mode === 'ios' ? iosLeaveAnimation : mdLeaveAnimation);
return this.animationCtrl.create(animationBuilder, this.el).then(animation => { return this.animationCtrl.create(animationBuilder, this.el).then(animation => {
this.animation = 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); return playAnimationAsync(animation);
}).then((animation) => { }).then((animation) => {
animation.destroy(); animation.destroy();

View File

@ -1,12 +1,18 @@
import { Config } from '../index'; 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 { export function createConfigController(configObj: any, platforms: PlatformConfig[]): Config {
configObj = configObj || {}; configObj = configObj || {};
function get(key: string, fallback?: any): any { 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]; return configObj[key];
} }
@ -14,7 +20,7 @@ export function createConfigController(configObj: any, platforms: PlatformConfig
for (let i = 0; i < platforms.length; i++) { for (let i = 0; i < platforms.length; i++) {
settings = platforms[i]['settings']; settings = platforms[i]['settings'];
if (settings && settings[key] !== undefined) { if (settings && isDef(settings[key])) {
return settings[key]; return settings[key];
} }
} }

View File

@ -47,7 +47,6 @@ export const PLATFORM_CONFIGS: PlatformConfig[] = [
]; ];
export function detectPlatforms(url: string, userAgent: string, platforms: PlatformConfig[], defaultPlatform: string) { export function detectPlatforms(url: string, userAgent: string, platforms: PlatformConfig[], defaultPlatform: string) {
// bracket notation to ensure they're not property renamed // bracket notation to ensure they're not property renamed
let validPlatforms = platforms.filter(p => p.isMatch && p.isMatch(url, userAgent)); 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; return validPlatforms;
} }
export function isPlatformMatch(url: string, userAgent: string, platformName: string, userAgentAtLeastHas: string[], userAgentMustNotHave: string[]) { export function isPlatformMatch(url: string, userAgent: string, platformName: string, userAgentAtLeastHas: string[], userAgentMustNotHave: string[]) {
const queryValue = queryParam(url, 'ionicplatform'); const queryValue = queryParam(url, 'ionicplatform');
if (queryValue) { 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(/[\]]/, '\\]'); key = key.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + key + '=([^&#]*)'); var regex = new RegExp('[\\?&]' + key + '=([^&#]*)');
var results = regex.exec(url); var results = regex.exec(url);
return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null; return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null;
} }
export interface PlatformConfig { export interface PlatformConfig {
name: string; name: string;
isMatch?: {(url: string, userAgent: string): boolean}; isMatch?: {(url: string, userAgent: string): boolean};