-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovableView.js
75 lines (64 loc) · 1.62 KB
/
movableView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//| Movable View v1.3.0
//| https://github.com/MustafaHi/Sciter-MovableView
// Call movableView('selector', true|false);
if (!Number.prototype.limit) {
Number.prototype.limit = function(min,max) {
if (this < min) return min;
if (this > max) return max;
return this;
}
}
function movableView(s, screenBound = false)
{
var xoff,yoff, minXY, maxX, maxY;
var dragging = false;
function screenBounds()
{
if (screenBound)
{
[maxX, maxY] = Window.this.screenBox("workarea", "dimension");
var [w, h] = Window.this.box("dimension", "border");
maxX -= w;
maxY -= h;
minXY = 0;
}
else
{
maxX = Number.MAX_SAFE_INTEGER;
maxY = Number.MAX_SAFE_INTEGER;
minXY = Number.MIN_SAFE_INTEGER;
}
}
function onMouseDown(e)
{
screenBounds();
e.target.state.capture(true);
var [x,y] = Window.this.box("position", "border", "screen");
xoff = e.screenX - x; yoff = e.screenY - y;
dragging = true;
}
function onMouseMove(e)
{
if(dragging)
{
Window.this.move((e.screenX - xoff).limit(minXY, maxX), (e.screenY - yoff).limit(minXY, maxY));
}
}
function onMouseUp(e)
{
if(dragging)
{
dragging = false;
e.target.state.capture(false);
}
}
const elements = document.querySelectorAll(s);
for(var i=0; i<elements.length; ++i) {
elements[i].on("mousedown", onMouseDown );
elements[i].on("mousemove", onMouseMove );
elements[i].on("mouseup", onMouseUp );
}
return elements.length ? true : false;
}
//| Module export (uncomment bellow)
// export { movableView as default };