mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
Platform.ready() for excellence
This commit is contained in:
@ -121,8 +121,7 @@ class FadeIn extends Animation {
|
||||
this
|
||||
.easing('ease')
|
||||
.duration(250)
|
||||
.fadeIn()
|
||||
.before.addClass('show-modal');
|
||||
.fadeIn();
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,8 +133,7 @@ class FadeOut extends Animation {
|
||||
this
|
||||
.easing('ease')
|
||||
.duration(250)
|
||||
.fadeOut()
|
||||
.after.removeClass('show-modal');
|
||||
.fadeOut();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,6 +175,10 @@ export function main(ionicBootstrap) {
|
||||
console.log('isRTL', app.isRTL())
|
||||
console.log('lang', app.lang())
|
||||
|
||||
Platform.ready().then(() => {
|
||||
console.log('Platform.ready')
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -121,16 +121,15 @@ Platform.register({
|
||||
name: 'cordova',
|
||||
isEngine: true,
|
||||
methods: {
|
||||
onReady: function() {
|
||||
return new Promise(resolve => {
|
||||
setTimeout(function() {
|
||||
resolve();
|
||||
}, 1000);
|
||||
ready: function() {
|
||||
return Platform.windowLoad().then(() => {
|
||||
return new Promise(resolve => {
|
||||
document.addEventListener("deviceready", resolve);
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
isMatch(p) {
|
||||
return true;
|
||||
return !!(window.cordova || window.PhoneGap || window.phonegap);
|
||||
}
|
||||
});
|
||||
|
@ -29,8 +29,6 @@ export function rafPromise() {
|
||||
return new Promise(resolve => raf(resolve));
|
||||
}
|
||||
|
||||
export const isSVG = val => window.SVGElement && (val instanceof window.SVGElement);
|
||||
|
||||
export let CSS = {};
|
||||
(function() {
|
||||
// transform
|
||||
@ -116,7 +114,7 @@ function cssPromise(el:Element, eventNames, animationName) {
|
||||
export function ready() {
|
||||
return new Promise(resolve => {
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||
setTimeout(resolve);
|
||||
resolve();
|
||||
|
||||
} else {
|
||||
|
||||
@ -135,7 +133,7 @@ export function ready() {
|
||||
export function windowLoad() {
|
||||
return new Promise(resolve => {
|
||||
if (document.readyState === 'complete') {
|
||||
setTimeout(resolve);
|
||||
resolve();
|
||||
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
@ -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'); }
|
||||
}
|
||||
|
||||
*/
|
Reference in New Issue
Block a user