click block updates

This commit is contained in:
Adam Bradley
2015-05-06 10:35:40 -05:00
parent 604a11cd7a
commit e36d48fdfc
3 changed files with 31 additions and 15 deletions

View File

@ -19,5 +19,6 @@ import {
export class Content { export class Content {
constructor() { constructor() {
this.contentClass = true; this.contentClass = true;
console.log('Content!');
} }
} }

View File

@ -195,8 +195,6 @@ export class NavBase {
// allow clicks again // allow clicks again
ClickBlock(false); ClickBlock(false);
console.log('transition, canSwipeBack()', this.canSwipeBack());
// resolve that this push has completed // resolve that this push has completed
resolve(); resolve();
}); });

View File

@ -1,5 +1,8 @@
import {raf} from './dom'
const CSS_CLICK_BLOCK = 'click-block-active'; const CSS_CLICK_BLOCK = 'click-block-active';
const DEFAULT_EXPIRE = 330;
let cbEle, fallbackTimerId, pendingShow; let cbEle, fallbackTimerId, pendingShow;
function preventClick(ev) { function preventClick(ev) {
@ -8,26 +11,40 @@ function preventClick(ev) {
} }
function show(expire) { function show(expire) {
pendingShow = true;
clearTimeout(fallbackTimerId); clearTimeout(fallbackTimerId);
fallbackTimerId = setTimeout(hide, expire || 320); fallbackTimerId = setTimeout(hide, expire || DEFAULT_EXPIRE);
raf(addBlock);
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);
}
} }
function hide() { function hide() {
pendingShow = false;
clearTimeout(fallbackTimerId); 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) { export let ClickBlock = function(shouldShow, expire) {