diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-01-12 08:59:34 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-01-12 08:59:53 -0500 |
commit | e2d9b02c56ee92fa92913b451598b59a385db609 (patch) | |
tree | ea914ac52663825dc14d8458dade2748ecdf3102 /tests | |
parent | 370bc00150f1f77275a861a3c15138b488061871 (diff) | |
download | jquery-ui-e2d9b02c56ee92fa92913b451598b59a385db609.tar.gz jquery-ui-e2d9b02c56ee92fa92913b451598b59a385db609.zip |
Simulate: Define getters for pageX and pageY in mouse events if they come through as 0. Fixes #7324 - simulate mouse events broken for IE 9.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/jquery.simulate.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/jquery.simulate.js b/tests/jquery.simulate.js index a37302c46..a8740e6b8 100644 --- a/tests/jquery.simulate.js +++ b/tests/jquery.simulate.js @@ -45,7 +45,7 @@ $.extend( $.simulate.prototype, { } }, mouseEvent: function( type, options ) { - var evt; + var evt, eventDoc, doc, body; var e = $.extend({ bubbles: true, cancelable: (type !== "mousemove"), @@ -71,6 +71,30 @@ $.extend( $.simulate.prototype, { e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget || document.body.parentNode ); + + // IE 9+ creates events with pageX and pageY set to 0. + // Trying to modify the properties throws an error, + // so we define getters to return the correct values. + if ( evt.pageX === 0 && evt.pageY === 0 && Object.defineProperty ) { + eventDoc = evt.relatedTarget.ownerDocument || document; + doc = eventDoc.documentElement; + body = eventDoc.body; + + Object.defineProperty( evt, "pageX", { + get: function() { + return e.clientX + + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - + ( doc && doc.clientLeft || body && body.clientLeft || 0 ); + } + }); + Object.defineProperty( evt, "pageY", { + get: function() { + return e.clientY + + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - + ( doc && doc.clientTop || body && body.clientTop || 0 ); + } + }); + } } else if ( document.createEventObject ) { evt = document.createEventObject(); $.extend( evt, e ); |