hack to get pageX/pageY working for jquery-simulate click

This commit is contained in:
Adam Shaw
2014-05-27 14:10:12 -07:00
parent 5db9a6eb97
commit ec8615e526
2 changed files with 33 additions and 1 deletions
+2 -1
View File
@@ -14,13 +14,14 @@ module.exports = function(config) {
'lib/jquery/jquery.js',
'lib/jquery-ui/ui/jquery-ui.js',
// for jquery-simulate-ext
// for jquery simulate
'lib/jquery-simulate-ext/libs/bililiteRange.js',
'lib/jquery-simulate-ext/libs/jquery.simulate.js',
'lib/jquery-simulate-ext/src/jquery.simulate.ext.js',
'lib/jquery-simulate-ext/src/jquery.simulate.drag-n-drop.js',
'lib/jquery-simulate-ext/src/jquery.simulate.key-sequence.js',
'lib/jquery-simulate-ext/src/jquery.simulate.key-combo.js',
'tests/lib/jquery-simulate-hacks.js', // needs to be last
'lib/jquery-mockjax/jquery.mockjax.js',
'lib/jasmine-jquery/lib/jasmine-jquery.js',
+31
View File
@@ -0,0 +1,31 @@
(function($) {
/*
Addresses a shortcoming with jquery-simulate[-ext] where a click event doesn't
provide pageX/pageY coordinates. Should be the centered coordinates of the element.
This file needs to be loaded after jquery-simulate and jquery-simulate-ext.
*/
var originalMouseEvent = $.simulate.prototype.mouseEvent;
$.simulate.prototype.mouseEvent = function(type, options) {
if (type === 'click' && options.pageX === undefined && options.pageY === undefined) {
$.extend(options, findCenterPageXY(this.target));
}
// after this, jquery-simulate-ext will calculate screenX/screenY
// and jquery-simulate will calculate clientX/clientY...
return originalMouseEvent.apply(this, [ type, options ]);
};
function findCenterPageXY( elem ) {
var offset,
$elem = $(elem),
offset = $elem.offset();
return {
pageX: Math.round(offset.left + $elem.outerWidth() / 2),
pageY: Math.round(offset.top + $elem.outerHeight() / 2)
};
}
})(jQuery);