mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
click block updates
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import {raf} from './dom'
|
||||
|
||||
|
||||
const CSS_CLICK_BLOCK = 'click-block-active';
|
||||
const DEFAULT_EXPIRE = 330;
|
||||
let cbEle, fallbackTimerId, pendingShow;
|
||||
|
||||
function preventClick(ev) {
|
||||
@ -8,26 +11,40 @@ function preventClick(ev) {
|
||||
}
|
||||
|
||||
function show(expire) {
|
||||
pendingShow = true;
|
||||
clearTimeout(fallbackTimerId);
|
||||
fallbackTimerId = setTimeout(hide, expire || 320);
|
||||
|
||||
if (cbEle) {
|
||||
cbEle.classList.add(CSS_CLICK_BLOCK);
|
||||
|
||||
} else {
|
||||
cbEle = document.createElement('div');
|
||||
cbEle.className = 'click-block ' + CSS_CLICK_BLOCK;
|
||||
document.body.appendChild(cbEle);
|
||||
cbEle.addEventListener('touchstart', preventClick);
|
||||
cbEle.addEventListener('mousedown', preventClick);
|
||||
}
|
||||
fallbackTimerId = setTimeout(hide, expire || DEFAULT_EXPIRE);
|
||||
raf(addBlock);
|
||||
}
|
||||
|
||||
function hide() {
|
||||
pendingShow = false;
|
||||
clearTimeout(fallbackTimerId);
|
||||
cbEle && cbEle.classList.remove(CSS_CLICK_BLOCK);
|
||||
raf(removeBlock);
|
||||
}
|
||||
|
||||
function addBlock() {
|
||||
if (pendingShow) {
|
||||
|
||||
if (cbEle) {
|
||||
cbEle.classList.add(CSS_CLICK_BLOCK);
|
||||
|
||||
} else {
|
||||
cbEle = document.createElement('div');
|
||||
cbEle.className = 'click-block ' + CSS_CLICK_BLOCK;
|
||||
document.body.appendChild(cbEle);
|
||||
cbEle.addEventListener('touchstart', preventClick);
|
||||
cbEle.addEventListener('mousedown', preventClick);
|
||||
}
|
||||
pendingShow = false;
|
||||
}
|
||||
}
|
||||
|
||||
function removeBlock() {
|
||||
if (!pendingShow) {
|
||||
cbEle && cbEle.classList.remove(CSS_CLICK_BLOCK);
|
||||
}
|
||||
}
|
||||
|
||||
export let ClickBlock = function(shouldShow, expire) {
|
||||
|
||||
|
Reference in New Issue
Block a user