Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined window #52

Merged
merged 1 commit into from
Jun 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions lib/wheel-indicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

/* global module, window, document */

var WheelIndicator = (function(win, doc) {
var eventWheel = 'onwheel' in doc ? 'wheel' : 'mousewheel',

DEFAULTS = {
var WheelIndicator = (function() {
function Module(options) {
var DEFAULTS = {
callback: function(){},
elem: doc,
elem: document,
preventMouse: true
};

function Module(options){
this.eventWheel = 'onwheel' in document ? 'wheel' : 'mousewheel'
this._options = extend(DEFAULTS, options);
this._deltaArray = [ 0, 0, 0 ];
this._isAcceleration = false;
Expand All @@ -31,12 +30,12 @@ var WheelIndicator = (function(win, doc) {
processDelta.call(self, event);

if (self._options.preventMouse) {
preventDefault(event);
preventDefault(event);
}
}
};

addEvent(this._options.elem, eventWheel, this._wheelHandler);
addEvent(this._options.elem, this.eventWheel, this._wheelHandler);
}

Module.prototype = {
Expand Down Expand Up @@ -64,14 +63,14 @@ var WheelIndicator = (function(win, doc) {
var neededOption = this._options[option];

if (neededOption !== undefined) {
return neededOption;
return neededOption;
}

throw new Error('Unknown option');
},

destroy: function(){
removeEvent(this._options.elem, eventWheel, this._wheelHandler);
removeEvent(this._options.elem, this.eventWheel, this._wheelHandler);

return this;
}
Expand All @@ -84,8 +83,7 @@ var WheelIndicator = (function(win, doc) {
}

var getDeltaY = function(event){

if(event.wheelDelta && !event.deltaY) {
if (event.wheelDelta && !event.deltaY) {
getDeltaY = function(event) {
return event.wheelDelta * -1;
};
Expand All @@ -99,7 +97,7 @@ var WheelIndicator = (function(win, doc) {
};

function preventDefault(event){
event = event || win.event;
event = event || window.event;

if (event.preventDefault) {
event.preventDefault();
Expand Down Expand Up @@ -137,7 +135,7 @@ var WheelIndicator = (function(win, doc) {
}

//if all of last three deltas is greater than 0 or lesser than 0 then direction is switched
if(Math.abs(repeatDirection) === arrayLength) {
if (Math.abs(repeatDirection) === arrayLength) {
//determine type of sustainable direction
//(three positive or negative deltas in a row)
sustainableDirection = repeatDirection > 0 ? 'down' : 'up';
Expand All @@ -150,7 +148,7 @@ var WheelIndicator = (function(win, doc) {
}

//if wheel`s moving and current event is not the first in array
if(!self._isStopped){
if (!self._isStopped){
if(changedDirection) {
self._isAcceleration = true;

Expand All @@ -168,7 +166,7 @@ var WheelIndicator = (function(win, doc) {
}

//if wheel is stopped and current delta value is the first in array
if(self._isStopped) {
if (self._isStopped) {
self._isStopped = false;
self._isAcceleration = true;
self._direction = direction;
Expand Down Expand Up @@ -239,7 +237,7 @@ var WheelIndicator = (function(win, doc) {
}

return Module;
}(window, document));
}());

if (typeof exports === 'object') {
module.exports = WheelIndicator;
Expand Down