fix(zoomscroll): fix using of incorrect offsetX/Y values for zoom on Gecko Browsers

close #83
This commit is contained in:
jdotzki 2014-07-09 15:07:29 +02:00
parent 9d178b23f2
commit 75402fe277
1 changed files with 45 additions and 2 deletions

View File

@ -51,8 +51,23 @@ function ZoomScroll(events, canvas) {
canvas.scroll(delta); canvas.scroll(delta);
} else { } else {
var offset = {};
// Gecko Browser should use _offsetX
if(!event.originalEvent.offsetX) {
offset = {
x: event.originalEvent._offsetX,
y: event.originalEvent._offsetY
};
} else {
offset = {
x: event.offsetX,
y: event.offsetY
};
}
// zoom in relative to diagram {x,y} coordinates // zoom in relative to diagram {x,y} coordinates
zoom(y, { x: event.offsetX, y: event.offsetY }); zoom(y, offset);
} }
event.preventDefault(); event.preventDefault();
@ -72,3 +87,31 @@ function ZoomScroll(events, canvas) {
ZoomScroll.$inject = [ 'eventBus', 'canvas' ]; ZoomScroll.$inject = [ 'eventBus', 'canvas' ];
module.exports = ZoomScroll; module.exports = ZoomScroll;
// Thx to https://bugzilla.mozilla.org/show_bug.cgi?id=69787#c37
// for providing a work around for missing offsetX in Gecko
Object.defineProperties(MouseEvent.prototype, {
_offsetRelativeElement: {
get: function() {
var element = this.target;
while (['block', 'inline-block', 'list-item', 'table', 'inline-table', 'table-caption',
'table-column', 'table-colgroup', 'table-header-group', 'table-row-group', 'table-footer-group',
'table-row', 'table-cell'].indexOf(window.getComputedStyle(element).display) === -1) {
element = element.parentNode;
}
return element;
}
},
_offsetX: {
get: function() {
return this.clientX - this._offsetRelativeElement.getBoundingClientRect().left;
}
},
_offsetY: {
get: function() {
return this.clientY - this._offsetRelativeElement.getBoundingClientRect().top;
}
}
});