| 1 | |
| 2 | _initWheel: function () { |
| 3 | utils.addEvent(this.wrapper, 'wheel', this); |
| 4 | utils.addEvent(this.wrapper, 'mousewheel', this); |
| 5 | utils.addEvent(this.wrapper, 'DOMMouseScroll', this); |
| 6 | |
| 7 | this.on('destroy', function () { |
| 8 | utils.removeEvent(this.wrapper, 'wheel', this); |
| 9 | utils.removeEvent(this.wrapper, 'mousewheel', this); |
| 10 | utils.removeEvent(this.wrapper, 'DOMMouseScroll', this); |
| 11 | }); |
| 12 | }, |
| 13 | |
| 14 | _wheel: function (e) { |
| 15 | if ( !this.enabled ) { |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | e.preventDefault(); |
| 20 | e.stopPropagation(); |
| 21 | |
| 22 | var wheelDeltaX, wheelDeltaY, |
| 23 | newX, newY, |
| 24 | that = this; |
| 25 | |
| 26 | if ( this.wheelTimeout === undefined ) { |
| 27 | that._execEvent('scrollStart'); |
| 28 | } |
| 29 | |
| 30 | // Execute the scrollEnd event after 400ms the wheel stopped scrolling |
| 31 | clearTimeout(this.wheelTimeout); |
| 32 | this.wheelTimeout = setTimeout(function () { |
| 33 | that._execEvent('scrollEnd'); |
| 34 | that.wheelTimeout = undefined; |
| 35 | }, 400); |
| 36 | |
| 37 | if ( 'deltaX' in e ) { |
| 38 | wheelDeltaX = -e.deltaX; |
| 39 | wheelDeltaY = -e.deltaY; |
| 40 | } else if ( 'wheelDeltaX' in e ) { |
| 41 | wheelDeltaX = e.wheelDeltaX / 120 * this.options.mouseWheelSpeed; |
| 42 | wheelDeltaY = e.wheelDeltaY / 120 * this.options.mouseWheelSpeed; |
| 43 | } else if ( 'wheelDelta' in e ) { |
| 44 | wheelDeltaX = wheelDeltaY = e.wheelDelta / 120 * this.options.mouseWheelSpeed; |
| 45 | } else if ( 'detail' in e ) { |
| 46 | wheelDeltaX = wheelDeltaY = -e.detail / 3 * this.options.mouseWheelSpeed; |
| 47 | } else { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | wheelDeltaX *= this.options.invertWheelDirection; |
| 52 | wheelDeltaY *= this.options.invertWheelDirection; |
| 53 | |
| 54 | if ( !this.hasVerticalScroll ) { |
| 55 | wheelDeltaX = wheelDeltaY; |
| 56 | wheelDeltaY = 0; |
| 57 | } |
| 58 | |
| 59 | if ( this.options.snap ) { |
| 60 | newX = this.currentPage.pageX; |
| 61 | newY = this.currentPage.pageY; |
| 62 | |
| 63 | if ( wheelDeltaX > 0 ) { |
| 64 | newX--; |
| 65 | } else if ( wheelDeltaX < 0 ) { |
| 66 | newX++; |
| 67 | } |
| 68 | |
| 69 | if ( wheelDeltaY > 0 ) { |
| 70 | newY--; |
| 71 | } else if ( wheelDeltaY < 0 ) { |
| 72 | newY++; |
| 73 | } |
| 74 | |
| 75 | this.goToPage(newX, newY); |
| 76 | |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | newX = this.x + Math.round(this.hasHorizontalScroll ? wheelDeltaX : 0); |
| 81 | newY = this.y + Math.round(this.hasVerticalScroll ? wheelDeltaY : 0); |
| 82 | |
| 83 | if ( newX > 0 ) { |
| 84 | newX = 0; |
| 85 | } else if ( newX < this.maxScrollX ) { |
| 86 | newX = this.maxScrollX; |
| 87 | } |
| 88 | |
| 89 | if ( newY > 0 ) { |
| 90 | newY = 0; |
| 91 | } else if ( newY < this.maxScrollY ) { |
| 92 | newY = this.maxScrollY; |
| 93 | } |
| 94 | |
| 95 | this.scrollTo(newX, newY, 0); |
| 96 | |
| 97 | // INSERT POINT: _wheel |
| 98 | }, |