Skip to content

Commit

Permalink
Fix pageX and pageY in IE’s JS events
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Mar 2, 2010
1 parent 1410ed4 commit 63de0a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 4 additions & 18 deletions lib/scripts/drag.js
Expand Up @@ -50,8 +50,8 @@ var drag = {

this.oX = parseInt(this.obj.style.left);
this.oY = parseInt(this.obj.style.top);
this.eX = drag.evX(e);
this.eY = drag.evY(e);
this.eX = e.pageX;
this.eY = e.pageY;

var _this = this;
this.mousehandlers = [function (e) {return _this.drag(e);}, function (e) {return _this.stop(e);}];
Expand Down Expand Up @@ -80,23 +80,9 @@ var drag = {
*/
drag: function(e) {
if(this.obj) {
this.obj.style.top = (this.evY(e)+this.oY-this.eY+'px');
this.obj.style.left = (this.evX(e)+this.oX-this.eX+'px');
this.obj.style.top = (e.pageY+this.oY-this.eY+'px');
this.obj.style.left = (e.pageX+this.oX-this.eX+'px');
}
},

/**
* Returns the X position of the given event.
*/
evX: function(e){
return (e.pageX) ? e.pageX : e.clientX + document.body.scrollTop; //fixme shouldn't this be scrollLeft?
},

/**
* Returns the Y position of the given event.
*/
evY: function(e){
return (e.pageY) ? e.pageY : e.clientY + document.body.scrollTop;
}

};
4 changes: 4 additions & 0 deletions lib/scripts/events.js
Expand Up @@ -55,6 +55,10 @@ function fixEvent(event) {
event.stopPropagation = fixEvent.stopPropagation;
// fix target
event.target = event.srcElement;
// fix coords
event.pageX = (typeof event.pageX !== 'undefined') ? event.pageX : event.clientX + document.body.scrollTop;
event.pageY = (typeof event.pageY !== 'undefined') ? event.pageY : event.clientY + document.body.scrollTop;

return event;
};
fixEvent.preventDefault = function() {
Expand Down

1 comment on commit 63de0a5

@splitbrain
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to find out why event.clientX + document.body.scrollTop; works and why scrollLeft doesn't!

Please sign in to comment.