Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wheel

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wheel - npm Package Compare versions

Comparing version 0.0.5 to 1.0.0

105

index.js
/**
* This module unifies handling of mouse whee event across different browsers
* This module used to unify mouse wheel behavior between different browsers in 2014
* Now it's just a wrapper around addEventListener('wheel');
*
* See https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Fwheel
* for more details
*
* Usage:

@@ -15,3 +13,2 @@ * var addWheelListener = require('wheel').addWheelListener;

*/
// by default we shortcut to 'addEventListener':

@@ -25,96 +22,8 @@ module.exports = addWheelListener;

var prefix = "", _addEventListener, _removeEventListener, support;
detectEventModel(typeof window !== 'undefined' && window,
typeof document !== 'undefined' && document);
function addWheelListener( elem, callback, useCapture ) {
_addWheelListener( elem, support, callback, useCapture );
// handle MozMousePixelScroll in older Firefox
if( support == "DOMMouseScroll" ) {
_addWheelListener( elem, "MozMousePixelScroll", callback, useCapture );
}
function addWheelListener(element, listener, useCapture) {
element.addEventListener('wheel', listener, useCapture);
}
function removeWheelListener( elem, callback, useCapture ) {
_removeWheelListener( elem, support, callback, useCapture );
// handle MozMousePixelScroll in older Firefox
if( support == "DOMMouseScroll" ) {
_removeWheelListener( elem, "MozMousePixelScroll", callback, useCapture );
}
}
// TODO: in theory this anonymous function may result in incorrect
// unsubscription in some browsers. But in practice, I don't think we should
// worry too much about it (those browsers are on the way out)
function _addWheelListener( elem, eventName, callback, useCapture ) {
elem[ _addEventListener ]( prefix + eventName, support == "wheel" ? callback : function( originalEvent ) {
!originalEvent && ( originalEvent = window.event );
// create a normalized event object
var event = {
// keep a ref to the original event object
originalEvent: originalEvent,
target: originalEvent.target || originalEvent.srcElement,
type: "wheel",
deltaMode: originalEvent.type == "MozMousePixelScroll" ? 0 : 1,
deltaX: 0,
deltaY: 0,
deltaZ: 0,
clientX: originalEvent.clientX,
clientY: originalEvent.clientY,
preventDefault: function() {
originalEvent.preventDefault ?
originalEvent.preventDefault() :
originalEvent.returnValue = false;
},
stopPropagation: function() {
if(originalEvent.stopPropagation)
originalEvent.stopPropagation();
},
stopImmediatePropagation: function() {
if(originalEvent.stopImmediatePropagation)
originalEvent.stopImmediatePropagation();
}
};
// calculate deltaY (and deltaX) according to the event
if ( support == "mousewheel" ) {
event.deltaY = - 1/40 * originalEvent.wheelDelta;
// Webkit also support wheelDeltaX
originalEvent.wheelDeltaX && ( event.deltaX = - 1/40 * originalEvent.wheelDeltaX );
} else {
event.deltaY = originalEvent.detail;
}
// it's time to fire the callback
return callback( event );
}, useCapture || false );
}
function _removeWheelListener( elem, eventName, callback, useCapture ) {
elem[ _removeEventListener ]( prefix + eventName, callback, useCapture || false );
}
function detectEventModel(window, document) {
if ( window && window.addEventListener ) {
_addEventListener = "addEventListener";
_removeEventListener = "removeEventListener";
} else {
_addEventListener = "attachEvent";
_removeEventListener = "detachEvent";
prefix = "on";
}
if (document) {
// detect available wheel event
support = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
document.onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
"DOMMouseScroll"; // let's assume that remaining browsers are older Firefox
} else {
support = "wheel";
}
}
function removeWheelListener( element, listener, useCapture ) {
element.removeEventListener('wheel', listener, useCapture);
}

2

package.json
{
"name": "wheel",
"version": "0.0.5",
"version": "1.0.0",
"description": "Mouse wheel event unified for all browsers",

@@ -5,0 +5,0 @@ "main": "index.js",

# wheel [![Build Status](https://travis-ci.org/anvaka/wheel.svg)](https://travis-ci.org/anvaka/wheel)
This module unifies handling of mouse whee event across different browsers.
In 2014 this module was supposed to unify handling of mouse whee event across
different browsers.
See [MDN](https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel?redirectlocale=en-US&redirectslug=DOM%2FMozilla_event_reference%2Fwheel)
for more details.
Now it's just a wrapper on top of `element.addEventListener('wheel', callback)`;

@@ -8,0 +8,0 @@ # Usage

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc