Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 5x 5x 5x 5x 4x 4x 4x 4x 4x 4x 4x 2x 1x 2x 1x 4x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x | class SwipeJsListener { constructor() { this.xDown = null; this.yDown = null; this.callbackFuncObj = {}; this.ctx = null; }; _onTouchStart = (evt) => { this.xDown = evt.touches[0].clientX; this.yDown = evt.touches[0].clientY; }; _onTouchMove = (evt) => { var isInTest = typeof window.alert === 'function'; Iif (!isInTest && (!this.xDown || !this.yDown)) return; const xDiff = this.xDown - evt.touches[0].clientX; const yDiff = this.yDown - evt.touches[0].clientY; if (Math.abs(xDiff) > Math.abs(yDiff)) { if (xDiff > 0 && Object.prototype.hasOwnProperty.call(this.callbackFuncObj, 'callbackToSwipeLeft')) this.callbackFuncObj.callbackToSwipeLeft.call(this.ctx); else Eif (Object.prototype.hasOwnProperty.call(this.callbackFuncObj, 'callbackToSwipeRight')) this.callbackFuncObj.callbackToSwipeRight.call(this.ctx); } else { if (yDiff > 0 && Object.prototype.hasOwnProperty.call(this.callbackFuncObj, 'callbackToSwipeUp')) this.callbackFuncObj.callbackToSwipeUp.call(this.ctx); else Eif (Object.prototype.hasOwnProperty.call(this.callbackFuncObj, 'callbackToSwipeDown')) this.callbackFuncObj.callbackToSwipeDown.call(this.ctx); } this.xDown = null; this.yDown = null; }; addSwipeListener = (ctx, callbackFuncObj) => { this.xDown = null; this.yDown = null; this.callbackFuncObj = callbackFuncObj; this.ctx = ctx; window.addEventListener('touchstart', this._onTouchStart); window.addEventListener('touchmove', this._onTouchMove); }; removeSwipeListener = () => { this.xDown = null; this.yDown = null; this.callbackFuncObj = {}; this.ctx = null; window.removeEventListener('touchstart', this._onTouchStart); window.removeEventListener('touchmove', this._onTouchMove); }; } Eif (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { module.exports = SwipeJsListener; } else { if (typeof define === 'function' && define.amd) { define([], function() { return SwipeJsListener; }); } else { window.SwipeJsListener = SwipeJsListener; } } |