virtual-scroll
Advanced tools
Comparing version 2.1.1 to 2.2.0
{ | ||
"name": "virtual-scroll", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Custom scroll events for smooth, fake scroll", | ||
@@ -5,0 +5,0 @@ "main": "lib/virtualscroll.js", |
import Emitter from 'tiny-emitter' | ||
import { support } from './support' | ||
import { getSupport } from './support' | ||
import { keyCodes } from './keycodes' | ||
const EVT_ID = 'virtualscroll' | ||
var support | ||
@@ -16,11 +17,2 @@ export default class VirtualScroll { | ||
constructor(options) { | ||
// Make sure these events listeners have the proper context (for both .addEventListener and .removeEventListener) | ||
bindThis([ | ||
'_onWheel', | ||
'_onMouseWheel', | ||
'_onTouchStart', | ||
'_onTouchMove', | ||
'_onKeyDown' | ||
], this) | ||
this.#el = window | ||
@@ -32,2 +24,4 @@ if (options && options.el) { | ||
if (!support) support = getSupport() | ||
this.#options = Object.assign( | ||
@@ -79,3 +73,3 @@ { | ||
_onWheel(e) { | ||
_onWheel = (e) => { | ||
var options = this.#options | ||
@@ -101,3 +95,3 @@ var evt = this.#event | ||
_onMouseWheel(e) { | ||
_onMouseWheel = (e) => { | ||
var evt = this.#event | ||
@@ -112,3 +106,3 @@ | ||
_onTouchStart(e) { | ||
_onTouchStart = (e) => { | ||
var t = e.targetTouches ? e.targetTouches[0] : e | ||
@@ -119,3 +113,3 @@ this.#touchStart.x = t.pageX | ||
_onTouchMove(e) { | ||
_onTouchMove = (e) => { | ||
var options = this.#options | ||
@@ -142,3 +136,3 @@ if ( | ||
_onKeyDown(e) { | ||
_onKeyDown = (e) => { | ||
var evt = this.#event | ||
@@ -262,8 +256,2 @@ evt.deltaX = evt.deltaY = 0 | ||
} | ||
} | ||
function bindThis(fns, ctx) { | ||
fns.forEach(fn => { | ||
ctx[fn] = ctx[fn].bind(ctx) | ||
}) | ||
} | ||
} |
@@ -1,9 +0,11 @@ | ||
export const support = { | ||
hasWheelEvent: 'onwheel' in document, | ||
hasMouseWheelEvent: 'onmousewheel' in document, | ||
hasTouch: 'ontouchstart' in document, | ||
hasTouchWin: navigator.msMaxTouchPoints && navigator.msMaxTouchPoints > 1, | ||
hasPointer: !!window.navigator.msPointerEnabled, | ||
hasKeyDown: 'onkeydown' in document, | ||
isFirefox: navigator.userAgent.indexOf('Firefox') > -1 | ||
export function getSupport() { | ||
return { | ||
hasWheelEvent: 'onwheel' in document, | ||
hasMouseWheelEvent: 'onmousewheel' in document, | ||
hasTouch: 'ontouchstart' in document, | ||
hasTouchWin: navigator.msMaxTouchPoints && navigator.msMaxTouchPoints > 1, | ||
hasPointer: !!window.navigator.msPointerEnabled, | ||
hasKeyDown: 'onkeydown' in document, | ||
isFirefox: navigator.userAgent.indexOf('Firefox') > -1, | ||
} | ||
} |
22221
377