mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
let there be typescript
This commit is contained in:
34
ionic/util/click-block.ts
Normal file
34
ionic/util/click-block.ts
Normal file
@ -0,0 +1,34 @@
|
||||
const CSS_CLICK_BLOCK = 'click-block-active';
|
||||
const DEFAULT_EXPIRE = 330;
|
||||
let cbEle, fallbackTimerId;
|
||||
let isShowing = false;
|
||||
|
||||
|
||||
function show(expire) {
|
||||
clearTimeout(fallbackTimerId);
|
||||
fallbackTimerId = setTimeout(hide, expire || DEFAULT_EXPIRE);
|
||||
|
||||
if (!isShowing) {
|
||||
isShowing = true;
|
||||
if (cbEle) {
|
||||
cbEle.classList.add(CSS_CLICK_BLOCK);
|
||||
|
||||
} else {
|
||||
cbEle = document.createElement('div');
|
||||
cbEle.className = 'click-block ' + CSS_CLICK_BLOCK;
|
||||
document.body.appendChild(cbEle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hide() {
|
||||
clearTimeout(fallbackTimerId);
|
||||
if (isShowing) {
|
||||
cbEle.classList.remove(CSS_CLICK_BLOCK);
|
||||
isShowing = false;
|
||||
}
|
||||
}
|
||||
|
||||
export let ClickBlock = function(shouldShow, expire) {
|
||||
(shouldShow ? show : hide)(expire);
|
||||
};
|
Reference in New Issue
Block a user