mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
wip
This commit is contained in:
@@ -3,8 +3,7 @@ import {DirectiveMetadata} from 'angular2/src/render/api';
|
||||
|
||||
import * as util from 'ionic/util';
|
||||
import {Platform} from 'ionic/platform/platform';
|
||||
|
||||
const platformMode = Platform.getMode();
|
||||
import {GlobalIonicConfig} from '../components/app/app';
|
||||
|
||||
|
||||
export class IonicDirective extends Directive {
|
||||
@@ -23,8 +22,6 @@ function appendModeConfig(ComponentType) {
|
||||
let config = ComponentType.config;
|
||||
config.host = config.host || {};
|
||||
|
||||
// let host = DirectiveMetadata.parseHostConfig(config.host);
|
||||
|
||||
const defaultProperties = config.defaultProperties;
|
||||
|
||||
config.properties = config.properties || [];
|
||||
@@ -56,20 +53,13 @@ function appendModeConfig(ComponentType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the property values from a global user config
|
||||
var globalPropertyValue = null;
|
||||
if (globalPropertyValue) {
|
||||
// get the property values from a global user/platform config
|
||||
let configVal = GlobalIonicConfig.setting(prop);
|
||||
if (configVal) {
|
||||
instance[prop] = globalPropertyValue;
|
||||
continue;
|
||||
}
|
||||
|
||||
// get the property values provided by this mode/platform
|
||||
var modePropertyValue = null;
|
||||
if (modePropertyValue) {
|
||||
instance[prop] = modePropertyValue;
|
||||
continue;
|
||||
}
|
||||
|
||||
// wasn't set yet, so go with property's default value
|
||||
instance[prop] = defaultProperties[prop];
|
||||
}
|
||||
@@ -92,8 +82,14 @@ function appendModeConfig(ComponentType) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!platformMode) {
|
||||
platformMode = GlobalIonicConfig.setting('mode');
|
||||
}
|
||||
|
||||
let id = config.classId || (config.selector && config.selector.replace('ion-', ''));
|
||||
config.host['class'] = (id + ' ' + id + '-' + platformMode);
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
let platformMode = null;
|
||||
|
||||
@@ -1,9 +1,123 @@
|
||||
import {isString, isObject, isDefined} from '../util/util';
|
||||
|
||||
|
||||
export class IonicConfig {
|
||||
|
||||
constructor() {
|
||||
this.canWe = true;
|
||||
constructor(settings={}) {
|
||||
this._settings = settings;
|
||||
this._settings.platforms = this._settings.platforms || {};
|
||||
}
|
||||
|
||||
platform(val) {
|
||||
if (arguments.length) {
|
||||
this._platform = val;
|
||||
}
|
||||
return this._platform;
|
||||
}
|
||||
|
||||
setting() {
|
||||
const args = arguments;
|
||||
const arg0 = args[0];
|
||||
const arg1 = args[1];
|
||||
const arg2 = args[2];
|
||||
const arg3 = args[3];
|
||||
const argLength = args.length;
|
||||
|
||||
let s = this._settings;
|
||||
|
||||
if (argLength === 0) {
|
||||
// setting() = get settings object
|
||||
return s;
|
||||
|
||||
} else if (argLength === 1) {
|
||||
// setting({...}) = set settings object
|
||||
// setting('key') = get value
|
||||
|
||||
if (isObject(arg0)) {
|
||||
// setting({...}) = set settings object
|
||||
// arg0 = setting object
|
||||
s = arg0;
|
||||
|
||||
} else if (isString(arg0)) {
|
||||
// setting('key') = get value
|
||||
// arg0 = key
|
||||
return s[arg0]
|
||||
}
|
||||
|
||||
} else if (argLength === 2) {
|
||||
// setting('key', 'value') = set key/value pair
|
||||
// arg0 = key
|
||||
// arg1 = value
|
||||
s[arg0] = arg1;
|
||||
|
||||
} else if (argLength > 2) {
|
||||
// create platform object and platformKey object if needed
|
||||
// arg0 = key
|
||||
// arg1 = platform key
|
||||
s.platforms = s.platforms || {};
|
||||
s.platforms[arg1] = s.platforms[arg1] || {};
|
||||
|
||||
if (argLength === 3) {
|
||||
// setting('key', 'ios', 'value') = set key/value pair for platform
|
||||
// arg0 = key
|
||||
// arg1 = platform key
|
||||
// arg2 = value
|
||||
s.platforms[arg1][arg0] = arg2;
|
||||
|
||||
} else if (argLength === 4) {
|
||||
// setting('key', 'ios', 'ipad', 'value') = set key/value pair for platform/device
|
||||
// arg0 = key
|
||||
// arg1 = platform key
|
||||
// arg2 = device key
|
||||
// arg3 = value
|
||||
s.platforms[arg1] = s.platforms[arg1] || {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (arguments.length > 1) {
|
||||
this._settings[key] = val;
|
||||
|
||||
} else {
|
||||
// 1) user platform settings
|
||||
// 2) user settings
|
||||
// 3) platform settings
|
||||
let tmp = null;
|
||||
|
||||
if (this._platform) {
|
||||
tmp = this.platformSetting( this._platform.name() );
|
||||
if (isDefined(tmp)) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = this._settings[key];
|
||||
if (util.isDefined(tmp)) {
|
||||
return tmp;
|
||||
}
|
||||
|
||||
if (this._platform) {
|
||||
return this._platform.setting(key);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
platformSettings(platformName, platformSettings) {
|
||||
let settings = this._settings.platforms[platformName] = this._settings.platforms[platformName] || {};
|
||||
if (arguments.length > 1) {
|
||||
settings = platformSettings || {};
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
platformSetting(platformName, key, val) {
|
||||
let settings = this._settings.platforms[platformName] = this._settings.platforms[platformName] || {};
|
||||
if (arguments.length > 2) {
|
||||
settings[key] = val;
|
||||
}
|
||||
return settings[key];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user