#310 scrolling the documentElement
This commit is contained in:
@@ -6,14 +6,14 @@ SQL.Map = function(owner) {
|
|||||||
this.dom.container = OZ.$("minimap");
|
this.dom.container = OZ.$("minimap");
|
||||||
this.width = this.dom.container.offsetWidth - 2;
|
this.width = this.dom.container.offsetWidth - 2;
|
||||||
this.height = this.dom.container.offsetHeight - 2;
|
this.height = this.dom.container.offsetHeight - 2;
|
||||||
|
|
||||||
this.dom.port = OZ.DOM.elm("div",{className:"port", zIndex:1});
|
this.dom.port = OZ.DOM.elm("div",{className:"port", zIndex:1});
|
||||||
this.dom.container.appendChild(this.dom.port);
|
this.dom.container.appendChild(this.dom.port);
|
||||||
this.sync = this.sync.bind(this);
|
this.sync = this.sync.bind(this);
|
||||||
|
|
||||||
this.flag = false;
|
this.flag = false;
|
||||||
this.sync();
|
this.sync();
|
||||||
|
|
||||||
OZ.Event.add(window, "resize", this.sync);
|
OZ.Event.add(window, "resize", this.sync);
|
||||||
OZ.Event.add(window, "scroll", this.sync);
|
OZ.Event.add(window, "scroll", this.sync);
|
||||||
OZ.Event.add(this.dom.container, "mousedown", this.down.bind(this));
|
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.x = Math.round(pos[0] + this.l + this.w/2);
|
||||||
this.y = Math.round(pos[1] + this.t + this.h/2);
|
this.y = Math.round(pos[1] + this.t + this.h/2);
|
||||||
this.move(e);
|
this.move(e);
|
||||||
|
|
||||||
if (e.type == "touchstart") {
|
if (e.type == "touchstart") {
|
||||||
var eventMove = "touchmove";
|
var eventMove = "touchmove";
|
||||||
var eventUp = "touchend";
|
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 */
|
SQL.Map.prototype.move = function(e) { /* mousemove */
|
||||||
if (!this.flag) { return; }
|
if (!this.flag) { return; }
|
||||||
OZ.Event.prevent(e);
|
OZ.Event.prevent(e);
|
||||||
|
|
||||||
if (e.type.match(/touch/)) {
|
if (e.type.match(/touch/)) {
|
||||||
if (e.touches.length > 1) { return; }
|
if (e.touches.length > 1) { return; }
|
||||||
var event = e.touches[0];
|
var event = e.touches[0];
|
||||||
} else {
|
} else {
|
||||||
var event = e;
|
var event = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dx = event.clientX - this.x;
|
var dx = event.clientX - this.x;
|
||||||
var dy = event.clientY - this.y;
|
var dy = event.clientY - this.y;
|
||||||
if (this.l + dx < 0) { dx = -this.l; }
|
if (this.l + dx < 0) { dx = -this.l; }
|
||||||
if (this.t + dy < 0) { dy = -this.t; }
|
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.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; }
|
if (this.t + this.h + 4 + dy > this.height) { dy = this.height - 4 - this.t - this.h; }
|
||||||
|
|
||||||
|
|
||||||
this.x += dx;
|
this.x += dx;
|
||||||
this.y += dy;
|
this.y += dy;
|
||||||
|
|
||||||
this.l += dx;
|
this.l += dx;
|
||||||
this.t += dy;
|
this.t += dy;
|
||||||
|
|
||||||
var coefX = this.width / this.owner.width;
|
var coefX = this.width / this.owner.width;
|
||||||
var coefY = this.height / this.owner.height;
|
var coefY = this.height / this.owner.height;
|
||||||
var left = this.l / coefX;
|
var left = this.l / coefX;
|
||||||
var top = this.t / coefY;
|
var top = this.t / coefY;
|
||||||
|
|
||||||
if (OZ.webkit) {
|
document.documentElement.scrollLeft = Math.round(left);
|
||||||
document.body.scrollLeft = Math.round(left);
|
document.documentElement.scrollTop = Math.round(top);
|
||||||
document.body.scrollTop = Math.round(top);
|
|
||||||
} else {
|
|
||||||
document.documentElement.scrollLeft = Math.round(left);
|
|
||||||
document.documentElement.scrollTop = Math.round(top);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,12 +96,12 @@ SQL.Map.prototype.sync = function() { /* when window changes, adjust map */
|
|||||||
var h = dims[1] * scaleY - 4 - 0;
|
var h = dims[1] * scaleY - 4 - 0;
|
||||||
var x = scroll[0] * scaleX;
|
var x = scroll[0] * scaleX;
|
||||||
var y = scroll[1] * scaleY;
|
var y = scroll[1] * scaleY;
|
||||||
|
|
||||||
this.w = Math.round(w);
|
this.w = Math.round(w);
|
||||||
this.h = Math.round(h);
|
this.h = Math.round(h);
|
||||||
this.l = Math.round(x);
|
this.l = Math.round(x);
|
||||||
this.t = Math.round(y);
|
this.t = Math.round(y);
|
||||||
|
|
||||||
this.redraw();
|
this.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user