Element: 'fix' mousewheel event before modifying it

In strict mode (in recent browsers), modifying deltaX on a WheelEvent
throws an exception:

Uncaught TypeError: Cannot set property deltaX of #<WheelEvent> which has only a getter

In non-strict mode or older browsers, assigning to deltaX is just a
no-op.

https://github.com/jquery/jquery-mousewheel/blob/master/jquery.mousewheel.js
is cited in this function; it uses $.event.fix() to make a mutable
jQuery.Event-flavoured copy of the native event before modifying its
properties. Let's do the same.

Fixes #2751
This commit is contained in:
Will Thompson 2015-05-20 12:33:44 +02:00 committed by j
parent eae9074cea
commit 3ed5da882f

View file

@ -304,7 +304,7 @@
if (!self._deltaFactor || self._deltaFactor > absDelta) { if (!self._deltaFactor || self._deltaFactor > absDelta) {
self._deltaFactor = absDelta; self._deltaFactor = absDelta;
} }
that.triggerEvent('mousewheel', Ox.extend(e, { that.triggerEvent('mousewheel', Ox.extend($.event.fix(e), {
deltaFactor: self._deltaFactor, deltaFactor: self._deltaFactor,
deltaX: Ox.trunc(deltaX / self._deltaFactor), deltaX: Ox.trunc(deltaX / self._deltaFactor),
deltaY: Ox.trunc(deltaY / self._deltaFactor) deltaY: Ox.trunc(deltaY / self._deltaFactor)