mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
add tapPolyfill setting
This commit is contained in:
@ -118,6 +118,23 @@ export class IonicApp {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initApp(window, document) {
|
||||||
|
// create the base IonicApp
|
||||||
|
let app = new IonicApp();
|
||||||
|
app.isRTL(document.documentElement.getAttribute('dir') == 'rtl');
|
||||||
|
app.lang(document.documentElement.getAttribute('lang'));
|
||||||
|
|
||||||
|
// load all platform data
|
||||||
|
// Platform is a global singleton
|
||||||
|
Platform.url(window.location.href);
|
||||||
|
Platform.userAgent(window.navigator.userAgent);
|
||||||
|
Platform.width(window.innerWidth);
|
||||||
|
Platform.height(window.innerHeight);
|
||||||
|
Platform.load();
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
export function ionicBootstrap(ComponentType, config) {
|
export function ionicBootstrap(ComponentType, config) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
@ -146,6 +163,11 @@ export function ionicBootstrap(ComponentType, config) {
|
|||||||
|
|
||||||
bootstrap(ComponentType, injectableBindings).then(appRef => {
|
bootstrap(ComponentType, injectableBindings).then(appRef => {
|
||||||
app.ref(appRef);
|
app.ref(appRef);
|
||||||
|
|
||||||
|
// prepare the ready promise to fire....when ready
|
||||||
|
Platform.prepareReady(config);
|
||||||
|
|
||||||
|
// resolve that the app has loaded
|
||||||
resolve(app);
|
resolve(app);
|
||||||
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
@ -160,25 +182,6 @@ export function ionicBootstrap(ComponentType, config) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initApp(window, document) {
|
|
||||||
// create the base IonicApp
|
|
||||||
let app = new IonicApp();
|
|
||||||
app.isRTL(document.documentElement.getAttribute('dir') == 'rtl');
|
|
||||||
app.lang(document.documentElement.getAttribute('lang'));
|
|
||||||
|
|
||||||
// load all platform data
|
|
||||||
// Platform is a global singleton
|
|
||||||
Platform.url(window.location.href);
|
|
||||||
Platform.userAgent(window.navigator.userAgent);
|
|
||||||
Platform.width(window.innerWidth);
|
|
||||||
Platform.height(window.innerHeight);
|
|
||||||
Platform.load();
|
|
||||||
|
|
||||||
return app;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let GlobalIonicConfig = null;
|
|
||||||
|
|
||||||
export function load(app) {
|
export function load(app) {
|
||||||
if (!app) {
|
if (!app) {
|
||||||
console.error('Invalid app module');
|
console.error('Invalid app module');
|
||||||
@ -190,3 +193,5 @@ export function load(app) {
|
|||||||
app.main(ionicBootstrap);
|
app.main(ionicBootstrap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let GlobalIonicConfig = null;
|
||||||
|
@ -11,6 +11,8 @@ export class PlatformCtrl {
|
|||||||
this._default = null;
|
this._default = null;
|
||||||
this._vMajor = 0;
|
this._vMajor = 0;
|
||||||
this._vMinor = 0;
|
this._vMinor = 0;
|
||||||
|
|
||||||
|
this._readyPromise = new Promise(res => { this._readyResolve = res; } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -40,20 +42,35 @@ export class PlatformCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ready() {
|
ready() {
|
||||||
// if a ready method was provided then it would
|
return this._readyPromise;
|
||||||
// override this default method
|
}
|
||||||
// fallback to use dom ready by default
|
|
||||||
return dom.ready();
|
prepareReady(config) {
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
function resolve() {
|
||||||
|
self._readyResolve(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._engineReady) {
|
||||||
|
// the engine provide a ready promise, use this instead
|
||||||
|
this._engineReady(resolve);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// there is no custom ready method from the engine
|
||||||
|
// use the default dom ready
|
||||||
|
dom.ready(resolve);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
domReady() {
|
domReady() {
|
||||||
// helper method so its easy to access on Platform
|
// convenience method so its easy to access on Platform
|
||||||
return dom.ready();
|
return dom.ready.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
windowLoad() {
|
windowLoad() {
|
||||||
// helper method so its easy to access on Platform
|
// convenience method so its easy to access on Platform
|
||||||
return dom.windowLoad();
|
return dom.windowLoad.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -198,7 +215,10 @@ export class PlatformCtrl {
|
|||||||
|
|
||||||
// add any events which the engine would provide
|
// add any events which the engine would provide
|
||||||
// for example, Cordova provides its own ready event
|
// for example, Cordova provides its own ready event
|
||||||
util.extend(this, engineNode.methods());
|
let engineMethods = engineNode.methods();
|
||||||
|
engineMethods._engineReady = engineMethods.ready;
|
||||||
|
delete engineMethods.ready;
|
||||||
|
util.extend(this, engineMethods);
|
||||||
}
|
}
|
||||||
|
|
||||||
let platformNode = rootPlatformNode;
|
let platformNode = rootPlatformNode;
|
||||||
|
@ -66,7 +66,8 @@ Platform.register({
|
|||||||
'iphone'
|
'iphone'
|
||||||
],
|
],
|
||||||
settings: {
|
settings: {
|
||||||
mode: 'ios'
|
mode: 'ios',
|
||||||
|
tapPolyfill: true
|
||||||
},
|
},
|
||||||
isMatch(p) {
|
isMatch(p) {
|
||||||
// SLEDGEHAMMER OVERRIDE FOR NOW
|
// SLEDGEHAMMER OVERRIDE FOR NOW
|
||||||
@ -121,12 +122,10 @@ Platform.register({
|
|||||||
name: 'cordova',
|
name: 'cordova',
|
||||||
isEngine: true,
|
isEngine: true,
|
||||||
methods: {
|
methods: {
|
||||||
ready: function() {
|
ready: function(resolve) {
|
||||||
return Platform.windowLoad().then(() => {
|
Platform.windowLoad(() => {
|
||||||
return new Promise(resolve => {
|
|
||||||
document.addEventListener("deviceready", resolve);
|
document.addEventListener("deviceready", resolve);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isMatch(p) {
|
isMatch(p) {
|
||||||
|
@ -111,37 +111,50 @@ function cssPromise(el:Element, eventNames, animationName) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ready() {
|
export function ready(callback) {
|
||||||
return new Promise(resolve => {
|
let promise = null;
|
||||||
|
|
||||||
|
if (!callback) {
|
||||||
|
// a callback wasn't provided, so let's return a promise instead
|
||||||
|
promise = new Promise(resolve => { callback = resolve; });
|
||||||
|
}
|
||||||
|
|
||||||
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||||
resolve();
|
callback();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
function completed() {
|
function completed() {
|
||||||
document.removeEventListener('DOMContentLoaded', completed, false);
|
document.removeEventListener('DOMContentLoaded', completed, false);
|
||||||
window.removeEventListener('load', completed, false);
|
window.removeEventListener('load', completed, false);
|
||||||
resolve();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', completed, false);
|
document.addEventListener('DOMContentLoaded', completed, false);
|
||||||
window.addEventListener('load', completed, false);
|
window.addEventListener('load', completed, false);
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function windowLoad(callback) {
|
||||||
|
let promise = null;
|
||||||
|
|
||||||
|
if (!callback) {
|
||||||
|
// a callback wasn't provided, so let's return a promise instead
|
||||||
|
promise = new Promise(resolve => { callback = resolve; });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function windowLoad() {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
resolve();
|
callback();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
function completed() {
|
function completed() {
|
||||||
window.removeEventListener('load', completed, false);
|
window.removeEventListener('load', completed, false);
|
||||||
resolve();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('load', completed, false);
|
window.addEventListener('load', completed, false);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return promise;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {dom} from 'ionic/util'
|
import {dom} from './dom'
|
||||||
import {Platform} from 'ionic/platform/platform'
|
import {Platform} from '../platform/platform'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ngdoc page
|
* @ngdoc page
|
||||||
@ -96,27 +96,20 @@ var tapEventListeners = {
|
|||||||
'touchcancel': tapTouchCancel,
|
'touchcancel': tapTouchCancel,
|
||||||
'touchmove': tapTouchMove,
|
'touchmove': tapTouchMove,
|
||||||
|
|
||||||
'pointerdown': tapTouchStart,
|
|
||||||
'pointerup': tapTouchEnd,
|
|
||||||
'pointercancel': tapTouchCancel,
|
|
||||||
'pointermove': tapTouchMove,
|
|
||||||
|
|
||||||
'MSPointerDown': tapTouchStart,
|
|
||||||
'MSPointerUp': tapTouchEnd,
|
|
||||||
'MSPointerCancel': tapTouchCancel,
|
|
||||||
'MSPointerMove': tapTouchMove,
|
|
||||||
|
|
||||||
'focusin': tapFocusIn,
|
'focusin': tapFocusIn,
|
||||||
'focusout': tapFocusOut
|
'focusout': tapFocusOut
|
||||||
};
|
};
|
||||||
|
|
||||||
export let Tap = {
|
Platform.ready().then(config => {
|
||||||
|
|
||||||
run: function() {
|
if (config.setting('tapPolyfill')) {
|
||||||
dom.ready().then(() => {
|
|
||||||
Tap.register(document);
|
Tap.register(document);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
|
export let Tap = {
|
||||||
|
|
||||||
register: function(ele) {
|
register: function(ele) {
|
||||||
tapDoc = ele;
|
tapDoc = ele;
|
||||||
@ -125,23 +118,9 @@ export let Tap = {
|
|||||||
tapEventListener('mouseup');
|
tapEventListener('mouseup');
|
||||||
tapEventListener('mousedown');
|
tapEventListener('mousedown');
|
||||||
|
|
||||||
if (window.navigator.pointerEnabled) {
|
|
||||||
tapEventListener('pointerdown');
|
|
||||||
tapEventListener('pointerup');
|
|
||||||
tapEventListener('pointcancel');
|
|
||||||
tapTouchMoveListener = 'pointermove';
|
|
||||||
|
|
||||||
} else if (window.navigator.msPointerEnabled) {
|
|
||||||
tapEventListener('MSPointerDown');
|
|
||||||
tapEventListener('MSPointerUp');
|
|
||||||
tapEventListener('MSPointerCancel');
|
|
||||||
tapTouchMoveListener = 'MSPointerMove';
|
|
||||||
|
|
||||||
} else {
|
|
||||||
tapEventListener('touchstart');
|
tapEventListener('touchstart');
|
||||||
tapEventListener('touchend');
|
tapEventListener('touchend');
|
||||||
tapEventListener('touchcancel');
|
tapEventListener('touchcancel');
|
||||||
}
|
|
||||||
|
|
||||||
tapEventListener('focusin');
|
tapEventListener('focusin');
|
||||||
tapEventListener('focusout');
|
tapEventListener('focusout');
|
||||||
@ -179,7 +158,7 @@ export let Tap = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
isKeyboardElement: function(ele) {
|
isKeyboardElement: function(ele) {
|
||||||
if ( !Platform.is('ios') || Platform.isDevice('ipad') ) {
|
if (Platform.isDevice('ipad') ) {
|
||||||
return Tap.isTextInput(ele) && !Tap.isDateInput(ele);
|
return Tap.isTextInput(ele) && !Tap.isDateInput(ele);
|
||||||
} else {
|
} else {
|
||||||
return Tap.isTextInput(ele) || ( !!ele && ele.tagName == "SELECT");
|
return Tap.isTextInput(ele) || ( !!ele && ele.tagName == "SELECT");
|
||||||
@ -431,7 +410,7 @@ function tapTouchStart(e) {
|
|||||||
// TODO(mlynch): re-enable
|
// TODO(mlynch): re-enable
|
||||||
//ionic.activator.start(e);
|
//ionic.activator.start(e);
|
||||||
|
|
||||||
if (Platform.is('ios') && Tap.isLabelWithTextInput(e.target)) {
|
if (Tap.isLabelWithTextInput(e.target)) {
|
||||||
// if the tapped element is a label, which has a child input
|
// if the tapped element is a label, which has a child input
|
||||||
// then preventDefault so iOS doesn't ugly auto scroll to the input
|
// then preventDefault so iOS doesn't ugly auto scroll to the input
|
||||||
// but do not prevent default on Android or else you cannot move the text caret
|
// but do not prevent default on Android or else you cannot move the text caret
|
||||||
|
Reference in New Issue
Block a user