mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
checking in
This commit is contained in:
@ -42,30 +42,30 @@ export class IonicApp {
|
||||
return this._ua;
|
||||
}
|
||||
|
||||
matchesQuery(queryKey, queryValue) {
|
||||
const val = this.query(queryKey);
|
||||
return !!(val && val == queryValue);
|
||||
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) {
|
||||
const rx = new RegExp(userAgentExpression, 'i');
|
||||
let rx = new RegExp(userAgentExpression, 'i');
|
||||
return rx.test(this._ua);
|
||||
}
|
||||
|
||||
matchesPlatform(platformQueryValue, platformUserAgentExpression) {
|
||||
if (!platformUserAgentExpression) {
|
||||
platformUserAgentExpression = platformQueryValue;
|
||||
matchesPlatform(queryValue, userAgentExpression) {
|
||||
if (!userAgentExpression) {
|
||||
userAgentExpression = queryValue;
|
||||
}
|
||||
return this.matchesQuery('ionicplatform', platformQueryValue) ||
|
||||
this.matchesUserAgent(platformUserAgentExpression);
|
||||
}
|
||||
|
||||
matchesDevice(deviceQueryValue, deviceUserAgentExpression) {
|
||||
if (!deviceUserAgentExpression) {
|
||||
deviceUserAgentExpression = deviceQueryValue;
|
||||
}
|
||||
return this.matchesQuery('ionicdevice', deviceQueryValue) ||
|
||||
this.matchesUserAgent(deviceUserAgentExpression);
|
||||
return this.matchesQuery(queryValue) ||
|
||||
this.matchesUserAgent(userAgentExpression);
|
||||
}
|
||||
|
||||
width(val) {
|
||||
@ -143,7 +143,7 @@ export function ionicBootstrap(ComponentType, config) {
|
||||
app.width(window.innerWidth);
|
||||
app.height(window.innerHeight);
|
||||
|
||||
let platform = Platform.getActivePlatform(app);
|
||||
let platform = Platform.create(app);
|
||||
|
||||
config = config || new IonicConfig();
|
||||
config.platform(platform);
|
||||
@ -159,8 +159,7 @@ export function ionicBootstrap(ComponentType, config) {
|
||||
bootstrap(ComponentType, injectableBindings).then(appRef => {
|
||||
app.ref(appRef);
|
||||
|
||||
let rootPlatform = platform.root();
|
||||
rootPlatform.runAll();
|
||||
platform.run();
|
||||
|
||||
resolve({
|
||||
app,
|
||||
|
@ -155,25 +155,16 @@ export function main(ionicBootstrap) {
|
||||
'tabBarPlacement': 'adam'
|
||||
});
|
||||
|
||||
// myConfig.platform('ios', {
|
||||
// 'tabBarPlacement': 'ios'
|
||||
// });
|
||||
|
||||
// myConfig.device('ipad', {
|
||||
// 'tabBarPlacement': 'ipad'
|
||||
// });
|
||||
|
||||
// myConfig.platform('android', {
|
||||
// 'tabBarPlacement': 'android'
|
||||
// });
|
||||
|
||||
ionicBootstrap(MyApp, myConfig).then(root => {
|
||||
|
||||
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'))
|
||||
|
||||
});
|
||||
}
|
||||
|
@ -6,9 +6,7 @@ export * from 'ionic/config/ionic-view'
|
||||
export * from 'ionic/components'
|
||||
|
||||
export * from 'ionic/platform/platform'
|
||||
// export * from 'ionic/platform/core'
|
||||
// export * from 'ionic/platform/android'
|
||||
// export * from 'ionic/platform/ios'
|
||||
export * from 'ionic/platform/registry'
|
||||
|
||||
export * from 'ionic/routing/router'
|
||||
|
||||
|
@ -1,90 +1,97 @@
|
||||
import * as util from '../util/util';
|
||||
import {Tap} from '../util/tap';
|
||||
|
||||
let platformRegistry = {};
|
||||
let defaultPlatform;
|
||||
let activePlatform;
|
||||
|
||||
export class Platform {
|
||||
|
||||
load(platformName) {
|
||||
this._c = Platform.get(platformName);
|
||||
constructor() {
|
||||
this._settings = {};
|
||||
this._platforms = [];
|
||||
}
|
||||
|
||||
name() {
|
||||
return this._c.name;
|
||||
is(platformName) {
|
||||
return (this._platforms.indexOf(platformName) > -1);
|
||||
}
|
||||
|
||||
settings() {
|
||||
return this._c.settings || {};
|
||||
settings(val) {
|
||||
if (arguments.length) {
|
||||
this._settings = val;
|
||||
}
|
||||
|
||||
subsets() {
|
||||
return this._c.subsets || [];
|
||||
return this._settings;
|
||||
}
|
||||
|
||||
run() {
|
||||
this._c.run && this._c.run();
|
||||
let config = null;
|
||||
|
||||
for (var i = 0; i < this._platforms.length; i++) {
|
||||
config = Platform.get(this._platforms[i]);
|
||||
config.run && config.run();
|
||||
}
|
||||
}
|
||||
|
||||
parent(val) {
|
||||
if (arguments.length) {
|
||||
this._parent = val;
|
||||
}
|
||||
return this._parent;
|
||||
add(platformName) {
|
||||
this._platforms.push(platformName);
|
||||
}
|
||||
|
||||
child(val) {
|
||||
if (arguments.length) {
|
||||
this._child = val;
|
||||
}
|
||||
return this._child;
|
||||
|
||||
/* Static Methods */
|
||||
static create(app) {
|
||||
let rootNode = null;
|
||||
|
||||
function matchPlatform(platformConfig) {
|
||||
let platformNode = new PlatformNode();
|
||||
platformNode.config(platformConfig);
|
||||
let tmpPlatform = platformNode.getRoot(app, 0);
|
||||
|
||||
if (tmpPlatform) {
|
||||
tmpPlatform.depth = 0;
|
||||
let childPlatform = tmpPlatform.child();
|
||||
while(childPlatform) {
|
||||
tmpPlatform.depth++
|
||||
childPlatform = childPlatform.child();
|
||||
}
|
||||
|
||||
isMatch(app) {
|
||||
if (!this._c.isMatch) {
|
||||
return true;
|
||||
}
|
||||
return this._c.isMatch(app);
|
||||
}
|
||||
|
||||
getRoot(app, childPlatform) {
|
||||
if (this.isMatch(app)) {
|
||||
let parents = Platform.getSubsetParents(this.name());
|
||||
|
||||
if (!parents.length) {
|
||||
platform = new Platform();
|
||||
platform.load(this.name());
|
||||
platform.child(childPlatform);
|
||||
return platform;
|
||||
}
|
||||
|
||||
let platform = null;
|
||||
let rootPlatform = null;
|
||||
|
||||
for (let i = 0; i < parents.length; i++) {
|
||||
platform = new Platform();
|
||||
platform.load(parents[i]);
|
||||
platform.child(this);
|
||||
|
||||
rootPlatform = platform.getRoot(app, this);
|
||||
if (rootPlatform) {
|
||||
this.parent(platform);
|
||||
return rootPlatform;
|
||||
if (!rootNode || tmpPlatform.depth > rootNode.depth) {
|
||||
rootNode = tmpPlatform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
function insertSuperset(platformNode) {
|
||||
let supersetPlaformName = platformNode.superset();
|
||||
if (supersetPlaformName) {
|
||||
let supersetPlatform = new PlatformNode();
|
||||
supersetPlatform.load(supersetPlaformName);
|
||||
supersetPlatform.parent(platformNode.parent());
|
||||
supersetPlatform.child(platformNode);
|
||||
supersetPlatform.parent().child(supersetPlatform);
|
||||
platformNode.parent(supersetPlatform);
|
||||
}
|
||||
}
|
||||
|
||||
for (let platformName in platformRegistry) {
|
||||
matchPlatform( platformRegistry[platformName] );
|
||||
}
|
||||
|
||||
static getActivePlatform(app) {
|
||||
let platform = new Platform();
|
||||
platform.load('tablet');
|
||||
if (rootNode) {
|
||||
let platformNode = rootNode.child();
|
||||
while (platformNode) {
|
||||
insertSuperset(platformNode);
|
||||
platformNode = platformNode.child();
|
||||
}
|
||||
|
||||
let root = platform.getRoot(app, null);
|
||||
console.log(root)
|
||||
platformNode = rootNode.child();
|
||||
let settings = {};
|
||||
while (platformNode) {
|
||||
platform.add(platformNode.name());
|
||||
util.extend(settings, platformNode.settings());
|
||||
platformNode = platformNode.child();
|
||||
}
|
||||
|
||||
platform.settings(settings);
|
||||
}
|
||||
|
||||
return platform;
|
||||
}
|
||||
|
||||
static register(platform) {
|
||||
@ -109,116 +116,93 @@ export class Platform {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PlatformNode {
|
||||
|
||||
load(platformName) {
|
||||
this._c = Platform.get(platformName);
|
||||
}
|
||||
|
||||
config(val) {
|
||||
this._c = val;
|
||||
}
|
||||
|
||||
settings() {
|
||||
return this._c.settings || {};
|
||||
}
|
||||
|
||||
name() {
|
||||
return this._c.name;
|
||||
}
|
||||
|
||||
superset() {
|
||||
return this._c.superset;
|
||||
}
|
||||
|
||||
runAll() {
|
||||
let platform = this;
|
||||
while (platform) {
|
||||
platform.run();
|
||||
platform = platform.child();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
parent(val) {
|
||||
if (arguments.length) {
|
||||
this._parent = val;
|
||||
}
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
child(val) {
|
||||
if (arguments.length) {
|
||||
this._child = val;
|
||||
}
|
||||
return this._child;
|
||||
}
|
||||
|
||||
isMatch(app) {
|
||||
if (typeof this._c._isMatched !== 'boolean') {
|
||||
// only do the actual check once
|
||||
if (!this._c.isMatch) {
|
||||
this._c._isMatched = true;
|
||||
} else {
|
||||
this._c._isMatched = this._c.isMatch(app);
|
||||
}
|
||||
}
|
||||
return this._c._isMatched;
|
||||
}
|
||||
|
||||
getRoot(app) {
|
||||
if (this.isMatch(app)) {
|
||||
|
||||
let parents = Platform.getSubsetParents(this.name());
|
||||
|
||||
if (!parents.length) {
|
||||
return this;
|
||||
}
|
||||
|
||||
let platform = null;
|
||||
let rootPlatform = null;
|
||||
|
||||
for (let i = 0; i < parents.length; i++) {
|
||||
platform = new PlatformNode();
|
||||
platform.load(parents[i]);
|
||||
platform.child(this);
|
||||
|
||||
Platform.register({
|
||||
name: 'core',
|
||||
subsets: [
|
||||
'mobile'
|
||||
],
|
||||
settings: {
|
||||
mode: 'a'
|
||||
},
|
||||
run() {
|
||||
console.log('Core');
|
||||
rootPlatform = platform.getRoot(app);
|
||||
if (rootPlatform) {
|
||||
this.parent(platform);
|
||||
return rootPlatform;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'mobile',
|
||||
subsets: [
|
||||
'android',
|
||||
'ios'
|
||||
],
|
||||
settings: {
|
||||
mode: 'b'
|
||||
},
|
||||
run() {
|
||||
console.log('Mobile');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'android',
|
||||
subsets: [
|
||||
'tablet'
|
||||
],
|
||||
settings: {
|
||||
mode: 'c'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('android');
|
||||
},
|
||||
run() {
|
||||
console.log('Android');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'tablet',
|
||||
settings: {
|
||||
mode: 'd'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.height() >= 800 || app.width() >= 800;
|
||||
},
|
||||
run() {
|
||||
console.log('Tablet');
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'ios',
|
||||
subsets: [
|
||||
'ipad',
|
||||
'iphone'
|
||||
],
|
||||
settings: {
|
||||
mode: 'e'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('ios');
|
||||
},
|
||||
run() {
|
||||
console.log('iOS');
|
||||
Tap.run();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'ipad',
|
||||
subsets: [
|
||||
'tablet'
|
||||
],
|
||||
settings: {
|
||||
mode: 'f'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesDevice('ipad');
|
||||
},
|
||||
run() {
|
||||
console.log('iPad');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'iphone',
|
||||
settings: {
|
||||
mode: 'g'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesDevice('iphone');
|
||||
},
|
||||
run() {
|
||||
console.log('iPhone');
|
||||
}
|
||||
});
|
||||
|
||||
let platformRegistry = {};
|
||||
|
||||
|
@ -1,155 +0,0 @@
|
||||
// import * as util from '../util/util';
|
||||
// import {IonicConfig} from '../config/config';
|
||||
|
||||
|
||||
// let platformRegistry = {};
|
||||
|
||||
// export class Platform extends IonicConfig {
|
||||
|
||||
// constructor(settings={}) {
|
||||
// super(settings);
|
||||
// this._chld = {};
|
||||
// this._parent = null;
|
||||
// }
|
||||
|
||||
// parent(val) {
|
||||
// if (arguments.length) {
|
||||
// this._parent = val;
|
||||
// }
|
||||
// return this._parent;
|
||||
// }
|
||||
|
||||
// app(val) {
|
||||
// if (arguments.length) {
|
||||
// this._app = val;
|
||||
// }
|
||||
// return this._app;
|
||||
// }
|
||||
|
||||
// name(val) {
|
||||
// if (arguments.length) {
|
||||
// this._name = val;
|
||||
// }
|
||||
// return this._name;
|
||||
// }
|
||||
|
||||
// is(platformName, climbToRoot) {
|
||||
// if (this._name == platformName) {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// let platform = null;
|
||||
|
||||
// if (climbToRoot !== false) {
|
||||
// platform = this._parent
|
||||
// while (platform) {
|
||||
// if (platform.name() == platformName) {
|
||||
// return true;
|
||||
// }
|
||||
// platform = platform._parent;
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (let childPlatform in this._chld) {
|
||||
// platform = this._chld[childPlatform];
|
||||
// platform.app(this._app);
|
||||
// if (platform.is(platformName, false) == platform.isMatch()) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// matchesQuery(queryKey, queryValue) {
|
||||
// const qs = this._app.query()[queryKey];
|
||||
// return !!(qs && qs == queryValue);
|
||||
// }
|
||||
|
||||
// matchesUserAgent(userAgentExpression) {
|
||||
// const rx = new RegExp(userAgentExpression, 'i');
|
||||
// return rx.test( this._app.userAgent() );
|
||||
// }
|
||||
|
||||
// matchesPlatform(platformQueryValue, platformUserAgentExpression) {
|
||||
// return this.matchesQuery('ionicplatform', platformQueryValue) ||
|
||||
// this.matchesUserAgent(platformUserAgentExpression);
|
||||
// }
|
||||
|
||||
// matchesDevice(deviceQueryValue, deviceUserAgentExpression) {
|
||||
// return this.matchesQuery('ionicdevice', deviceQueryValue) ||
|
||||
// this.matchesUserAgent(deviceUserAgentExpression);
|
||||
// }
|
||||
|
||||
// registerChild(platformName, PlatformClass) {
|
||||
// let platform = new PlatformClass();
|
||||
// platform.name(platformName);
|
||||
// platform.parent(this);
|
||||
// this._chld[platformName] = platform;
|
||||
// }
|
||||
|
||||
// root() {
|
||||
// let rootPlatform = this;
|
||||
// while (rootPlatform._parent) {
|
||||
// rootPlatform = rootPlatform._parent;
|
||||
// }
|
||||
// return rootPlatform;
|
||||
// }
|
||||
|
||||
// runAll() {
|
||||
// let platform = null;
|
||||
|
||||
// if (this.isMatch()) {
|
||||
// this.run();
|
||||
|
||||
// for (let childPlatform in this._chld) {
|
||||
// this._chld[childPlatform].app(this._app);
|
||||
// this._chld[childPlatform].runAll();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// getActive() {
|
||||
// let platform = null;
|
||||
|
||||
// if (this.isMatch()) {
|
||||
// for (let childPlatform in this._chld) {
|
||||
// this._chld[childPlatform].app(this._app);
|
||||
// platform = this._chld[childPlatform].getActive();
|
||||
// if (platform) {
|
||||
// return platform;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// return null;
|
||||
// }
|
||||
|
||||
|
||||
// /* Methods to Override */
|
||||
// isMatch() { return true; }
|
||||
// run() {}
|
||||
|
||||
|
||||
// /* Static Methods */
|
||||
// static register(platformName, PlatformClass) {
|
||||
// basePlatform.registerChild(platformName, PlatformClass);
|
||||
// }
|
||||
|
||||
// static getActivePlatform(app) {
|
||||
// basePlatform.app(app);
|
||||
// return basePlatform.getActive(app);
|
||||
// }
|
||||
|
||||
// static setBase(PlatformClass) {
|
||||
// basePlatform = new PlatformClass();
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// let basePlatform = null;
|
||||
|
||||
|
||||
console.log('')
|
113
ionic/platform/registry.js
Normal file
113
ionic/platform/registry.js
Normal file
@ -0,0 +1,113 @@
|
||||
import {Platform} from './platform';
|
||||
import {Tap} from '../util/tap';
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'core',
|
||||
subsets: [
|
||||
'android',
|
||||
'ios',
|
||||
'windowsphone'
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'mobile'
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'phablet',
|
||||
isMatch(app) {
|
||||
let smallest = Math.min(app.width(), app.height());
|
||||
let largest = Math.max(app.width(), app.height());
|
||||
// http://www.mydevice.io/devices/
|
||||
return (smallest > 390 && smallest < 520) &&
|
||||
(largest > 620 && largest < 800);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'tablet',
|
||||
isMatch(app) {
|
||||
let smallest = Math.min(app.width(), app.height());
|
||||
let largest = Math.max(app.width(), app.height());
|
||||
// http://www.mydevice.io/devices/
|
||||
return (smallest > 460 && smallest < 820) &&
|
||||
(largest > 780 && largest < 1400);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'android',
|
||||
superset: 'mobile',
|
||||
subsets: [
|
||||
'phablet',
|
||||
'tablet'
|
||||
],
|
||||
settings: {
|
||||
mode: 'md'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('android');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'ios',
|
||||
superset: 'mobile',
|
||||
subsets: [
|
||||
'ipad',
|
||||
'iphone'
|
||||
],
|
||||
settings: {
|
||||
mode: 'ios'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('ios');
|
||||
},
|
||||
run() {
|
||||
Tap.run();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'ipad',
|
||||
superset: 'tablet',
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('ipad');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'iphone',
|
||||
subsets: [
|
||||
'phablet'
|
||||
],
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('iphone');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Platform.register({
|
||||
name: 'windowsphone',
|
||||
superset: 'mobile',
|
||||
subsets: [
|
||||
'phablet',
|
||||
'tablet'
|
||||
],
|
||||
settings: {
|
||||
mode: 'wp'
|
||||
},
|
||||
isMatch(app) {
|
||||
return app.matchesPlatform('windowsphone', 'windows phone');
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user