Skip to content

Commit

Permalink
#310 scrolling the documentElement
Browse files Browse the repository at this point in the history
  • Loading branch information
ondras committed Apr 27, 2022
1 parent bbea4e9 commit 4c2b6f5
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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";
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down

0 comments on commit 4c2b6f5

Please sign in to comment.