|
1 | 1 | /*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) |
2 | 2 | * Licensed under the MIT License (LICENSE.txt). |
3 | 3 | * |
4 | | - * Version: 3.1.6 |
| 4 | + * Version: 3.1.7-pre |
5 | 5 | * |
6 | 6 | * Requires: jQuery 1.2.2+ |
7 | 7 | */ |
|
31 | 31 | } |
32 | 32 | } |
33 | 33 |
|
34 | | - $.event.special.mousewheel = { |
| 34 | + var special = $.event.special.mousewheel = { |
35 | 35 | version: '3.1.6', |
36 | 36 |
|
37 | 37 | setup: function() { |
|
42 | 42 | } else { |
43 | 43 | this.onmousewheel = handler; |
44 | 44 | } |
| 45 | + // Store the line height and page height for this particular element |
| 46 | + $.data(this, 'mousewheel-line-height', special.getLineHeight(this)); |
| 47 | + $.data(this, 'mousewheel-page-height', special.getPageHeight(this)); |
45 | 48 | }, |
46 | 49 |
|
47 | 50 | teardown: function() { |
|
52 | 55 | } else { |
53 | 56 | this.onmousewheel = null; |
54 | 57 | } |
| 58 | + }, |
| 59 | + |
| 60 | + getLineHeight: function(elem) { |
| 61 | + return parseInt($(elem).offsetParent().css('fontSize'), 10); |
| 62 | + }, |
| 63 | + |
| 64 | + getPageHeight: function(elem) { |
| 65 | + return $(elem).height(); |
55 | 66 | } |
56 | 67 | }; |
57 | 68 |
|
|
104 | 115 | // No change actually happened, no reason to go any further |
105 | 116 | if ( deltaY === 0 && deltaX === 0 ) { return; } |
106 | 117 |
|
| 118 | + // Need to convert lines and pages to pixels if we aren't already in pixels |
| 119 | + // There are three delta modes: |
| 120 | + // * deltaMode 0 is by pixels, nothing to do |
| 121 | + // * deltaMode 1 is by lines |
| 122 | + // * deltaMode 2 is by pages |
| 123 | + if ( orgEvent.deltaMode === 1 ) { |
| 124 | + var lineHeight = $.data(this, 'mousewheel-line-height'); |
| 125 | + delta *= lineHeight; |
| 126 | + deltaY *= lineHeight; |
| 127 | + deltaX *= lineHeight; |
| 128 | + } else if ( orgEvent.deltaMode === 2 ) { |
| 129 | + var pageHeight = $.data(this, 'mousewheel-page-height'); |
| 130 | + delta *= pageHeight; |
| 131 | + deltaY *= pageHeight; |
| 132 | + deltaX *= pageHeight; |
| 133 | + } |
| 134 | + |
107 | 135 | // Store lowest absolute delta to normalize the delta values |
108 | 136 | absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); |
| 137 | + |
109 | 138 | if ( !lowestDelta || absDelta < lowestDelta ) { |
110 | 139 | lowestDelta = absDelta; |
111 | 140 | } |
|
119 | 148 | event.deltaX = deltaX; |
120 | 149 | event.deltaY = deltaY; |
121 | 150 | event.deltaFactor = lowestDelta; |
| 151 | + // Go ahead and set deltaMode to 0 since we converted to pixels |
| 152 | + // Although this is a little odd since we overwrite the deltaX/Y |
| 153 | + // properties with normalized deltas. |
| 154 | + event.deltaMode = 0; |
122 | 155 |
|
123 | 156 | // Add event and delta to the front of the arguments |
124 | 157 | args.unshift(event, delta, deltaX, deltaY); |
|
0 commit comments