mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
engine now Engine, platform now Platform
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import {Component, View, bootstrap} from 'angular2/angular2'
|
||||
import {Tabs, Tab} from 'ionic/ionic'
|
||||
import {engine} from 'ionic/engine/engine'
|
||||
import {Engine} from 'ionic/engine/engine'
|
||||
import * as util from 'ionic/util'
|
||||
|
||||
|
||||
@ -13,18 +13,18 @@ class IonicApp {
|
||||
constructor() {
|
||||
console.log('IonicApp Start');
|
||||
|
||||
console.log(engine.getName(), engine.is('cordova'));
|
||||
console.log(Engine.getName(), Engine.is('cordova'));
|
||||
|
||||
engine.ready().then(() => {
|
||||
console.log('engine ready')
|
||||
Engine.ready().then(() => {
|
||||
console.log('Engine ready')
|
||||
});
|
||||
|
||||
engine.fullScreen(true).then((isShown) => {
|
||||
console.log('fullScreen', isShown)
|
||||
Engine.fullScreen(true).then((isShown) => {
|
||||
console.log('Engine fullScreen', isShown)
|
||||
});
|
||||
|
||||
engine.showStatusBar(true).then((isShown) => {
|
||||
console.log('showStatusBar', isShown)
|
||||
Engine.showStatusBar(true).then((isShown) => {
|
||||
console.log('Engine showStatusBar', isShown)
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import {BackButton} from 'ionic/components/toolbar/back-button';
|
||||
import {IonicComponent} from 'ionic/config/component';
|
||||
import {NavController} from 'ionic/components/nav/nav-item';
|
||||
import {raf} from 'ionic/util/dom';
|
||||
import {platform} from 'ionic/platform/platform';
|
||||
import {Platform} from 'ionic/platform/platform';
|
||||
|
||||
|
||||
// FYI for later:
|
||||
@ -47,7 +47,7 @@ export class Toolbar {
|
||||
|
||||
// TODO use config to add these classes
|
||||
this.viewContainer.domElement.classList.add('toolbar');
|
||||
this.viewContainer.domElement.classList.add(`toolbar-${platform.getMode()}`);
|
||||
this.viewContainer.domElement.classList.add(`toolbar-${Platform.getMode()}`);
|
||||
|
||||
// TODO Make a better way than this
|
||||
if (/header/i.test(this.viewContainer.domElement.tagName)) {
|
||||
|
@ -1,188 +0,0 @@
|
||||
import {platform} from 'ionic/platform/platform'
|
||||
import * as util from 'ionic/util'
|
||||
|
||||
|
||||
/*
|
||||
let MyConfig = new ComponentConfig(MyComponent)
|
||||
MyConfig.classes('classes')
|
||||
MyConfig.delegate('gesture')
|
||||
.when({side: 'left'}, LeftAsideGesture)
|
||||
.when({side: 'right'}, RightAsideGesture)
|
||||
.when({side: 'top'}, TopAsideGesture)
|
||||
.when({side: 'bottom'}, BottomAsideGesture)
|
||||
*/
|
||||
export function ComponentConfig(componentCssName) {
|
||||
let platformName = platform.get().name;
|
||||
return class Config {
|
||||
static classes() {
|
||||
Config.classProperties || (Config.classProperties = [])
|
||||
Config.classProperties.push.apply(Config.classProperties, arguments)
|
||||
return Config
|
||||
}
|
||||
static delegate(delegateName) {
|
||||
let self = {
|
||||
when(condition, DelegateConstructor) {
|
||||
Config.addCase(delegateName, condition, DelegateConstructor)
|
||||
return self
|
||||
}
|
||||
}
|
||||
return self
|
||||
}
|
||||
static platform(name, Class) {
|
||||
Config.platformFns = Config.platformFns || []
|
||||
if (name === platformName) {
|
||||
Config.platformFns.unshift(Class)
|
||||
}
|
||||
return Config
|
||||
}
|
||||
static addCase(delegateName, condition, DelegateConstructor) {
|
||||
Config.registry || (Config.registry = {})
|
||||
var array = (Config.registry[delegateName] || (Config.registry[delegateName] = []))
|
||||
|
||||
let callback = condition
|
||||
if (util.isObject(callback)) {
|
||||
// Support eg `{side: 'left'}` as a condition
|
||||
callback = (instance) => {
|
||||
for (let key in condition) {
|
||||
if (condition.hasOwnProperty(key) && instance[key] !== condition[key]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
array.unshift({ callback, DelegateConstructor })
|
||||
}
|
||||
|
||||
create(instance) {
|
||||
instance.domElement.classList.add(componentCssName)
|
||||
instance.domElement.classList.add(`${componentCssName}-${platformName}`)
|
||||
for (let i = 0; i < (Config.classProperties || []).length; i++) {
|
||||
let propertyValue = instance[Config.classProperties[i]]
|
||||
instance.domElement.classList.add(`${componentCssName}-${propertyValue}`)
|
||||
}
|
||||
for (let i = 0; i < (Config.platformFns || []).length; i++) {
|
||||
new Config.platformFns[i](instance)
|
||||
}
|
||||
return {
|
||||
getDelegate(delegateName) {
|
||||
let registry = Config.registry && Config.registry[delegateName] || []
|
||||
for (let i = 0; i < registry.length; i++) {
|
||||
let condition = registry[i]
|
||||
if (condition.callback(instance)) {
|
||||
return new condition.DelegateConstructor(instance)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// TODO stop hardcoding platforms and media sizes
|
||||
|
||||
/*
|
||||
@ConfigPlatform({
|
||||
for: AsideBase
|
||||
platform: 'android',
|
||||
defaults: {
|
||||
type: 'reveal'
|
||||
}
|
||||
})
|
||||
class AndroidAside extends AsideBase {}
|
||||
|
||||
```@ConfigCase({
|
||||
for: AsideBase,
|
||||
condition: instance => instance.type === 'reveal'
|
||||
})
|
||||
class AsideReveal {
|
||||
constructor(aside: AsideBase) {}
|
||||
}
|
||||
*/
|
||||
|
||||
// export class Config extends ConfigCase {
|
||||
// constructor() {
|
||||
// this._root = this
|
||||
// this._cases = {}
|
||||
// super({
|
||||
// root: this,
|
||||
// parent: null,
|
||||
// path: ''
|
||||
// })
|
||||
// }
|
||||
// invoke(instance) {
|
||||
// return invokeConfig(this, instance)
|
||||
// }
|
||||
// _addCase(key, baseCase) {
|
||||
// let path = baseCase._path.slice()
|
||||
// path.push(key)
|
||||
|
||||
// // Remove empties & duplicates
|
||||
// path = path
|
||||
// .filter((value, index) => {
|
||||
// return value && path.indexOf(value) === index
|
||||
// })
|
||||
// .sort()
|
||||
|
||||
// if (path.join(' ') === baseCase._path.join(' ')) {
|
||||
// return baseCase
|
||||
// }
|
||||
// return this._createCase(path)
|
||||
// }
|
||||
// _createCase(path) {
|
||||
// if (!path.length) return this
|
||||
// let pathStr = path.join(' ')
|
||||
// let configCase = this._cases[pathStr]
|
||||
// if (!configCase) {
|
||||
// let parentPath = path.slice(0, path.length - 1)
|
||||
// configCase = this._cases[pathStr] = new ConfigCase({
|
||||
// root: this,
|
||||
// parent: this._createCase(parentPath),
|
||||
// path: path
|
||||
// })
|
||||
// }
|
||||
// return configCase
|
||||
// }
|
||||
// }
|
||||
|
||||
// export function invokeConfig(config, object) {
|
||||
// let platformName = platform.get().name
|
||||
|
||||
// let passedCases = [config].concat(
|
||||
// Object.keys(config._cases)
|
||||
// .map(name => config._cases[name])
|
||||
// .filter(configCasePasses)
|
||||
// .sort(function(a,b) {
|
||||
// return a._path.length < b._path.length ? -1 : 1
|
||||
// })
|
||||
// )
|
||||
|
||||
// // Extend the given object with the values of all the passed cases, starting with the
|
||||
// // most specific.
|
||||
// let defaults = [object]
|
||||
// // Also find the most specific case with a component that we should use.
|
||||
// let ComponentToUse
|
||||
// for (let i = 0, ii = passedCases.length i < ii i++) {
|
||||
// defaults.push(passedCases[i]._values)
|
||||
// if (passedCases[i]._component) {
|
||||
// ComponentToUse = passedCases[i]._component
|
||||
// }
|
||||
// }
|
||||
|
||||
// util.defaults.apply(null, defaults)
|
||||
|
||||
// return ComponentToUse
|
||||
|
||||
// function configCasePasses(configCase) {
|
||||
// let path = configCase._path
|
||||
// let key
|
||||
// for (let i = 0, ii = path.length i < ii i++) {
|
||||
// if (platformName !== path[i]) return false
|
||||
// }
|
||||
// return true
|
||||
// }
|
||||
|
||||
// }
|
@ -1,7 +1,7 @@
|
||||
import * as util from 'ionic/util'
|
||||
import {platform} from 'ionic/platform/platform'
|
||||
import {Platform} from 'ionic/platform/platform'
|
||||
|
||||
let platformMode = platform.getMode()
|
||||
let platformMode = Platform.getMode();
|
||||
|
||||
// Low-level: how the user will override
|
||||
// BackButton.config.bind.icon.value = 'ion-chevron-right'
|
||||
|
4
ionic/engine/cordova/cordova.js
vendored
4
ionic/engine/cordova/cordova.js
vendored
@ -1,7 +1,7 @@
|
||||
import {engine} from '../engine';
|
||||
import {Engine} from '../engine';
|
||||
|
||||
|
||||
engine.register({
|
||||
Engine.register({
|
||||
name: 'cordova',
|
||||
isMatch() {
|
||||
return !(!window.cordova && !window.PhoneGap && !window.phonegap);
|
||||
|
@ -1,8 +1,8 @@
|
||||
import * as util from 'ionic/util';
|
||||
import {engine} from '../engine';
|
||||
import {Engine} from '../engine';
|
||||
|
||||
|
||||
engine.register({
|
||||
Engine.register({
|
||||
name: 'electron',
|
||||
isMatch() {
|
||||
try {
|
||||
|
@ -42,16 +42,16 @@ class EngineController {
|
||||
return activeEngine || defaultEngine;
|
||||
}
|
||||
|
||||
set(eng) {
|
||||
activeEngine = eng;
|
||||
set(engine) {
|
||||
activeEngine = engine;
|
||||
}
|
||||
|
||||
setDefault(eng) {
|
||||
defaultEngine = eng;
|
||||
setDefault(engine) {
|
||||
defaultEngine = engine;
|
||||
}
|
||||
|
||||
register(eng) {
|
||||
registry[eng.name] = eng;
|
||||
register(engine) {
|
||||
registry[engine.name] = engine;
|
||||
}
|
||||
|
||||
detect() {
|
||||
@ -65,9 +65,9 @@ class EngineController {
|
||||
|
||||
}
|
||||
|
||||
export let engine = new EngineController();
|
||||
export let Engine = new EngineController();
|
||||
|
||||
engine.setDefault({
|
||||
Engine.setDefault({
|
||||
name: 'default',
|
||||
ready: util.dom.windowLoad
|
||||
});
|
||||
|
@ -51,14 +51,14 @@ class PlatformController {
|
||||
}
|
||||
}
|
||||
|
||||
export let platform = new PlatformController();
|
||||
export let Platform = new PlatformController();
|
||||
|
||||
|
||||
const ua = window.navigator.userAgent;
|
||||
const queryPlatform = (util.getQuerystring('ionicplatform')).toLowerCase()
|
||||
|
||||
|
||||
platform.register({
|
||||
Platform.register({
|
||||
name: 'android',
|
||||
mode: 'md',
|
||||
isMatch() {
|
||||
@ -66,7 +66,7 @@ platform.register({
|
||||
}
|
||||
});
|
||||
|
||||
platform.register({
|
||||
Platform.register({
|
||||
name: 'ios',
|
||||
isMatch() {
|
||||
return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua)
|
||||
@ -74,8 +74,8 @@ platform.register({
|
||||
});
|
||||
|
||||
// Last case is a catch-all
|
||||
platform.setDefault({
|
||||
Platform.setDefault({
|
||||
name: 'core'
|
||||
});
|
||||
|
||||
platform.set( platform.detect() );
|
||||
Platform.set( Platform.detect() );
|
||||
|
Reference in New Issue
Block a user