Platform.ready() for excellence

This commit is contained in:
Adam Bradley
2015-06-26 10:49:03 -05:00
parent ef82b00f45
commit 69e7d7c69f
7 changed files with 68 additions and 84 deletions

View File

@ -1,4 +1,5 @@
import * as util from '../util/util';
import * as dom from '../util/dom';
export class PlatformCtrl {
@ -10,6 +11,29 @@ export class PlatformCtrl {
this._default = null;
}
// Methods
// **********************************************
ready() {
// no ready method was provided by an engine
// fallback to use dom ready instead
// if a ready method was provide then it would
// override the default method
return dom.ready();
}
domReady() {
return dom.ready();
}
windowLoad() {
return dom.windowLoad();
}
// Properties
// **********************************************
url(val) {
if (arguments.length) {
this._url = val;
@ -49,14 +73,6 @@ export class PlatformCtrl {
}
}
isPlatform(queryValue, userAgentExpression) {
if (!userAgentExpression) {
userAgentExpression = queryValue;
}
return (this.matchQuery(queryValue)) ||
(this.matchUserAgent(userAgentExpression) !== null);
}
width(val) {
if (arguments.length) {
this._w = val;
@ -71,6 +87,10 @@ export class PlatformCtrl {
return this._h || 0;
}
// Registry
// **********************************************
register(platformConfig) {
this._registry[platformConfig.name] = platformConfig;
}
@ -83,6 +103,14 @@ export class PlatformCtrl {
this._default = platformName;
}
isPlatform(queryValue, userAgentExpression) {
if (!userAgentExpression) {
userAgentExpression = queryValue;
}
return (this.matchQuery(queryValue)) ||
(this.matchUserAgent(userAgentExpression) !== null);
}
load() {
let rootPlatformNode = null;
let engineNode = null;
@ -128,6 +156,10 @@ export class PlatformCtrl {
engineNode.child(rootPlatformNode);
rootPlatformNode.parent(engineNode);
rootPlatformNode = engineNode;
// add any events which the engine would provide
// for example, Cordova provides its own ready event
util.extend(this, engineNode.methods());
}
let platformNode = rootPlatformNode;
@ -136,6 +168,14 @@ export class PlatformCtrl {
platformNode = platformNode.child();
}
// make sure the root noot is actually the root
// incase a node was inserted before the root
platformNode = rootPlatformNode.parent();
while (platformNode) {
rootPlatformNode = platformNode;
platformNode = platformNode.parent();
}
platformNode = rootPlatformNode;
while (platformNode) {
// set the array of active platforms with
@ -202,7 +242,9 @@ function insertSuperset(platformNode) {
let supersetPlatform = new PlatformNode(supersetPlaformName);
supersetPlatform.parent(platformNode.parent());
supersetPlatform.child(platformNode);
supersetPlatform.parent().child(supersetPlatform);
if (supersetPlatform.parent()) {
supersetPlatform.parent().child(supersetPlatform);
}
platformNode.parent(supersetPlatform);
}
}
@ -227,6 +269,10 @@ class PlatformNode {
return this.c.superset;
}
methods() {
return this.c.methods || {};
}
parent(val) {
if (arguments.length) {
this._parent = val;