Skip to content
This repository was archived by the owner on Apr 15, 2020. It is now read-only.

Commit 6b211d5

Browse files
committed
Minor refactor: removed unnecessary function definition
1 parent 8ef6150 commit 6b211d5

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

src/services/mousewheel.js

+21-26
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,42 @@
44
var snapscroll = angular.module('snapscroll');
55

66
snapscroll.factory('mousewheel', [function () {
7-
function onWheel(e, up, down) {
8-
var delta;
9-
10-
if (e.originalEvent) {
11-
e = e.originalEvent;
12-
}
13-
14-
delta = Math.max(-1, Math.min(1, (e.wheelDelta || -(e.deltaY || e.detail))));
15-
if (isNaN(delta) || delta === 0) {
16-
return;
17-
}
18-
19-
if (delta > 0) {
20-
if (up) {
21-
up(e);
22-
}
23-
} else {
24-
if (down) {
25-
down(e);
26-
}
27-
}
28-
}
29-
307
return {
318
bind: function (element, callbacks) {
329
callbacks = callbacks || {};
10+
3311
if (angular.isDefined(callbacks.up) && !angular.isFunction(callbacks.up)) {
3412
throw new Error('The \'up\' callback must be a function');
3513
}
36-
3714
if (angular.isDefined(callbacks.down) && !angular.isFunction(callbacks.down)) {
3815
throw new Error('The \'down\' callback must be a function');
3916
}
40-
4117
if (!angular.isDefined(callbacks.up) && !angular.isDefined(callbacks.down)) {
4218
throw new Error('At least one callback (\'up\' or \'down\') must be provided');
4319
}
4420

4521
function bindWheel(e) {
46-
onWheel(e, callbacks.up, callbacks.down);
22+
if (e.originalEvent) {
23+
e = e.originalEvent;
24+
}
25+
26+
var delta;
27+
delta = Math.max(-1, Math.min(1, (e.wheelDelta || -(e.deltaY || e.detail))));
28+
if (isNaN(delta) || delta === 0) {
29+
return;
30+
}
31+
32+
if (delta > 0) {
33+
if (callbacks.up) {
34+
callbacks.up(e);
35+
}
36+
} else {
37+
if (callbacks.down) {
38+
callbacks.down(e);
39+
}
40+
}
4741
}
42+
4843
element.data('snapscroll-bindWheel', bindWheel);
4944
element.on('wheel mousewheel onmousewheel', bindWheel);
5045
},

0 commit comments

Comments
 (0)