This repository was archived by the owner on Apr 15, 2020. It is now read-only.
File tree 1 file changed +21
-26
lines changed
1 file changed +21
-26
lines changed Original file line number Diff line number Diff line change 4
4
var snapscroll = angular . module ( 'snapscroll' ) ;
5
5
6
6
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
-
30
7
return {
31
8
bind : function ( element , callbacks ) {
32
9
callbacks = callbacks || { } ;
10
+
33
11
if ( angular . isDefined ( callbacks . up ) && ! angular . isFunction ( callbacks . up ) ) {
34
12
throw new Error ( 'The \'up\' callback must be a function' ) ;
35
13
}
36
-
37
14
if ( angular . isDefined ( callbacks . down ) && ! angular . isFunction ( callbacks . down ) ) {
38
15
throw new Error ( 'The \'down\' callback must be a function' ) ;
39
16
}
40
-
41
17
if ( ! angular . isDefined ( callbacks . up ) && ! angular . isDefined ( callbacks . down ) ) {
42
18
throw new Error ( 'At least one callback (\'up\' or \'down\') must be provided' ) ;
43
19
}
44
20
45
21
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
+ }
47
41
}
42
+
48
43
element . data ( 'snapscroll-bindWheel' , bindWheel ) ;
49
44
element . on ( 'wheel mousewheel onmousewheel' , bindWheel ) ;
50
45
} ,
You can’t perform that action at this time.
0 commit comments