|
86 | 86 | });
|
87 | 87 | };
|
88 | 88 |
|
89 |
| - var initWheelEvents = function (scope, element) { |
90 |
| - var onWheel, |
91 |
| - bindWheel, |
92 |
| - unbindWheel; |
93 |
| - |
94 |
| - onWheel = function (e) { |
95 |
| - var bubbleUp, |
96 |
| - delta; |
97 |
| - |
98 |
| - if (e.originalEvent) { |
99 |
| - e = e.originalEvent; |
100 |
| - } |
101 |
| - |
102 |
| - e.preventDefault(); |
103 |
| - |
104 |
| - delta = Math.max(-1, Math.min(1, (e.wheelDelta || -(e.deltaY || e.detail)))); |
105 |
| - |
106 |
| - if (isNaN(delta) || delta === 0) { |
107 |
| - return; |
| 89 | + var initWheelEvents = function (wheel, scope, element) { |
| 90 | + function maybePreventBubbling(e, bubbleUp) { |
| 91 | + if (!bubbleUp) { |
| 92 | + e.stopPropagation(); |
108 | 93 | }
|
| 94 | + } |
109 | 95 |
|
110 |
| - if (delta < 0) { |
111 |
| - if (scope.snapDirection !== 1) { |
112 |
| - if (scope.snapIndex + 1 > scope.scopeIndexMax()) { |
| 96 | + wheel.bind(element, { |
| 97 | + up: function (e) { |
| 98 | + var bubbleUp; |
| 99 | + if (scope.snapDirection !== -1) { |
| 100 | + if (scope.snapIndex - 1 < scope.snapIndexMin()) { |
113 | 101 | bubbleUp = true;
|
114 | 102 | } else {
|
115 | 103 | bubbleUp = false;
|
116 | 104 | scope.$apply(function () {
|
117 |
| - scope.snapIndex += 1; |
| 105 | + scope.snapIndex -= 1; |
118 | 106 | });
|
119 | 107 | }
|
120 | 108 | }
|
121 |
| - } else { |
122 |
| - if (scope.snapDirection !== -1) { |
123 |
| - if (scope.snapIndex - 1 < scope.snapIndexMin()) { |
| 109 | + maybePreventBubbling(e, bubbleUp); |
| 110 | + }, |
| 111 | + down: function (e) { |
| 112 | + var bubbleUp; |
| 113 | + if (scope.snapDirection !== 1) { |
| 114 | + if (scope.snapIndex + 1 > scope.scopeIndexMax()) { |
124 | 115 | bubbleUp = true;
|
125 | 116 | } else {
|
126 | 117 | bubbleUp = false;
|
127 | 118 | scope.$apply(function () {
|
128 |
| - scope.snapIndex -= 1; |
| 119 | + scope.snapIndex += 1; |
129 | 120 | });
|
130 | 121 | }
|
131 | 122 | }
|
| 123 | + maybePreventBubbling(e, bubbleUp); |
132 | 124 | }
|
| 125 | + }); |
133 | 126 |
|
134 |
| - if (!bubbleUp) { |
135 |
| - e.stopPropagation(); |
136 |
| - } |
137 |
| - }; |
138 |
| - |
139 |
| - bindWheel = function () { |
140 |
| - element.on('wheel mousewheel onmousewheel', onWheel); |
141 |
| - }; |
142 |
| - |
143 |
| - unbindWheel = function () { |
144 |
| - element.off('wheel mousewheel onmousewheel', onWheel); |
145 |
| - }; |
146 |
| - |
147 |
| - bindWheel(); |
148 |
| - scope.$on('$destroy', unbindWheel); |
| 127 | + scope.$on('$destroy', function () { |
| 128 | + wheel.unbind(element); |
| 129 | + }); |
149 | 130 | };
|
150 | 131 |
|
151 |
| - var snapscrollAsAnAttribute = ['$timeout', 'scroll', 'defaultSnapscrollScrollDelay', 'defaultSnapscrollSnapDuration', 'defaultSnapscrollBindScrollTimeout', |
152 |
| - function ($timeout, scroll, defaultSnapscrollScrollDelay, defaultSnapscrollSnapDuration, defaultSnapscrollBindScrollTimeout) { |
| 132 | + var snapscrollAsAnAttribute = ['$timeout', 'scroll', 'wheel', 'defaultSnapscrollScrollDelay', 'defaultSnapscrollSnapDuration', 'defaultSnapscrollBindScrollTimeout', |
| 133 | + function ($timeout, scroll, wheel, defaultSnapscrollScrollDelay, defaultSnapscrollSnapDuration, defaultSnapscrollBindScrollTimeout) { |
153 | 134 | return {
|
154 | 135 | restrict: 'A',
|
155 | 136 | scope: scopeObject,
|
|
290 | 271 | scope.$on('$destroy', unbindScroll);
|
291 | 272 | }
|
292 | 273 |
|
293 |
| - initWheelEvents(scope, element); |
| 274 | + initWheelEvents(wheel, scope, element); |
294 | 275 | };
|
295 | 276 |
|
296 | 277 | init();
|
|
0 commit comments