Skip to content

Commit 2b35cee

Browse files
committed
EXPERIMENTAL JS PORT 02
- Screen bound - Now it's usable inside uSciter and standard windows - Will be fully functional by next Sciter.JS release - Number class extended by `limit()` function, like `Integer.limit()` in Sciter.TIS
1 parent 7369655 commit 2b35cee

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

movableView.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1-
// Movable View v1.2 EXPERIMENTAL JS PORT 01
1+
// Movable View v1.2 EXPERIMENTAL JS PORT 02
22
// https://github.com/MustafaHi/Sciter-MovableView
33

44
// Call movableView('selector' [, screenBound:bool(false)]);
5+
6+
Number.prototype.limit = function(min,max) {
7+
if (this < min) return min;
8+
if (this > max) return max;
9+
return this;
10+
}
11+
512
function movableView(s, screenBound = false)
613
{
714
var xoff,yoff, minXY, maxX, maxY;
815
var dragging = false;
916

17+
function screenBounds()
18+
{
19+
if (screenBound)
20+
{
21+
[maxX, maxY] = Window.this.screenBox("workarea", "dimension");
22+
var [w, h] = Window.this.box("dimension", "border");
23+
maxX -= w;
24+
maxY -= h;
25+
minXY = 0;
26+
}
27+
else
28+
{
29+
maxX = Number.MAX_SAFE_INTEGER;
30+
maxY = Number.MAX_SAFE_INTEGER;
31+
minXY = Number.MIN_SAFE_INTEGER;
32+
}
33+
}
34+
1035
function onMouseDown(e)
1136
{
12-
xoff = e.clientX; yoff = e.clientY;
37+
screenBounds();
38+
var [x,y] = Window.this.box("position", "border", "screen");
39+
xoff = e.screenX - x; yoff = e.screenY - y;
1340
dragging = true;
1441

1542
document.on("mouseup" , onMouseUp );
@@ -23,7 +50,7 @@ function movableView(s, screenBound = false)
2350
if(dragging)
2451
{
2552
e.preventDefault();
26-
Window.this.move(e.screenX - xoff, e.screenY - yoff);
53+
Window.this.move((e.screenX - xoff).limit(minXY, maxX), (e.screenY - yoff).limit(minXY, maxY));
2754
}
2855
}
2956

0 commit comments

Comments
 (0)