mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
refactor(config): get/set/settings and unit tests
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export class Icon {
|
||||
this.eleRef = elementRef;
|
||||
this.config = config;
|
||||
|
||||
this.mode = config.setting('iconMode');
|
||||
this.mode = config.get('iconMode');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 = (_) => {};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Label {
|
||||
* @param {IonicConfig} config
|
||||
*/
|
||||
constructor(config: IonicConfig) {
|
||||
this.scrollAssist = config.setting('keyboardScrollAssist');
|
||||
this.scrollAssist = config.get('keyboardScrollAssist');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user