platform/app updates

This commit is contained in:
Adam Bradley
2015-06-26 08:49:44 -05:00
parent 5db5b66373
commit ef82b00f45
5 changed files with 183 additions and 173 deletions

View File

@ -43,67 +43,6 @@ export class IonicApp {
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;
}
matchQuery(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;
}
matchUserAgent(userAgentExpression) {
if (this._ua) {
let rx = new RegExp(userAgentExpression, 'i');
return rx.exec(this._ua);
}
}
isPlatform(queryValue, userAgentExpression) {
if (!userAgentExpression) {
userAgentExpression = queryValue;
}
return (this.matchQuery(queryValue)) ||
(this.matchUserAgent(userAgentExpression) !== null);
}
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.
@ -154,13 +93,27 @@ export class IonicApp {
return this._ref;
}
applyCss(platform, config) {
let className = document.body.className;
applyCss(bodyEle, platform, config) {
let className = bodyEle.className;
platform.platforms().forEach(platformName => {
className += ' platform-' + platformName;
});
className += ' mode-' + config.setting('mode');
document.body.className = className.trim();
bodyEle.className = className.trim();
}
isRTL(val) {
if (arguments.length) {
this._rtl = val;
}
return this._rtl;
}
lang(val) {
if (arguments.length) {
this._lang = val;
}
return this._lang;
}
}
@ -168,24 +121,24 @@ export class IonicApp {
export function ionicBootstrap(ComponentType, config) {
return new Promise((resolve, reject) => {
try {
let app = new IonicApp();
app.url(window.location.href);
app.userAgent(window.navigator.userAgent);
app.width(window.innerWidth);
app.height(window.innerHeight);
let platform = Platform.load(app);
// create the base IonicApp
let app = initApp(window, document)
// get the user config, or create one if wasn't passed in
config = config || new IonicConfig();
// copy default platform settings into the user config platform settings
// user config platform settings should override default platform settings
config.setPlatform(platform);
app.applyCss(platform, config)
config.setPlatform(Platform);
// make the config global
GlobalIonicConfig = config;
// config and platform settings have been figured out
// apply the correct CSS to the app
app.applyCss(document.body, Platform, config)
// add injectables that will be available to all child components
let injectableBindings = [
bind(IonicApp).toValue(app),
bind(IonicConfig).toValue(config)
@ -193,14 +146,7 @@ export function ionicBootstrap(ComponentType, config) {
bootstrap(ComponentType, injectableBindings).then(appRef => {
app.ref(appRef);
platform.run();
resolve({
app,
config,
platform
});
resolve(app);
}).catch(err => {
console.error('ionicBootstrap', err);
@ -214,6 +160,23 @@ export function ionicBootstrap(ComponentType, config) {
});
}
function initApp(window, document) {
// create the base IonicApp
let app = new IonicApp();
app.isRTL(document.documentElement.getAttribute('dir') == 'rtl');
app.lang(document.documentElement.getAttribute('lang'));
// load all platform data
// Platform is a global singleton
Platform.url(window.location.href);
Platform.userAgent(window.navigator.userAgent);
Platform.width(window.innerWidth);
Platform.height(window.innerHeight);
Platform.load();
return app;
}
export let GlobalIonicConfig = null;
export function load(app) {

View File

@ -4,7 +4,7 @@ import {Component, Directive} from 'angular2/src/core/annotations_impl/annotatio
import {View} from 'angular2/src/core/annotations_impl/view';
import {Parent, Ancestor} from 'angular2/src/core/annotations_impl/visibility';
import {IonicView, IonicConfig} from 'ionic/ionic';
import {IonicView, IonicConfig, Platform} from 'ionic/ionic';
import {IonicComponent} from 'ionic/ionic';
import {Modal, NavController, NavParams, Animation, ActionMenu} from 'ionic/ionic';
@ -17,7 +17,7 @@ import {Modal, NavController, NavParams, Animation, ActionMenu} from 'ionic/ioni
@IonicView({
templateUrl: 'main.html'
})
class MyApp {
class MyAppCmp {
constructor(Modal: Modal) {
this.Modal = Modal;
@ -152,25 +152,28 @@ export function main(ionicBootstrap) {
let myConfig = new IonicConfig();
//myConfig.setting('someKey', 'userConfig');
// myConfig.setting('someKey', 'userConfig');
// myConfig.setting('ios', 'someKey', 'iosConfig');
// myConfig.setting('ipad', 'someKey', 'ipadConfig');
ionicBootstrap(MyApp, myConfig).then(root => {
ionicBootstrap(MyAppCmp, myConfig).then(app => {
console.log('platforms', root.platform.platforms());
console.log('platforms', Platform.platforms());
console.log('mode', myConfig.setting('mode'));
console.log('core', root.platform.is('core'))
console.log('cordova', root.platform.is('cordova'))
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'))
console.log('core', Platform.is('core'))
console.log('cordova', Platform.is('cordova'))
console.log('mobile', Platform.is('mobile'))
console.log('ipad', Platform.is('ipad'))
console.log('iphone', Platform.is('iphone'))
console.log('phablet', Platform.is('phablet'))
console.log('tablet', Platform.is('tablet'))
console.log('ios', Platform.is('ios'))
console.log('android', Platform.is('android'))
console.log('windows phone', Platform.is('windowsphone'))
console.log('isRTL', app.isRTL())
console.log('lang', app.lang())
});
}