diff --git a/demos/modal/index.ts b/demos/modal/index.ts index 3b15c4ec16..54bee6fbe3 100644 --- a/demos/modal/index.ts +++ b/demos/modal/index.ts @@ -11,7 +11,7 @@ class MyAppCmp { this.modal = modal; console.log('platforms', platform.platforms()); - console.log('mode', config.setting('mode')); + console.log('mode', config.get('mode')); console.log('core', platform.is('core')) console.log('cordova', platform.is('cordova')) diff --git a/ionic/components/action-sheet/action-sheet.ts b/ionic/components/action-sheet/action-sheet.ts index ba0490303d..bfed358662 100644 --- a/ionic/components/action-sheet/action-sheet.ts +++ b/ionic/components/action-sheet/action-sheet.ts @@ -110,10 +110,10 @@ export class ActionSheet extends Overlay { open(opts={}) { let config = this.config; let defaults = { - enterAnimation: config.setting('actionSheetEnter'), - leaveAnimation: config.setting('actionSheetLeave'), - cancelIcon: config.setting('actionSheetCancelIcon'), - destructiveIcon: config.setting('actionSheetDestructiveIcon') + enterAnimation: config.get('actionSheetEnter'), + leaveAnimation: config.get('actionSheetLeave'), + cancelIcon: config.get('actionSheetCancelIcon'), + destructiveIcon: config.get('actionSheetDestructiveIcon') }; let context = util.extend(defaults, opts); diff --git a/ionic/components/app/app.ts b/ionic/components/app/app.ts index 90a30a0772..7a1deb80e3 100644 --- a/ionic/components/app/app.ts +++ b/ionic/components/app/app.ts @@ -281,7 +281,7 @@ function initApp(window, document, config, platform) { platform.url(window.location.href); platform.userAgent(window.navigator.userAgent); platform.navigatorPlatform(window.navigator.platform); - platform.load(config); + platform.load(); // copy default platform settings into the user config platform settings // user config platform settings should override default platform settings @@ -361,7 +361,7 @@ export function ionicBootstrap(rootComponentType, views, config) { let loader = injector.get(DynamicComponentLoader); loader.loadNextToLocation(RootAnchor, lastElementRef).then(() => { // append the focus holder if its needed - if (config.setting('keyboardScrollAssist')) { + if (config.get('keyboardScrollAssist')) { app.appendComponent(FocusHolder).then(ref => { app.focusHolder(ref.instance); }); @@ -409,11 +409,11 @@ function applyBodyCss(document, config, platform) { // set the mode class name // ios - bodyEle.classList.add(config.setting('mode')); + bodyEle.classList.add(config.get('mode')); // touch devices should not use :hover CSS pseudo // enable :hover CSS when the "hoverCSS" setting is not false - if (config.setting('hoverCSS') !== false) { + if (config.get('hoverCSS') !== false) { bodyEle.classList.add('enable-hover'); } diff --git a/ionic/components/button/button.ts b/ionic/components/button/button.ts index 1756a039cc..9151012bf9 100644 --- a/ionic/components/button/button.ts +++ b/ionic/components/button/button.ts @@ -17,7 +17,7 @@ export class Button { ) { let element = elementRef.nativeElement; - if (config.setting('hoverCSS') === false) { + if (config.get('hoverCSS') === false) { element.classList.add('disable-hover'); } diff --git a/ionic/components/icon/icon.ts b/ionic/components/icon/icon.ts index d76d3be9af..7f2c28d74b 100644 --- a/ionic/components/icon/icon.ts +++ b/ionic/components/icon/icon.ts @@ -34,7 +34,7 @@ export class Icon { this.eleRef = elementRef; this.config = config; - this.mode = config.setting('iconMode'); + this.mode = config.get('iconMode'); } /** diff --git a/ionic/components/ion.ts b/ionic/components/ion.ts index d6c0d375dc..6be3e4dd58 100644 --- a/ionic/components/ion.ts +++ b/ionic/components/ion.ts @@ -35,7 +35,7 @@ export class Ion { } // get the property values from a global user/platform config - let configVal = this.config.setting(prop); + let configVal = this.config.get(prop); if (configVal) { this[prop] = configVal; continue; diff --git a/ionic/components/modal/modal.ts b/ionic/components/modal/modal.ts index 791dc6869e..3764cecbcf 100644 --- a/ionic/components/modal/modal.ts +++ b/ionic/components/modal/modal.ts @@ -38,8 +38,8 @@ export class Modal extends Overlay { */ open(ComponentType: Type, opts={}) { let defaults = { - enterAnimation: this.config.setting('modalEnter') || 'modal-slide-in', - leaveAnimation: this.config.setting('modalLeave') || 'modal-slide-out', + enterAnimation: this.config.get('modalEnter') || 'modal-slide-in', + leaveAnimation: this.config.get('modalLeave') || 'modal-slide-out', }; return this.create(OVERLAY_TYPE, ComponentType, util.extend(defaults, opts)); diff --git a/ionic/components/modal/test/basic/index.ts b/ionic/components/modal/test/basic/index.ts index f21fab5ced..4d91f900ea 100644 --- a/ionic/components/modal/test/basic/index.ts +++ b/ionic/components/modal/test/basic/index.ts @@ -11,7 +11,7 @@ class MyAppCmp { this.modal = modal; console.log('platforms', platform.platforms()); - console.log('mode', config.setting('mode')); + console.log('mode', config.get('mode')); console.log('core', platform.is('core')) console.log('cordova', platform.is('cordova')) diff --git a/ionic/components/nav-bar/nav-bar.ts b/ionic/components/nav-bar/nav-bar.ts index 66d7ebed15..108dbee8b2 100644 --- a/ionic/components/nav-bar/nav-bar.ts +++ b/ionic/components/nav-bar/nav-bar.ts @@ -83,8 +83,8 @@ export class Navbar extends ToolbarBase { this.app = app; viewCtrl && viewCtrl.navbarView(this); - this.bbIcon = config.setting('backButtonIcon'); - this.bbDefault = config.setting('backButtonText'); + this.bbIcon = config.get('backButtonIcon'); + this.bbDefault = config.get('backButtonText'); } getBackButtonRef() { diff --git a/ionic/components/nav/nav-controller.ts b/ionic/components/nav/nav-controller.ts index 3eaeac525a..636f7d5e8e 100644 --- a/ionic/components/nav/nav-controller.ts +++ b/ionic/components/nav/nav-controller.ts @@ -46,8 +46,8 @@ export class NavController extends Ion { this.views = []; this._sbTrans = null; - this._sbEnabled = config.setting('swipeBackEnabled') || false; - this._sbThreshold = config.setting('swipeBackThreshold') || 40; + this._sbEnabled = config.get('swipeBackEnabled') || false; + this._sbThreshold = config.get('swipeBackThreshold') || 40; this.id = ++ctrlIds; this._ids = -1; @@ -333,7 +333,7 @@ export class NavController extends Ion { } if (!opts.animation) { - opts.animation = this.config.setting('viewTransition'); + opts.animation = this.config.get('viewTransition'); } // wait for the new view to complete setup diff --git a/ionic/components/overlay/overlay.ts b/ionic/components/overlay/overlay.ts index 3a8d9c299d..e6bf9ff0a6 100644 --- a/ionic/components/overlay/overlay.ts +++ b/ionic/components/overlay/overlay.ts @@ -11,7 +11,7 @@ export class Overlay { constructor(app: IonicApp, config: IonicConfig) { this.app = app; this.config = config; - this.mode = config.setting('mode'); + this.mode = config.get('mode'); } create(overlayType, componentType: Type, opts={}, context=null) { diff --git a/ionic/components/popup/popup.ts b/ionic/components/popup/popup.ts index 90bbd9f0af..e9b1c75b57 100644 --- a/ionic/components/popup/popup.ts +++ b/ionic/components/popup/popup.ts @@ -74,8 +74,8 @@ export class Popup extends Overlay { return new Promise((resolve, reject)=> { let config = this.config; let defaults = { - enterAnimation: config.setting('popupPopIn'), - leaveAnimation: config.setting('popupPopOut'), + enterAnimation: config.get('popupPopIn'), + leaveAnimation: config.get('popupPopOut'), }; opts.promiseResolve = resolve; diff --git a/ionic/components/switch/switch.ts b/ionic/components/switch/switch.ts index 16e3d28d40..e3fc3f6968 100644 --- a/ionic/components/switch/switch.ts +++ b/ionic/components/switch/switch.ts @@ -130,7 +130,7 @@ export class Switch extends Ion { self.id = IonInput.nextId(); self.tabIndex = 0; self.lastTouch = 0; - self.mode = config.setting('mode'); + self.mode = config.get('mode'); self.onChange = (_) => {}; self.onTouched = (_) => {}; diff --git a/ionic/components/tabs/tabs.ts b/ionic/components/tabs/tabs.ts index 3d5cb9c6a1..40fd909b4d 100644 --- a/ionic/components/tabs/tabs.ts +++ b/ionic/components/tabs/tabs.ts @@ -202,7 +202,7 @@ class TabButton extends Ion { super(elementRef, config); this.tabs = tabs; - if (config.setting('hoverCSS') === false) { + if (config.get('hoverCSS') === false) { elementRef.nativeElement.classList.add('disable-hover'); } } @@ -232,7 +232,7 @@ class TabButton extends Ion { }) class TabHighlight { constructor(@Host() tabs: Tabs, config: IonicConfig, elementRef: ElementRef) { - if (config.setting('mode') === 'md') { + if (config.get('mode') === 'md') { tabs.highlight = this; this.elementRef = elementRef; } diff --git a/ionic/components/tap-click/activator.ts b/ionic/components/tap-click/activator.ts index a919c4798c..7adcc819f8 100644 --- a/ionic/components/tap-click/activator.ts +++ b/ionic/components/tap-click/activator.ts @@ -9,7 +9,7 @@ export class Activator { this.active = []; this.clearStateTimeout = 180; this.clearAttempt = 0; - this.activatedClass = config.setting('activatedClass') || 'activated'; + this.activatedClass = config.get('activatedClass') || 'activated'; this.x = 0; this.y = 0; } diff --git a/ionic/components/tap-click/tap-click.ts b/ionic/components/tap-click/tap-click.ts index 9a0647a2d7..1a93c766b5 100644 --- a/ionic/components/tap-click/tap-click.ts +++ b/ionic/components/tap-click/tap-click.ts @@ -18,9 +18,9 @@ export class TapClick { self.disableClick = 0; self.disableClickLimit = 1000; - self.tapPolyfill = (config.setting('tapPolyfill') !== false); + self.tapPolyfill = (config.get('tapPolyfill') !== false); - if (config.setting('mdRipple')) { + if (config.get('mdRipple')) { self.activator = new RippleActivator(app, config); } else { self.activator = new Activator(app, config); diff --git a/ionic/components/text-input/label.ts b/ionic/components/text-input/label.ts index f038e0e35e..b4ff8a1e1d 100644 --- a/ionic/components/text-input/label.ts +++ b/ionic/components/text-input/label.ts @@ -26,7 +26,7 @@ export class Label { * @param {IonicConfig} config */ constructor(config: IonicConfig) { - this.scrollAssist = config.setting('keyboardScrollAssist'); + this.scrollAssist = config.get('keyboardScrollAssist'); } /** diff --git a/ionic/components/text-input/text-input.ts b/ionic/components/text-input/text-input.ts index 8b41724d12..16c76cf7b4 100644 --- a/ionic/components/text-input/text-input.ts +++ b/ionic/components/text-input/text-input.ts @@ -111,7 +111,7 @@ export class TextInput extends Ion { super(elementRef, config); this.scrollView = scrollView; - this.scrollAssist = config.setting('keyboardScrollAssist'); + this.scrollAssist = config.get('keyboardScrollAssist'); this.id = IonInput.nextId(); IonInput.registerInput(this); @@ -121,7 +121,7 @@ export class TextInput extends Ion { this.inputQry = inputQry; this.labelQry = labelQry; - this.keyboardHeight = this.config.setting('keyboardHeight'); + this.keyboardHeight = this.config.get('keyboardHeight'); } /** diff --git a/ionic/config/config.ts b/ionic/config/config.ts index 7be575d64b..96468c174e 100644 --- a/ionic/config/config.ts +++ b/ionic/config/config.ts @@ -1,4 +1,4 @@ - +import {IonicPlatform} from '../platform/platform'; import {isObject, isDefined, isFunction, extend} from '../util/util'; /** @@ -10,56 +10,129 @@ export class IonicConfig { * TODO * @param {Object} settings The settings for your app */ - constructor(settings) { + constructor(settings={}) { + this._s = settings; + this._c = {}; // cached values + } - // defaults - this._settings = {}; + /** + * For setting and getting multiple config values + */ + settings() { + const args = arguments; + + switch (args.length) { + + case 0: + return this._s; + + case 1: + // settings({...}) + this._s = args[0]; + this._c = {}; // clear cache + break; + + case 2: + // settings('ios', {...}) + this._s.platforms = this._s.platforms || {}; + this._s.platforms[args[0]] = args[1]; + this._c = {}; // clear cache + break; - // override defaults w/ user config - if (settings) { - extend(this._settings, settings); } } - get(key) { - let settings = this._settings; + /** + * For setting a single config values + */ + set() { + const args = arguments; + const arg0 = args[0]; + const arg1 = args[1]; - if (!isDefined(this._settings[key])) { + switch (args.length) { + case 2: + // set('key', 'value') = set key/value pair + // arg1 = value + this._s[arg0] = arg1; + delete this._c[arg0]; // clear cache + break; + + case 3: + // setting('ios', 'key', 'value') = set key/value pair for platform + // arg0 = platform + // arg1 = key + // arg2 = value + this._s.platforms = this._s.platforms || {}; + this._s.platforms[arg0] = this._s.platforms[arg0] || {}; + this._s.platforms[arg0][arg1] = args[2]; + delete this._c[arg1]; // clear cache + break; + + } + + return this; + } + + /** + * For getting a single config values + */ + get(key) { + + if (!isDefined(this._c[key])) { // if the value was already set this will all be skipped // if there was no user config then it'll check each of // the user config's platforms, which already contains // settings from default platform configs - this._settings[key] = null; + this._c[key] = null; - // check the platform settings object for this value - // loop though each of the active platforms - let activePlatformKeys = this._platforms; - let platformSettings = this._settings.platforms; - let platformObj = null; - if (platformSettings) { - let platformValue = undefined; + let userPlatformValue = undefined; + let platformValue = undefined; + let userDefaultValue = this._s[key]; + let modeValue = undefined; + + if (this._platform) { + // check the platform settings object for this value + // loop though each of the active platforms + let platformObj = null; + + // array of active platforms, which also knows the hierarchy, + // with the last one the most important + let activePlatformKeys = this._platform.platforms(); + + // loop through all of the active platforms we're on for (let i = 0; i < activePlatformKeys.length; i++) { - platformObj = platformSettings[ activePlatformKeys[i] ]; - if (platformObj) { - if (isDefined(platformObj[key])) { - // check assigned platform settings - platformValue = platformObj[key]; - - } else if (platformObj.mode) { - // check the platform default mode settings - platformObj = IonicConfig.modeConfig(platformObj.mode); - if (platformObj) { - platformValue = platformObj[key]; - } + // get user defined platform values + if (this._s.platforms) { + platformObj = this._s.platforms[ activePlatformKeys[i] ]; + if (platformObj && isDefined(platformObj[key])) { + userPlatformValue = platformObj[key]; } } - } - if (isDefined(platformValue)) { - this._settings[key] = platformValue; + // get default platform's setting + platformObj = IonicPlatform.get(activePlatformKeys[i]); + if (platformObj && platformObj.settings) { + + if (isDefined(platformObj.settings[key])) { + // found a setting for this platform + platformValue = platformObj.settings[key]; + } + + platformObj = IonicConfig.modeConfig(platformObj.settings.mode); + if (platformObj && isDefined(platformObj[key])) { + // found setting for this platform's mode + modeValue = platformObj[key]; + } + + } + } } + + // cache the value + this._c[key] = isDefined(userPlatformValue) ? userPlatformValue : isDefined(platformValue) ? platformValue : isDefined(userDefaultValue) ? userDefaultValue : isDefined(modeValue) ? modeValue : null; } // return key's value @@ -67,124 +140,11 @@ export class IonicConfig { // or it was from the users platform configs // or it was from the default platform configs // in that order - if (isFunction(this._settings[key])) { - this._settings[key] = settings[key](this._platform); - } - return this._settings[key]; - } - - /** - * TODO - */ - setting() { - const args = arguments; - const arg0 = args[0]; - const arg1 = args[1]; - - let settings = this._settings; - - switch (args.length) { - - case 0: - // setting() = get settings object - return settings; - - - case 1: - // setting({...}) = set settings object - // setting('key') = get value - - if (isObject(arg0)) { - // setting({...}) = set settings object - // arg0 = setting object - this._settings = arg0; - return this; - } - - // time for the big show, get the value - // setting('key') = get value - // arg0 = key - - if (!isDefined(settings[arg0])) { - // if the value was already set this will all be skipped - // if there was no user config then it'll check each of - // the user config's platforms, which already contains - // settings from default platform configs - settings[arg0] = null; - - // check the platform settings object for this value - // loop though each of the active platforms - let activePlatformKeys = this._platforms; - let platformSettings = settings.platforms; - let platformObj = null; - if (platformSettings) { - let platformValue = undefined; - for (let i = 0; i < activePlatformKeys.length; i++) { - platformObj = platformSettings[ activePlatformKeys[i] ]; - - if (platformObj) { - if (isDefined(platformObj[arg0])) { - // check assigned platform settings - platformValue = platformObj[arg0]; - - } else if (platformObj.mode) { - // check the platform default mode settings - platformObj = IonicConfig.modeConfig(platformObj.mode); - if (platformObj) { - platformValue = platformObj[arg0]; - } - } - } - - } - if (isDefined(platformValue)) { - settings[arg0] = platformValue; - } - } - } - - // return key's value - // either it came directly from the user config - // or it was from the users platform configs - // or it was from the default platform configs - // in that order - if (isFunction(settings[arg0])) { - settings[arg0] = settings[arg0](this._platform); - } - return settings[arg0]; - - - case 2: - // setting('ios', {...}) = set platform config object - // setting('key', 'value') = set key/value pair - if (isObject(arg1)) { - // setting('ios', {...}) = set platform config object - // arg0 = platform - // arg1 = platform config object - settings.platforms = settings.platforms || {}; - settings.platforms[arg0] = arg1; - - } else { - // setting('key', 'value') = set key/value pair - // arg0 = key - // arg1 = value - settings[arg0] = arg1; - } - return this; - - - case 3: - // setting('ios', 'key', 'value') = set key/value pair for platform - // arg0 = platform - // arg1 = key - // arg2 = value - settings.platforms = settings.platforms || {}; - settings.platforms[arg0] = settings.platforms[arg0] || {}; - settings.platforms[arg0][arg1] = args[2]; - return this; - + if (isFunction(this._c[key])) { + return this._c[key](this._platform); } + return this._c[key]; } /** @@ -193,14 +153,6 @@ export class IonicConfig { */ setPlatform(platform) { this._platform = platform; - - // get the array of active platforms, which also knows the hierarchy, - // with the last one the most important - this._platforms = platform.platforms(); - - // copy default platform settings into the user config platform settings - // user config platform settings should override default platform settings - this._settings.platforms = extend(platform.settings(), this._settings.platforms || {}); } static modeConfig(mode, config) { diff --git a/ionic/config/test/config.spec.ts b/ionic/config/test/config.spec.ts index 1d14153559..15b987b315 100644 --- a/ionic/config/test/config.spec.ts +++ b/ionic/config/test/config.spec.ts @@ -2,9 +2,206 @@ import {IonicConfig, IonicPlatform} from 'ionic/ionic'; export function run() { + it('should get ios mode for core platform', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['core']); + config.setPlatform(platform); + + expect(config.get('mode')).toEqual('ios'); + }); + + it('should get ios mode for ipad platform', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'ios', 'ipad', 'tablet']); + config.setPlatform(platform); + + expect(config.get('mode')).toEqual('ios'); + }); + + it('should get md mode for windowsphone platform', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'windowsphone']); + config.setPlatform(platform); + + expect(config.get('mode')).toEqual('md'); + }); + + it('should get md mode for android platform', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'android']); + config.setPlatform(platform); + + expect(config.get('mode')).toEqual('md'); + }); + + it('should override ios mode config with user platform setting', () => { + let config = new IonicConfig({ + tabBarPlacement: 'hide', + platforms: { + ios: { + tabBarPlacement: 'top' + } + } + }); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + expect(config.get('tabBarPlacement')).toEqual('top'); + }); + + it('should override ios mode config with user setting', () => { + let config = new IonicConfig({ + tabBarPlacement: 'top' + }); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + expect(config.get('tabBarPlacement')).toEqual('top'); + }); + + it('should get setting from md mode', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['android']); + config.setPlatform(platform); + + expect(config.get('tabBarPlacement')).toEqual('top'); + }); + + it('should get setting from ios mode', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + expect(config.get('tabBarPlacement')).toEqual('bottom'); + }); + + it('should set/get platform setting from set()', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + config.set('tabBarPlacement', 'bottom'); + config.set('ios', 'tabBarPlacement', 'top'); + + expect(config.get('tabBarPlacement')).toEqual('top'); + }); + + it('should set/get setting from set()', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + config.set('tabBarPlacement', 'top'); + + expect(config.get('tabBarPlacement')).toEqual('top'); + }); + + it('should set ios platform settings from settings()', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + config.settings('ios', { + key: 'iosValue' + }); + + expect(config.get('key')).toEqual('iosValue'); + }); + + it('should set/get mobile setting even w/ higher priority ios', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'ios']); + config.setPlatform(platform); + + config.settings({ + key: 'defaultValue', + platforms: { + mobile: { + key: 'mobileValue' + } + } + }); + + expect(config.get('key')).toEqual('mobileValue'); + }); + + it('should set/get mobile setting even w/ higher priority ios', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'ios']); + config.setPlatform(platform); + + config.settings({ + key: 'defaultValue', + platforms: { + mobile: { + key: 'mobileValue' + } + } + }); + + expect(config.get('key')).toEqual('mobileValue'); + }); + + it('should set/get android setting w/ higher priority than mobile', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['mobile', 'android']); + config.setPlatform(platform); + + config.settings({ + key: 'defaultValue', + platforms: { + mobile: { + key: 'mobileValue' + }, + android: { + key: 'androidValue' + } + } + }); + + expect(config.get('key')).toEqual('androidValue'); + }); + + it('should set/get ios setting w/ platforms set', () => { + let config = new IonicConfig(); + let platform = new IonicPlatform(['ios']); + config.setPlatform(platform); + + config.settings({ + key: 'defaultValue', + platforms: { + ios: { + key: 'iosValue' + }, + android: { + key: 'androidValue' + } + } + }); + + expect(config.get('key')).toEqual('iosValue'); + }); + + it('should set/get default setting w/ platforms set, but no platform match', () => { + let config = new IonicConfig(); + config.settings({ + key: 'defaultValue', + platforms: { + ios: { + key: 'iosValue' + }, + android: { + key: 'androidValue' + } + } + }); + + expect(config.get('key')).toEqual('defaultValue'); + }); + it('should set setting object', () => { let config = new IonicConfig(); - config.setting({ + config.settings({ name: 'Doc Brown', occupation: 'Weather Man' }); @@ -26,8 +223,8 @@ export function run() { it('should set/get single setting', () => { let config = new IonicConfig(); - config.setting('name', 'Doc Brown'); - config.setting('occupation', 'Weather Man'); + config.set('name', 'Doc Brown'); + config.set('occupation', 'Weather Man'); expect(config.get('name')).toEqual('Doc Brown'); expect(config.get('name')).toEqual('Doc Brown'); @@ -50,7 +247,7 @@ export function run() { occupation: 'Weather Man' }); - expect(config.setting()).toEqual({ + expect(config.settings()).toEqual({ name: 'Doc Brown', occupation: 'Weather Man' }); diff --git a/ionic/platform/platform.ts b/ionic/platform/platform.ts index ed1098d137..4311fa49da 100644 --- a/ionic/platform/platform.ts +++ b/ionic/platform/platform.ts @@ -7,9 +7,8 @@ import * as dom from '../util/dom'; */ export class IonicPlatform { - constructor() { - this._settings = {}; - this._platforms = []; + constructor(platforms=[]) { + this._platforms = platforms; this._versions = {}; this._onResizes = []; @@ -283,12 +282,12 @@ export class IonicPlatform { * TODO * @param {TODO} config TODO */ - load(config) { + load(platformOverride) { let rootPlatformNode = null; let engineNode = null; let self = this; - this.platformOverride = config.setting('platform'); + this.platformOverride = platformOverride; // figure out the most specific platform and active engine let tmpPlatform = null; @@ -359,9 +358,6 @@ export class IonicPlatform { // the last one in the array the most important this._platforms.push(platformNode.name()); - // copy default platform settings into this platform settings obj - this._settings[platformNode.name()] = util.extend({}, platformNode.settings()); - // get the platforms version if a version parser was provided this._versions[platformNode.name()] = platformNode.version(this); @@ -394,13 +390,6 @@ export class IonicPlatform { return rootNode; } - settings(val) { - if (arguments.length) { - this._settings = val; - } - return this._settings; - } - } function insertSuperset(platformNode) { diff --git a/ionic/platform/test/platform.spec.ts b/ionic/platform/test/platform.spec.ts index 784129e6b7..534cbf992e 100644 --- a/ionic/platform/test/platform.spec.ts +++ b/ionic/platform/test/platform.spec.ts @@ -1,13 +1,21 @@ -import {IonicConfig, IonicPlatform} from 'ionic/ionic'; +import {IonicPlatform} from 'ionic/ionic'; export function run() { + it('should set core as the fallback', () => { + let platform = new IonicPlatform(); + platform.userAgent('idk'); + platform.load(); + + expect(platform.is('android')).toEqual(false); + expect(platform.is('ios')).toEqual(false); + expect(platform.is('core')).toEqual(true); + }); + it('should set android via platformOverride, despite ios user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); - config.setting('platform', 'android'); platform.userAgent(IPAD_UA); - platform.load(config); + platform.load('android'); expect(platform.is('android')).toEqual(true); expect(platform.is('ios')).toEqual(false); @@ -15,10 +23,8 @@ export function run() { it('should set ios via platformOverride, despite android querystring', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); - config.setting('platform', 'ios'); platform.url('/?ionicplatform=android'); - platform.load(config); + platform.load('ios'); expect(platform.is('android')).toEqual(false); expect(platform.is('ios')).toEqual(true); @@ -26,9 +32,7 @@ export function run() { it('should set ios via platformOverride', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); - config.setting('platform', 'ios'); - platform.load(config); + platform.load('ios'); expect(platform.is('android')).toEqual(false); expect(platform.is('ios')).toEqual(true); @@ -36,9 +40,7 @@ export function run() { it('should set android via platformOverride', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); - config.setting('platform', 'android'); - platform.load(config); + platform.load('android'); expect(platform.is('android')).toEqual(true); expect(platform.is('ios')).toEqual(false); @@ -46,9 +48,8 @@ export function run() { it('should set ios via querystring', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.url('/?ionicplatform=ios'); - platform.load(config); + platform.load(); expect(platform.is('mobile')).toEqual(true); expect(platform.is('android')).toEqual(false); @@ -58,10 +59,9 @@ export function run() { it('should set ios via querystring, even with android user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.url('/?ionicplatform=ios'); platform.userAgent(ANDROID_UA); - platform.load(config); + platform.load(); expect(platform.is('android')).toEqual(false); expect(platform.is('ios')).toEqual(true); @@ -69,9 +69,8 @@ export function run() { it('should set android via querystring', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.url('/?ionicplatform=android'); - platform.load(config); + platform.load(); expect(platform.is('android')).toEqual(true); expect(platform.is('ios')).toEqual(false); @@ -79,10 +78,9 @@ export function run() { it('should set android via querystring, even with ios user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.url('/?ionicplatform=android'); platform.userAgent(IPHONE_UA); - platform.load(config); + platform.load(); expect(platform.is('android')).toEqual(true); expect(platform.is('ios')).toEqual(false); @@ -90,9 +88,8 @@ export function run() { it('should set android via user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.userAgent(ANDROID_UA); - platform.load(config); + platform.load(); expect(platform.is('mobile')).toEqual(true); expect(platform.is('android')).toEqual(true); @@ -101,9 +98,8 @@ export function run() { it('should set iphone via user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.userAgent(IPHONE_UA); - platform.load(config); + platform.load(); expect(platform.is('mobile')).toEqual(true); expect(platform.is('android')).toEqual(false); @@ -114,9 +110,8 @@ export function run() { it('should set ipad via user agent', () => { let platform = new IonicPlatform(); - let config = new IonicConfig(); platform.userAgent(IPAD_UA); - platform.load(config); + platform.load(); expect(platform.is('mobile')).toEqual(true); expect(platform.is('android')).toEqual(false); diff --git a/ionic/transitions/ios-transition.ts b/ionic/transitions/ios-transition.ts index 6009cac757..87bc8b3f13 100644 --- a/ionic/transitions/ios-transition.ts +++ b/ionic/transitions/ios-transition.ts @@ -26,7 +26,7 @@ class IOSTransition extends Transition { this.enteringContent .to(TRANSLATEX, CENTER) .to(OPACITY, 1) - .before.setStyles({ zIndex: this.entering.index }); + .before.setStyles({ zIndex: this.enteringZ }); this.enteringTitle .fadeIn() @@ -36,16 +36,16 @@ class IOSTransition extends Transition { .to(TRANSLATEX, CENTER); // leaving view moves off screen - this.leavingContent && this.leavingContent + this.leavingContent .from(TRANSLATEX, CENTER) .from(OPACITY, 1) - .before.setStyles({ zIndex: this.leaving.index }); + .before.setStyles({ zIndex: this.leavingZ }); - this.leavingTitle && this.leavingTitle + this.leavingTitle .from(TRANSLATEX, CENTER) .from(OPACITY, 1); - this.leavingNavbarBg && this.leavingNavbarBg + this.leavingNavbarBg .from(TRANSLATEX, CENTER); // set properties depending on direction @@ -62,15 +62,15 @@ class IOSTransition extends Transition { this.enteringNavbarBg .from(TRANSLATEX, OFF_LEFT); - this.leavingContent && this.leavingContent + this.leavingContent .to(TRANSLATEX, '100%') .to(OPACITY, 1); - this.leavingTitle && this.leavingTitle + this.leavingTitle .to(TRANSLATEX, '100%') .to(OPACITY, 0); - this.leavingNavbarBg && this.leavingNavbarBg + this.leavingNavbarBg .to(TRANSLATEX, '100%'); if (this.leaving && this.leaving.enableBack() && this.viewWidth() > 200) { @@ -91,15 +91,15 @@ class IOSTransition extends Transition { this.enteringNavbarBg .from(TRANSLATEX, '99.5%'); - this.leavingContent && this.leavingContent + this.leavingContent .to(TRANSLATEX, OFF_LEFT) .to(OPACITY, OFF_OPACITY); - this.leavingTitle && this.leavingTitle + this.leavingTitle .to(TRANSLATEX, OFF_LEFT) .to(OPACITY, 0); - this.leavingNavbarBg && this.leavingNavbarBg + this.leavingNavbarBg .to(TRANSLATEX, OFF_LEFT); if (this.entering.enableBack() && this.viewWidth() > 200) { diff --git a/ionic/transitions/md-transition.ts b/ionic/transitions/md-transition.ts index d7c4521422..d7789970d5 100644 --- a/ionic/transitions/md-transition.ts +++ b/ionic/transitions/md-transition.ts @@ -15,19 +15,19 @@ class MaterialTransition extends Transition { // entering item moves in bottom to center this.enteringContent .to(TRANSLATEY, CENTER) - .before.setStyles({ zIndex: this.entering.index }); + .before.setStyles({ zIndex: this.enteringZ }); // entering item moves in bottom to center this.enteringNavbar .to(TRANSLATEY, CENTER) - .before.setStyles({ zIndex: this.entering.index + 10 }); + .before.setStyles({ zIndex: this.enteringZ + 10 }); // leaving view stays put - this.leavingContent && this.leavingContent - .before.setStyles({ zIndex: this.leaving.index }); + this.leavingContent + .before.setStyles({ zIndex: this.leavingZ }); - this.leavingNavbar && this.leavingNavbar - .before.setStyles({ zIndex: this.leaving.index + 10 }); + this.leavingNavbar + .before.setStyles({ zIndex: this.leavingZ + 10 }); // set properties depending on direction if (opts.direction === 'back') { @@ -41,11 +41,11 @@ class MaterialTransition extends Transition { .from(TRANSLATEY, CENTER); // leaving view goes center to bottom - this.leavingContent && this.leavingContent + this.leavingContent .fromTo(TRANSLATEY, CENTER, OFF_BOTTOM) .fadeOut(); - this.leavingNavbar && this.leavingNavbar + this.leavingNavbar .fromTo(TRANSLATEY, CENTER, OFF_BOTTOM) .fadeOut(); diff --git a/ionic/transitions/transition.ts b/ionic/transitions/transition.ts index 61067f6a26..b8e8c32a54 100644 --- a/ionic/transitions/transition.ts +++ b/ionic/transitions/transition.ts @@ -17,60 +17,62 @@ export class Transition extends Animation { let entering = this.entering = nav.getStagedEnteringView(); let leaving = this.leaving = nav.getStagedLeavingView(); + this.enteringZ = entering.index; + this.leavingZ = (leaving && leaving.index) || 0; // create animation for the entering view's content area this.enteringContent = new Animation(entering.viewElementRef()); this.enteringContent.before.addClass(SHOW_VIEW_CSS); this.add(this.enteringContent); + let enteringNavbar = this.enteringNavbar = new Animation(entering.navbarRef()); + this.enteringBackButton = new Animation(entering.backBtnRef()); + this.enteringTitle = new Animation(entering.titleRef()); + this.enteringNavbarItems = new Animation(entering.navbarItemRefs()); + this.enteringNavbarBg = new Animation(entering.navbarBgRef()); + if (opts.navbar !== false) { - let enteringNavbar = this.enteringNavbar = new Animation(entering.navbarRef()); enteringNavbar.before.addClass(SHOW_NAVBAR_CSS); if (entering.enableBack()) { // only animate in the back button if the entering view has it enabled - let enteringBackButton = this.enteringBackButton = new Animation(entering.backBtnRef()); - enteringBackButton + this.enteringBackButton .before.addClass(SHOW_BACK_BUTTON) .fadeIn(); - enteringNavbar.add(enteringBackButton); + enteringNavbar.add(this.enteringBackButton); } - this.enteringTitle = new Animation(entering.titleRef()); - enteringNavbar.add(this.enteringTitle); + enteringNavbar + .add(this.enteringTitle) + .add(this.enteringNavbarItems.fadeIn()) + .add(this.enteringNavbarBg); + this.add(enteringNavbar); - - this.enteringNavbarItems = new Animation(entering.navbarItemRefs()); - enteringNavbar.add(this.enteringNavbarItems.fadeIn()); - - this.enteringNavbarBg = new Animation(entering.navbarBgRef()); - enteringNavbar.add(this.enteringNavbarBg); } + this.leavingContent = new Animation(leaving && leaving.viewElementRef()); + let leavingNavbar = this.leavingNavbar = new Animation(leaving && leaving.navbarRef()); + this.leavingBackButton = new Animation(leaving && leaving.backBtnRef()); + this.leavingTitle = new Animation(leaving && leaving.titleRef()); + this.leavingNavbarItems = new Animation(leaving && leaving.navbarItemRefs()); + this.leavingNavbarBg = new Animation(leaving && leaving.navbarBgRef()); if (leaving) { // setup the leaving item if one exists (initial viewing wouldn't have a leaving item) - this.leavingContent = new Animation(leaving.viewElementRef()); this.leavingContent.after.removeClass(SHOW_VIEW_CSS); - let leavingNavbar = this.leavingNavbar = new Animation(leaving.navbarRef()); leavingNavbar.after.removeClass(SHOW_NAVBAR_CSS); - let leavingBackButton = this.leavingBackButton = new Animation(leaving.backBtnRef()); - leavingBackButton + this.leavingBackButton .after.removeClass(SHOW_BACK_BUTTON) .fadeOut(); - leavingNavbar.add(leavingBackButton); - this.leavingTitle = new Animation(leaving.titleRef()); - leavingNavbar.add(this.leavingTitle); - - this.leavingNavbarItems = new Animation(leaving.navbarItemRefs()); - leavingNavbar.add(this.leavingNavbarItems.fadeOut()); - - this.leavingNavbarBg = new Animation(leaving.navbarBgRef()); - leavingNavbar.add(this.leavingNavbarBg); + leavingNavbar + .add(this.leavingBackButton) + .add(this.leavingTitle) + .add(this.leavingNavbarItems.fadeOut()) + .add(this.leavingNavbarBg); this.add(this.leavingContent, leavingNavbar); }