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

@ -121,8 +121,7 @@ class FadeIn extends Animation {
this this
.easing('ease') .easing('ease')
.duration(250) .duration(250)
.fadeIn() .fadeIn();
.before.addClass('show-modal');
} }
} }
@ -134,8 +133,7 @@ class FadeOut extends Animation {
this this
.easing('ease') .easing('ease')
.duration(250) .duration(250)
.fadeOut() .fadeOut();
.after.removeClass('show-modal');
} }
} }

View File

@ -175,6 +175,10 @@ export function main(ionicBootstrap) {
console.log('isRTL', app.isRTL()) console.log('isRTL', app.isRTL())
console.log('lang', app.lang()) console.log('lang', app.lang())
Platform.ready().then(() => {
console.log('Platform.ready')
});
}); });
} }

View File

@ -1,4 +1,5 @@
import * as util from '../util/util'; import * as util from '../util/util';
import * as dom from '../util/dom';
export class PlatformCtrl { export class PlatformCtrl {
@ -10,6 +11,29 @@ export class PlatformCtrl {
this._default = null; 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) { url(val) {
if (arguments.length) { if (arguments.length) {
this._url = val; 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) { width(val) {
if (arguments.length) { if (arguments.length) {
this._w = val; this._w = val;
@ -71,6 +87,10 @@ export class PlatformCtrl {
return this._h || 0; return this._h || 0;
} }
// Registry
// **********************************************
register(platformConfig) { register(platformConfig) {
this._registry[platformConfig.name] = platformConfig; this._registry[platformConfig.name] = platformConfig;
} }
@ -83,6 +103,14 @@ export class PlatformCtrl {
this._default = platformName; this._default = platformName;
} }
isPlatform(queryValue, userAgentExpression) {
if (!userAgentExpression) {
userAgentExpression = queryValue;
}
return (this.matchQuery(queryValue)) ||
(this.matchUserAgent(userAgentExpression) !== null);
}
load() { load() {
let rootPlatformNode = null; let rootPlatformNode = null;
let engineNode = null; let engineNode = null;
@ -128,6 +156,10 @@ export class PlatformCtrl {
engineNode.child(rootPlatformNode); engineNode.child(rootPlatformNode);
rootPlatformNode.parent(engineNode); rootPlatformNode.parent(engineNode);
rootPlatformNode = 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; let platformNode = rootPlatformNode;
@ -136,6 +168,14 @@ export class PlatformCtrl {
platformNode = platformNode.child(); 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; platformNode = rootPlatformNode;
while (platformNode) { while (platformNode) {
// set the array of active platforms with // set the array of active platforms with
@ -202,7 +242,9 @@ function insertSuperset(platformNode) {
let supersetPlatform = new PlatformNode(supersetPlaformName); let supersetPlatform = new PlatformNode(supersetPlaformName);
supersetPlatform.parent(platformNode.parent()); supersetPlatform.parent(platformNode.parent());
supersetPlatform.child(platformNode); supersetPlatform.child(platformNode);
if (supersetPlatform.parent()) {
supersetPlatform.parent().child(supersetPlatform); supersetPlatform.parent().child(supersetPlatform);
}
platformNode.parent(supersetPlatform); platformNode.parent(supersetPlatform);
} }
} }
@ -227,6 +269,10 @@ class PlatformNode {
return this.c.superset; return this.c.superset;
} }
methods() {
return this.c.methods || {};
}
parent(val) { parent(val) {
if (arguments.length) { if (arguments.length) {
this._parent = val; this._parent = val;

View File

@ -121,16 +121,15 @@ Platform.register({
name: 'cordova', name: 'cordova',
isEngine: true, isEngine: true,
methods: { methods: {
onReady: function() { ready: function() {
return Platform.windowLoad().then(() => {
return new Promise(resolve => { return new Promise(resolve => {
setTimeout(function() { document.addEventListener("deviceready", resolve);
resolve(); });
}, 1000);
}); });
} }
}, },
isMatch(p) { isMatch(p) {
return true;
return !!(window.cordova || window.PhoneGap || window.phonegap); return !!(window.cordova || window.PhoneGap || window.phonegap);
} }
}); });

View File

@ -29,8 +29,6 @@ export function rafPromise() {
return new Promise(resolve => raf(resolve)); return new Promise(resolve => raf(resolve));
} }
export const isSVG = val => window.SVGElement && (val instanceof window.SVGElement);
export let CSS = {}; export let CSS = {};
(function() { (function() {
// transform // transform
@ -116,7 +114,7 @@ function cssPromise(el:Element, eventNames, animationName) {
export function ready() { export function ready() {
return new Promise(resolve => { return new Promise(resolve => {
if (document.readyState === 'complete' || document.readyState === 'interactive') { if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(resolve); resolve();
} else { } else {
@ -135,7 +133,7 @@ export function ready() {
export function windowLoad() { export function windowLoad() {
return new Promise(resolve => { return new Promise(resolve => {
if (document.readyState === 'complete') { if (document.readyState === 'complete') {
setTimeout(resolve); resolve();
} else { } else {
function completed() { function completed() {
@ -147,25 +145,3 @@ export function windowLoad() {
} }
}); });
} }
export function hasAttribute(el: Element, attributeName) {
return el.hasAttribute(attributeName);
}
export function addClass(el: Element, ...classNames) {
for (let c of classNames) {
el.classList.add(c);
}
}
export function getChildIndex(el: Element) {
let child;
let parent = el.parentNode;
for(let i = 0, j = parent.children.length; i < j; i++) {
child = parent.children[i];
if(child === el) {
return i;
}
}
return -1;
}

View File

@ -1,24 +0,0 @@
/**
* TODO: Wait until the new ElementRef stuff lands in Angular2.
import {RenderedElement} from 'ionic/util/render/element';
export class DomRenderedElement extends RenderedElement {
constructor(domElement: Element) {
super(domElement)
}
removeClass(className) {
this.element.classList.remove(classList);
}
addClass(...classNames) {
for(let c of classNames) {
this.element.classList.add(c);
}
}
removeClass(...classNames) {
for(let c of classes) {
this.element.classList.remove(c);
}
}
}
*/

View File

@ -1,15 +0,0 @@
/**
* TODO: Wait until the new ElementRef stuff lands in Angular2
export class RenderedElement {
constructor(element) {
this.element = element;
}
_notImplemented(fnName) {
console.error("RenderedElement." + fnName + "addClass is not implemented. Use a concrete class like DomRenderedElement instead.");
}
addClass(...classNames) { this._notImplemented('addClass'); }
removeClass(className) { this._notImplemented('removeClass'); }
removeClasses(...classNames) { this._notImplemented('removeClasses'); }
}
*/