Skip to content

Commit

Permalink
mouse click/drag offset fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Wilkins committed Jan 16, 2015
1 parent a58ea48 commit 54d8139
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions compass-rose-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@
return coords;
};

this.getMousePosition = function(ev){
// XXX: Do these values get used?
var coordinates;
var offset = $(this.frontcanv).offset();;
if (ev.originalEvent['layerX'] != undefined) {
coordinates = {
x: ev.originalEvent.pageX - offset.left,
y: ev.originalEvent.pageY - offset.top
};
} else {
// in IE, we use this property
coordinates = {
x: ev.originalEvent.x,
y: ev.originalEvent.y
};
}
return coordinates;
};

this.drawArrow = function(coords) {
var canvas = this.frontcanv;
var ctx = canvas.getContext('2d');
Expand Down Expand Up @@ -284,20 +303,8 @@

$(frontcanv).mousedown(function (ev) {
this.pressed = true;
var coordinates;
// XXX: Do these values get used?
if (ev.originalEvent['layerX'] != undefined) {
coordinates = {
x: ev.originalEvent.layerX,
y: ev.originalEvent.layerY
};
} else {
// in IE, we use this property
coordinates = {
x: ev.originalEvent.x,
y: ev.originalEvent.y
};
}
var coordinates = _this.getMousePosition(ev);

_this.drawArrow(coordinates);
// pass our values to the configured move function
if (this.parentElement.settings &&
Expand All @@ -312,20 +319,7 @@
return;
}
this.moved = true;
var coordinates;

if (ev.originalEvent['layerX'] != undefined) {
coordinates = {
x: ev.originalEvent.layerX,
y: ev.originalEvent.layerY
};
} else {
// in IE, we use this property
coordinates = {
x: ev.originalEvent.x,
y: ev.originalEvent.y
};
}
var coordinates = _this.getMousePosition(ev);

_this.drawArrow(coordinates);
// pass our values to the configured move function
Expand Down

0 comments on commit 54d8139

Please sign in to comment.