Skip to content

Instantly share code, notes, and snippets.

@andreiglingeanu
Created February 24, 2013 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreiglingeanu/5024216 to your computer and use it in GitHub Desktop.
Save andreiglingeanu/5024216 to your computer and use it in GitHub Desktop.
fix events
function fixEvent(e, _this) {
e = e || window.event;
if (!e.currentTarget) e.currentTarget = _this;
if (!e.target) e.target = e.srcElement;
if (!e.relatedTarget) {
if (e.type == 'mouseover') e.relatedTarget = e.fromElement;
if (e.type == 'mouseout') e.relatedTarget = e.toElement;
}
if (e.pageX == null && e.clientX != null ) {
var html = document.documentElement;
var body = document.body;
e.pageX = e.clientX + (html.scrollLeft || body && body.scrollLeft || 0);
e.pageX -= html.clientLeft || 0;
e.pageY = e.clientY + (html.scrollTop || body && body.scrollTop || 0);
e.pageY -= html.clientTop || 0;
}
if (!e.which && e.button) {
e.which = e.button & 1 ? 1 : ( e.button & 2 ? 3 : (e.button & 4 ? 2 : 0) );
}
return e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment