Comparing version 0.0.1 to 0.0.2
31
index.js
@@ -8,16 +8,27 @@ /** | ||
* Usage: | ||
* var addWheelListener = require('wheel'); | ||
* var addWheelListener = require('wheel').addWheelListener; | ||
* var removeWheelListener = require('wheel').removeWheelListener; | ||
* addWheelListener(domElement, function (e) { | ||
* // mouse wheel event | ||
* }); | ||
* removeWheelListener(domElement, function); | ||
*/ | ||
// by default we shortcut to 'addEventListener': | ||
module.exports = addWheelListener; | ||
var prefix = "", _addEventListener, onwheel, support; | ||
// But also expose "advanced" api with unsubscribe: | ||
mdoule.exports.addWheelListener = addWheelListener; | ||
mdoule.exports.removeWheelListener = removeWheelListener; | ||
var prefix = "", _addEventListener, _removeEventListener, onwheel, support; | ||
// detect event model | ||
if ( window.addEventListener ) { | ||
_addEventListener = "addEventListener"; | ||
_removeEventListener = "removeEventListener"; | ||
} else { | ||
_addEventListener = "attachEvent"; | ||
_removeEventListener = "detachEvent"; | ||
prefix = "on"; | ||
@@ -40,3 +51,15 @@ } | ||
function removeWheelListener( elem, callback, useCapture ) { | ||
_removeWheelListener( elem, support, callback, useCapture ); | ||
// handle MozMousePixelScroll in older Firefox | ||
if( support == "DOMMouseScroll" ) { | ||
_removeWheelListener( elem, "MozMousePixelScroll", callback, useCapture ); | ||
} | ||
}; | ||
function _addWheelListener( elem, eventName, 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) | ||
elem[ _addEventListener ]( prefix + eventName, support == "wheel" ? callback : function( originalEvent ) { | ||
@@ -83,1 +106,5 @@ !originalEvent && ( originalEvent = window.event ); | ||
} | ||
function _removeWheelListener( elem, eventName, callback, useCapture ) { | ||
elem[ _removeEventListener ]( prefix + eventName, callback, useCapture || false ); | ||
} |
{ | ||
"name": "wheel", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Mouse wheel event unified for all browsers", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,5 +11,16 @@ # wheel | ||
``` js | ||
var addWheelListener = require('wheel').addWheelListener; | ||
var removeWheelListener = require('wheel').removeWheelListener; | ||
addWheelListener(domElement, function (e) { | ||
// mouse wheel event | ||
}); | ||
removeWheelListener(domElement, function); | ||
``` | ||
You can also use a shortcut for addWheelListener: | ||
``` js | ||
var addWheelListener = require('wheel'); | ||
addWheelListener(domElement, function (e) { | ||
// mouse wheel event | ||
// mouse wheel event | ||
}); | ||
@@ -16,0 +27,0 @@ ``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6304
91
39