#310 scrolling the documentElement

This commit is contained in:
Ondřej Žára
2022-04-27 13:55:08 +02:00
parent bbea4e9028
commit 4c2b6f5d53
+16 -21
View File
@@ -6,14 +6,14 @@ SQL.Map = function(owner) {
this.dom.container = OZ.$("minimap");
this.width = this.dom.container.offsetWidth - 2;
this.height = this.dom.container.offsetHeight - 2;
this.dom.port = OZ.DOM.elm("div",{className:"port", zIndex:1});
this.dom.container.appendChild(this.dom.port);
this.sync = this.sync.bind(this);
this.flag = false;
this.sync();
OZ.Event.add(window, "resize", this.sync);
OZ.Event.add(window, "scroll", this.sync);
OZ.Event.add(this.dom.container, "mousedown", this.down.bind(this));
@@ -30,7 +30,7 @@ SQL.Map.prototype.down = function(e) { /* mousedown - move view and start drag *
this.x = Math.round(pos[0] + this.l + this.w/2);
this.y = Math.round(pos[1] + this.t + this.h/2);
this.move(e);
if (e.type == "touchstart") {
var eventMove = "touchmove";
var eventUp = "touchend";
@@ -46,41 +46,36 @@ SQL.Map.prototype.down = function(e) { /* mousedown - move view and start drag *
SQL.Map.prototype.move = function(e) { /* mousemove */
if (!this.flag) { return; }
OZ.Event.prevent(e);
if (e.type.match(/touch/)) {
if (e.touches.length > 1) { return; }
var event = e.touches[0];
} else {
var event = e;
}
var dx = event.clientX - this.x;
var dy = event.clientY - this.y;
if (this.l + dx < 0) { dx = -this.l; }
if (this.t + dy < 0) { dy = -this.t; }
if (this.l + this.w + 4 + dx > this.width) { dx = this.width - 4 - this.l - this.w; }
if (this.t + this.h + 4 + dy > this.height) { dy = this.height - 4 - this.t - this.h; }
this.x += dx;
this.y += dy;
this.l += dx;
this.t += dy;
var coefX = this.width / this.owner.width;
var coefY = this.height / this.owner.height;
var left = this.l / coefX;
var top = this.t / coefY;
if (OZ.webkit) {
document.body.scrollLeft = Math.round(left);
document.body.scrollTop = Math.round(top);
} else {
document.documentElement.scrollLeft = Math.round(left);
document.documentElement.scrollTop = Math.round(top);
}
document.documentElement.scrollLeft = Math.round(left);
document.documentElement.scrollTop = Math.round(top);
this.redraw();
}
@@ -101,12 +96,12 @@ SQL.Map.prototype.sync = function() { /* when window changes, adjust map */
var h = dims[1] * scaleY - 4 - 0;
var x = scroll[0] * scaleX;
var y = scroll[1] * scaleY;
this.w = Math.round(w);
this.h = Math.round(h);
this.l = Math.round(x);
this.t = Math.round(y);
this.redraw();
}