mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Merge branch 'config-wip'
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
import {bootstrap} from 'angular2/angular2';
|
||||
import {AppViewManager} from 'angular2/src/core/compiler/view_manager';
|
||||
import {Component, Directive, onInit} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {View} from 'angular2/src/core/annotations_impl/view';
|
||||
import {ComponentRef, onDestroy, DomRenderer, ApplicationRef} from 'angular2/angular2';
|
||||
import {Promise} from 'angular2/src/facade/async';
|
||||
import {isPresent, Type} from 'angular2/src/facade/lang';
|
||||
import {Compiler} from 'angular2/angular2';
|
||||
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
|
||||
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
|
||||
import {Injector} from 'angular2/di';
|
||||
import {Parent} from 'angular2/src/core/annotations_impl/visibility';
|
||||
import {bind} from 'angular2/di';
|
||||
import {Injectable} from 'angular2/src/di/decorators';
|
||||
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
|
||||
|
||||
import {IonicConfig} from '../../config/config';
|
||||
import {ViewController} from '../view/view-controller';
|
||||
import {Platform} from '../../platform/platform';
|
||||
import * as util from '../../util/util';
|
||||
|
||||
|
||||
export class IonicApp {
|
||||
@@ -24,6 +16,72 @@ export class IonicApp {
|
||||
this.overlays = [];
|
||||
}
|
||||
|
||||
config(val) {
|
||||
if (arguments.length) {
|
||||
this._config = val;
|
||||
}
|
||||
return this._config;
|
||||
}
|
||||
|
||||
url(val) {
|
||||
if (arguments.length) {
|
||||
this._url = val;
|
||||
this._qs = util.getQuerystring(val);
|
||||
}
|
||||
return this._url;
|
||||
}
|
||||
|
||||
query(key) {
|
||||
return (this._qs || {})[key];
|
||||
}
|
||||
|
||||
userAgent(val) {
|
||||
if (arguments.length) {
|
||||
this._ua = val;
|
||||
}
|
||||
return this._ua;
|
||||
}
|
||||
|
||||
matchesQuery(queryValue) {
|
||||
let val = this.query('ionicplatform');
|
||||
if (val) {
|
||||
let valueSplit = val.toLowerCase().split(';');
|
||||
for (let i = 0; i < valueSplit.length; i++) {
|
||||
if (valueSplit[i] == queryValue) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
matchesUserAgent(userAgentExpression) {
|
||||
let rx = new RegExp(userAgentExpression, 'i');
|
||||
return rx.test(this._ua);
|
||||
}
|
||||
|
||||
matchesPlatform(queryValue, userAgentExpression) {
|
||||
if (!userAgentExpression) {
|
||||
userAgentExpression = queryValue;
|
||||
}
|
||||
return this.matchesQuery(queryValue) ||
|
||||
this.matchesUserAgent(userAgentExpression);
|
||||
}
|
||||
|
||||
width(val) {
|
||||
if (arguments.length) {
|
||||
this._w = val;
|
||||
}
|
||||
return this._w || 0;
|
||||
}
|
||||
|
||||
height(val) {
|
||||
if (arguments.length) {
|
||||
this._h = val;
|
||||
}
|
||||
return this._h || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and append the given component into the root
|
||||
* element of the app.
|
||||
@@ -67,9 +125,9 @@ export class IonicApp {
|
||||
});
|
||||
}
|
||||
|
||||
ref() {
|
||||
ref(val) {
|
||||
if (arguments.length) {
|
||||
this._ref = arguments[0];
|
||||
this._ref = val;
|
||||
}
|
||||
return this._ref;
|
||||
}
|
||||
@@ -78,26 +136,55 @@ export class IonicApp {
|
||||
|
||||
export function ionicBootstrap(ComponentType, config) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let app = new IonicApp();
|
||||
config = config || new IonicConfig();
|
||||
try {
|
||||
let app = new IonicApp();
|
||||
app.url(window.location.href);
|
||||
app.userAgent(window.navigator.userAgent);
|
||||
app.width(window.innerWidth);
|
||||
app.height(window.innerHeight);
|
||||
|
||||
let componentInjectableBindings = [
|
||||
bind(IonicApp).toValue(app),
|
||||
bind(IonicConfig).toValue(config)
|
||||
];
|
||||
let platform = Platform.create(app);
|
||||
|
||||
bootstrap(ComponentType, componentInjectableBindings).then(appRef => {
|
||||
app.ref(appRef);
|
||||
resolve(app);
|
||||
config = config || new IonicConfig();
|
||||
|
||||
}).catch(err => {
|
||||
// copy default platform settings into the user config platform settings
|
||||
// user config platform settings should override default platform settings
|
||||
config.setPlatform(platform);
|
||||
|
||||
|
||||
GlobalIonicConfig = config;
|
||||
|
||||
let injectableBindings = [
|
||||
bind(IonicApp).toValue(app),
|
||||
bind(Platform).toValue(platform),
|
||||
bind(IonicConfig).toValue(config)
|
||||
];
|
||||
|
||||
bootstrap(ComponentType, injectableBindings).then(appRef => {
|
||||
app.ref(appRef);
|
||||
|
||||
platform.run();
|
||||
|
||||
resolve({
|
||||
app,
|
||||
config,
|
||||
platform
|
||||
});
|
||||
|
||||
}).catch(err => {
|
||||
console.error('ionicBootstrap', err);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error('ionicBootstrap', err);
|
||||
reject(err);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export let GlobalIonicConfig = null;
|
||||
|
||||
export function load(app) {
|
||||
if (!app) {
|
||||
console.error('Invalid app module');
|
||||
|
||||
@@ -149,12 +149,27 @@ export class ModalSecondPage {
|
||||
}
|
||||
|
||||
export function main(ionicBootstrap) {
|
||||
// crazy config
|
||||
|
||||
let myConfig = new IonicConfig();
|
||||
|
||||
ionicBootstrap(MyApp, myConfig).then(app => {
|
||||
// crazy run
|
||||
console.log('ionicBootstrap', app);
|
||||
//myConfig.setting('someKey', 'userConfig');
|
||||
// myConfig.setting('ios', 'someKey', 'iosConfig');
|
||||
// myConfig.setting('ipad', 'someKey', 'ipadConfig');
|
||||
|
||||
ionicBootstrap(MyApp, myConfig).then(root => {
|
||||
|
||||
console.log('someKey', myConfig.setting('someKey'));
|
||||
console.log(myConfig.setting('mode'));
|
||||
|
||||
console.log('mobile', root.platform.is('mobile'))
|
||||
console.log('ipad', root.platform.is('ipad'))
|
||||
console.log('iphone', root.platform.is('iphone'))
|
||||
console.log('phablet', root.platform.is('phablet'))
|
||||
console.log('tablet', root.platform.is('tablet'))
|
||||
console.log('ios', root.platform.is('ios'))
|
||||
console.log('android', root.platform.is('android'))
|
||||
console.log('windows phone', root.platform.is('windowsphone'))
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user