mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
refactor(clickBlock): add to dom on init
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
import {Title} from 'angular2/angular2';
|
import {Title} from 'angular2/angular2';
|
||||||
|
|
||||||
import {rafFrames} from '../../util/dom';
|
import {rafFrames} from '../../util/dom';
|
||||||
import {ClickBlock} from '../../util/click-block';
|
|
||||||
import {ScrollTo} from '../../animations/scroll-to';
|
import {ScrollTo} from '../../animations/scroll-to';
|
||||||
|
|
||||||
|
|
||||||
@ -11,11 +10,12 @@ import {ScrollTo} from '../../animations/scroll-to';
|
|||||||
*/
|
*/
|
||||||
export class IonicApp {
|
export class IonicApp {
|
||||||
|
|
||||||
constructor(config) {
|
constructor(config, clickBlock) {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._titleSrv = new Title();
|
this._titleSrv = new Title();
|
||||||
this._title = '';
|
this._title = '';
|
||||||
this._disTime = 0;
|
this._disTime = 0;
|
||||||
|
this._clickBlock = clickBlock;
|
||||||
|
|
||||||
// Our component registry map
|
// Our component registry map
|
||||||
this.components = {};
|
this.components = {};
|
||||||
@ -49,9 +49,7 @@ export class IonicApp {
|
|||||||
*/
|
*/
|
||||||
setEnabled(isEnabled, fallback=700) {
|
setEnabled(isEnabled, fallback=700) {
|
||||||
this._disTime = (isEnabled ? 0 : Date.now() + fallback);
|
this._disTime = (isEnabled ? 0 : Date.now() + fallback);
|
||||||
if (this._config.get('clickBlock')) {
|
this._clickBlock.show(!isEnabled, fallback + 100);
|
||||||
ClickBlock(!isEnabled, fallback + 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,8 @@ import {Translate} from '../translation/translate';
|
|||||||
import {ClickBlock} from '../util/click-block';
|
import {ClickBlock} from '../util/click-block';
|
||||||
import {FeatureDetect} from '../util/feature-detect';
|
import {FeatureDetect} from '../util/feature-detect';
|
||||||
import {initTapClick} from '../components/tap-click/tap-click';
|
import {initTapClick} from '../components/tap-click/tap-click';
|
||||||
import * as dom from '../util/dom';
|
import {ClickBlock} from '../util/click-block';
|
||||||
|
import {ready, closest} from '../util/dom';
|
||||||
|
|
||||||
|
|
||||||
export function ionicProviders(args={}) {
|
export function ionicProviders(args={}) {
|
||||||
@ -36,13 +37,15 @@ export function ionicProviders(args={}) {
|
|||||||
platform.load();
|
platform.load();
|
||||||
config.setPlatform(platform);
|
config.setPlatform(platform);
|
||||||
|
|
||||||
let app = new IonicApp(config);
|
let clickBlock = new ClickBlock(config.get('clickBlock'));
|
||||||
|
|
||||||
|
let app = new IonicApp(config, clickBlock);
|
||||||
|
|
||||||
let events = new Events();
|
let events = new Events();
|
||||||
initTapClick(window, document, app, config);
|
initTapClick(window, document, app, config);
|
||||||
let featureDetect = new FeatureDetect();
|
let featureDetect = new FeatureDetect();
|
||||||
|
|
||||||
setupDom(window, document, config, platform, featureDetect);
|
setupDom(window, document, config, platform, clickBlock, featureDetect);
|
||||||
bindEvents(window, document, platform, events);
|
bindEvents(window, document, platform, events);
|
||||||
|
|
||||||
// prepare the ready promise to fire....when ready
|
// prepare the ready promise to fire....when ready
|
||||||
@ -69,10 +72,10 @@ export function ionicProviders(args={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setupDom(window, document, config, platform, featureDetect) {
|
function setupDom(window, document, config, platform, clickBlock, featureDetect) {
|
||||||
let bodyEle = document.body;
|
let bodyEle = document.body;
|
||||||
if (!bodyEle) {
|
if (!bodyEle) {
|
||||||
return dom.ready(function() {
|
return ready(function() {
|
||||||
applyBodyCss(document, config, platform);
|
applyBodyCss(document, config, platform);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -104,6 +107,10 @@ function setupDom(window, document, config, platform, featureDetect) {
|
|||||||
bodyEle.classList.add('enable-hover');
|
bodyEle.classList.add('enable-hover');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.get('clickBlock')) {
|
||||||
|
clickBlock.enable();
|
||||||
|
}
|
||||||
|
|
||||||
// run feature detection tests
|
// run feature detection tests
|
||||||
featureDetect.run(window, document);
|
featureDetect.run(window, document);
|
||||||
}
|
}
|
||||||
@ -131,7 +138,7 @@ function bindEvents(window, document, platform, events) {
|
|||||||
var el = document.elementFromPoint(platform.width() / 2, platform.height() / 2);
|
var el = document.elementFromPoint(platform.width() / 2, platform.height() / 2);
|
||||||
if(!el) { return; }
|
if(!el) { return; }
|
||||||
|
|
||||||
var content = dom.closest(el, 'scroll-content');
|
var content = closest(el, 'scroll-content');
|
||||||
if(content) {
|
if(content) {
|
||||||
var scrollTo = new ScrollTo(content);
|
var scrollTo = new ScrollTo(content);
|
||||||
scrollTo.start(0, 0, 300, 0);
|
scrollTo.start(0, 0, 300, 0);
|
||||||
|
@ -3,9 +3,31 @@ const DEFAULT_EXPIRE = 330;
|
|||||||
let cbEle, fallbackTimerId;
|
let cbEle, fallbackTimerId;
|
||||||
let isShowing = false;
|
let isShowing = false;
|
||||||
|
|
||||||
function disableInput(ev) {
|
|
||||||
ev.preventDefault();
|
export class ClickBlock {
|
||||||
ev.stopPropagation();
|
|
||||||
|
enable() {
|
||||||
|
cbEle = document.createElement('div');
|
||||||
|
cbEle.className = 'click-block';
|
||||||
|
document.body.appendChild(cbEle);
|
||||||
|
cbEle.addEventListener('touchmove', function(ev) {
|
||||||
|
ev.preventDefault();
|
||||||
|
ev.stopPropagation();
|
||||||
|
});
|
||||||
|
this._enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
show(shouldShow, expire) {
|
||||||
|
if (this._enabled) {
|
||||||
|
if (shouldShow) {
|
||||||
|
show(expire);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function show(expire) {
|
function show(expire) {
|
||||||
@ -13,16 +35,8 @@ function show(expire) {
|
|||||||
fallbackTimerId = setTimeout(hide, expire || DEFAULT_EXPIRE);
|
fallbackTimerId = setTimeout(hide, expire || DEFAULT_EXPIRE);
|
||||||
|
|
||||||
if (!isShowing) {
|
if (!isShowing) {
|
||||||
isShowing = true;
|
cbEle.classList.add(CSS_CLICK_BLOCK);
|
||||||
if (cbEle) {
|
isShowing = true;
|
||||||
cbEle.classList.add(CSS_CLICK_BLOCK);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
cbEle = document.createElement('div');
|
|
||||||
cbEle.className = 'click-block ' + CSS_CLICK_BLOCK;
|
|
||||||
document.body.appendChild(cbEle);
|
|
||||||
}
|
|
||||||
cbEle.addEventListener('touchmove', disableInput);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,10 +45,5 @@ function hide() {
|
|||||||
if (isShowing) {
|
if (isShowing) {
|
||||||
cbEle.classList.remove(CSS_CLICK_BLOCK);
|
cbEle.classList.remove(CSS_CLICK_BLOCK);
|
||||||
isShowing = false;
|
isShowing = false;
|
||||||
cbEle.removeEventListener('touchmove', disableInput);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export let ClickBlock = function(shouldShow, expire) {
|
|
||||||
(shouldShow ? show : hide)(expire);
|
|
||||||
};
|
|
||||||
|
Reference in New Issue
Block a user