Skip to content

Commit 6105fab

Browse files
committed
Update 03 Version 1.3.0 JS Port
- Javascript port - License `The Unlicense` - Number class extended by `limit()` function, like `Integer.limit()` in Sciter.TIS - Now it's usable inside standard windows - Versioning work as followed `Major.Improve.Fix`, the last not needed to be synced between JS/TIS.
1 parent 2b35cee commit 6105fab

5 files changed

Lines changed: 83 additions & 35 deletions

File tree

LICENCE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# MovableView v1.2
1+
# MovableView
2+
```lua
3+
> Tiscript : 1.3.0
4+
> Javascript : 1.3.0
5+
```
26
Movable view for Sciter windows, allows you to move the window using any element in it.
37
Advantages:
48
1. Cheating windows performance setting, you will see the full window and not just a rectangle while moving it in performance mode.
@@ -12,21 +16,24 @@ Using inside a compiled application should use less than 1% CPU (while moving th
1216
## Install
1317
Add this file to your resources/UI folder
1418
```php
15-
movableView.tis
19+
movableView.tis // OR
20+
movableView.js
1621
```
1722

1823
Then add the file to your project either from HTML :
1924
```html
20-
<script src="movableView.tis" type="text/tiscript"></script>
25+
<script src="movableView.tis" type="text/tiscript"></script> // OR
26+
<script src="movableView.js" type="text/javascript"></script>
2127
```
2228
or from your main script file :
23-
```php
24-
include "movableView.tis";
29+
```js
30+
include "movableView.tis"; // OR
31+
import movableView from "movableView.js" // uncomment last line in `movableView.js`
2532
```
2633

2734
Then initiate it by calling
2835
```js
2936
movableView("selector" [, screenBound:bool(false)]);
3037
```
3138
with the selector being any CSS selector i.e. `div` `.div` `#div`
32-
the second parameter will prevent window from going past the screen boundaries.
39+
the second parameter `true|false` to prevent window from going past the screen boundaries.

demo.htm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@
1212
}
1313
</style>
1414
<script src="movableView.tis" type="text/tiscript"></script>
15+
<script src="movableView.js" type="text/javascript"></script>
1516
<script type="text/tiscript">
17+
// include "movableView.tis";
18+
movableView(".header");
19+
movableView(".footer", true);
20+
</script>
21+
<script type="text/javascript" type="module">
22+
// import movableView from "movableView.js";
1623
movableView(".header");
1724
movableView(".footer", true);
1825
</script>
1926
</head>
2027
<body>
2128
<div class="header">Header</div>
22-
<div class="content">Content - Grab the header or footer to move (footer will not allow you to cross screen bounds)</div>
29+
<div class="content">Grab the header or footer to move (footer will not allow you to cross screen bounds)</div>
2330
<div class="footer">Footer</div>
2431
</body>
2532
</html>

movableView.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// Movable View v1.2 EXPERIMENTAL JS PORT 02
2-
// https://github.com/MustafaHi/Sciter-MovableView
1+
//| Movable View v1.3.0
2+
//| https://github.com/MustafaHi/Sciter-MovableView
33

4-
// Call movableView('selector' [, screenBound:bool(false)]);
4+
// Call movableView('selector', true|false);
55

6-
Number.prototype.limit = function(min,max) {
7-
if (this < min) return min;
8-
if (this > max) return max;
9-
return this;
6+
if (!Number.prototype.limit) {
7+
Number.prototype.limit = function(min,max) {
8+
if (this < min) return min;
9+
if (this > max) return max;
10+
return this;
11+
}
1012
}
1113

1214
function movableView(s, screenBound = false)
@@ -26,46 +28,48 @@ function movableView(s, screenBound = false)
2628
}
2729
else
2830
{
29-
maxX = Number.MAX_SAFE_INTEGER;
30-
maxY = Number.MAX_SAFE_INTEGER;
31+
maxX = Number.MAX_SAFE_INTEGER;
32+
maxY = Number.MAX_SAFE_INTEGER;
3133
minXY = Number.MIN_SAFE_INTEGER;
3234
}
3335
}
3436

3537
function onMouseDown(e)
3638
{
3739
screenBounds();
40+
e.target.state.capture(true);
41+
3842
var [x,y] = Window.this.box("position", "border", "screen");
3943
xoff = e.screenX - x; yoff = e.screenY - y;
40-
dragging = true;
4144

42-
document.on("mouseup" , onMouseUp );
43-
document.on("mousemove", onMouseMove );
44-
e.preventDefault();
45-
e.stopPropagation();
45+
dragging = true;
4646
}
4747

4848
function onMouseMove(e)
4949
{
5050
if(dragging)
5151
{
52-
e.preventDefault();
5352
Window.this.move((e.screenX - xoff).limit(minXY, maxX), (e.screenY - yoff).limit(minXY, maxY));
5453
}
5554
}
5655

5756
function onMouseUp(e)
5857
{
59-
if(dragging) { dragging = false; }
60-
document.off("mouseup");
61-
document.off("mousemove");
62-
e.preventDefault();
58+
if(dragging)
59+
{
60+
dragging = false;
61+
e.target.state.capture(false);
62+
}
6363
}
6464

6565
const elements = document.querySelectorAll(s);
6666
for(var i=0; i<elements.length; ++i) {
6767
elements[i].on("mousedown", onMouseDown );
68+
elements[i].on("mousemove", onMouseMove );
69+
elements[i].on("mouseup", onMouseUp );
6870
}
69-
return true;
71+
return elements.length ? true : false;
7072
}
7173

74+
//| Module export (uncomment bellow)
75+
// export { movableView as default };

movableView.tis

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Movable View v1.2
2-
// https://github.com/MustafaHi/Sciter-MovableView
1+
//| Movable View v1.3.0
2+
//| https://github.com/MustafaHi/Sciter-MovableView
3+
4+
// Call movableView('selector', true|false);
35

4-
// Call movableView('selector' [, screenBound:bool(false)]);
56
function movableView(s, screenBound = false)
67
{
78
var xoff,yoff, minXY, maxX, maxY;
@@ -32,7 +33,10 @@ function movableView(s, screenBound = false)
3233

3334
screenBounds();
3435
e.target.capture(true);
35-
xoff = e.xView; yoff = e.yView;
36+
37+
var (x,y) = view.box(#position, #border, #screen);
38+
xoff = e.xScreen - x; yoff = e.yScreen - y;
39+
3640
dragging = true;
3741
doDrag();
3842
}
@@ -43,13 +47,15 @@ function movableView(s, screenBound = false)
4347
{
4448
view.move( (e.xScreen - xoff).limit(minXY, maxX), (e.yScreen - yoff).limit(minXY, maxY), false );
4549
}
46-
return true;
4750
}
4851

4952
function onMouseUp(e)
5053
{
51-
if(dragging) { dragging = false; e.target.capture(false); }
52-
return true;
54+
if(dragging)
55+
{
56+
dragging = false;
57+
e.target.capture(false);
58+
}
5359
}
5460

5561
const elements = $$({s});
@@ -58,6 +64,6 @@ function movableView(s, screenBound = false)
5864
elements[i].subscribe(onMouseUp, Event.MOUSE, Event.MOUSE_UP );
5965
elements[i].subscribe(onMouseMove, Event.MOUSE, Event.MOUSE_MOVE );
6066
}
61-
return true;
67+
return elements.length ? true : false;
6268
}
6369

0 commit comments

Comments
 (0)